Pil0tXia commented on code in PR #4837: URL: https://github.com/apache/eventmesh/pull/4837#discussion_r1581728180
########## eventmesh-connectors/eventmesh-connector-http/src/main/java/org/apache/eventmesh/connector/http/sink/handle/CommonHttpSinkHandler.java: ########## @@ -0,0 +1,197 @@ +/* + * 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.sink.handle; + +import org.apache.eventmesh.connector.http.sink.config.SinkConnectorConfig; +import org.apache.eventmesh.connector.http.sink.data.HttpConnectRecord; +import org.apache.eventmesh.openconnect.offsetmgmt.api.data.ConnectRecord; + +import java.time.LocalDateTime; +import java.util.Map; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + +import io.netty.handler.codec.http.HttpHeaderNames; +import io.netty.handler.codec.http.HttpResponseStatus; +import io.vertx.core.MultiMap; +import io.vertx.core.Vertx; +import io.vertx.core.http.HttpHeaders; +import io.vertx.ext.web.client.WebClient; +import io.vertx.ext.web.client.WebClientOptions; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; + +import lombok.extern.slf4j.Slf4j; + +/** + * Common HttpSinkHandler to handle ConnectRecord + */ +@Slf4j +public class CommonHttpSinkHandler implements HttpSinkHandler { + + private final SinkConnectorConfig connectorConfig; + + private WebClient webClient; + + private final String type; + + // store the received data, when webhook is enabled + private final BlockingQueue<JSONObject> receivedDataQueue; + + public CommonHttpSinkHandler(SinkConnectorConfig sinkConnectorConfig) { + SinkConnectorConfig.populateFieldsWithDefaults(sinkConnectorConfig); + this.connectorConfig = sinkConnectorConfig; + this.receivedDataQueue = this.connectorConfig.isWebhook() ? new LinkedBlockingQueue<>() : null; + type = String.format("%s.%s.%s", + sinkConnectorConfig.getConnectorName(), + sinkConnectorConfig.isSsl() ? "https" : "http", + sinkConnectorConfig.isWebhook() ? "webhook" : "common"); + } + + /** + * Get the oldest data in the queue + * + * @return received data + */ + public Object getReceivedData() { + if (!this.connectorConfig.isWebhook()) { + return null; + } + return this.receivedDataQueue.poll(); + } Review Comment: You can start an HTTPServer and export receivedDataQueue. -- 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: issues-unsubscr...@eventmesh.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@eventmesh.apache.org For additional commands, e-mail: issues-h...@eventmesh.apache.org