pandaapo commented on code in PR #4634: URL: https://github.com/apache/eventmesh/pull/4634#discussion_r1421699370
########## tools/dependency-check/known-dependencies.txt: ########## @@ -25,6 +25,7 @@ cache-api-1.1.1.jar checker-qual-3.12.0.jar cloudevents-api-2.4.2.jar cloudevents-core-2.4.2.jar +cloudevents-http-vertx-2.3.0.jar Review Comment: Apart from cloudevents-http-vertx and vertx-web, are there any unnecessary dependencies in the newly added dependencies? ########## eventmesh-connectors/eventmesh-connector-http/src/main/java/org/apache/eventmesh/connector/http/source/connector/HttpSourceConnector.java: ########## @@ -0,0 +1,147 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.eventmesh.connector.http.source.connector; + +import org.apache.eventmesh.common.exception.EventMeshException; +import org.apache.eventmesh.connector.http.source.config.HttpSourceConfig; +import org.apache.eventmesh.openconnect.api.config.Config; +import org.apache.eventmesh.openconnect.api.connector.ConnectorContext; +import org.apache.eventmesh.openconnect.api.connector.SourceConnectorContext; +import org.apache.eventmesh.openconnect.api.source.Source; +import org.apache.eventmesh.openconnect.offsetmgmt.api.data.ConnectRecord; +import org.apache.eventmesh.openconnect.util.CloudEventUtil; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + +import io.cloudevents.CloudEvent; +import io.cloudevents.core.message.MessageReader; +import io.cloudevents.http.vertx.VertxMessageFactory; +import io.netty.handler.codec.http.HttpResponseStatus; +import io.vertx.core.Vertx; +import io.vertx.core.http.HttpMethod; +import io.vertx.core.http.HttpServer; +import io.vertx.core.http.HttpServerOptions; +import io.vertx.ext.web.Router; +import io.vertx.ext.web.handler.LoggerHandler; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class HttpSourceConnector implements Source { + + private static final int DEFAULT_BATCH_SIZE = 10; + + private HttpSourceConfig sourceConfig; + private BlockingQueue<CloudEvent> queue; + private HttpServer server; + + @Override + public Class<? extends Config> configClass() { + return HttpSourceConfig.class; + } + + @Override + public void init(Config config) throws Exception { + this.sourceConfig = (HttpSourceConfig) config; + doInit(); + } + + @Override + public void init(ConnectorContext connectorContext) throws Exception { + SourceConnectorContext sourceConnectorContext = (SourceConnectorContext) connectorContext; + this.sourceConfig = (HttpSourceConfig) sourceConnectorContext.getSourceConfig(); + doInit(); + } + + private void doInit() throws Exception { + this.queue = new LinkedBlockingQueue<>(1000); + + final Vertx vertx = Vertx.vertx(); + final Router router = Router.router(vertx); + router.route() + .path(this.sourceConfig.connectorConfig.getPath()) + .method(HttpMethod.POST) + .handler(LoggerHandler.create()) + .handler(ctx -> { + VertxMessageFactory.createReader(ctx.request()) + .map(MessageReader::toEvent) Review Comment: Is there a custom conversion method available here to directly convert data into `ConnectorRecord`? This will reduce one data conversion in `poll()`. If possible, you can optimize in this PR or in a new PR. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
