diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/EventMeshCommon.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/EventMeshCommon.java similarity index 96% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/EventMeshCommon.java rename to eventmesh-common/src/main/java/org/apache/eventmesh/common/EventMeshCommon.java index 902a135221..5f49115c9f 100644 --- a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/EventMeshCommon.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/EventMeshCommon.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.eventmesh.client.tcp.common; +package org.apache.eventmesh.common; public class EventMeshCommon { diff --git a/eventmesh-connectors/eventmesh-connector-openfunction/build.gradle b/eventmesh-connectors/eventmesh-connector-openfunction/build.gradle index 5fc19090a7..58b3a6fe81 100644 --- a/eventmesh-connectors/eventmesh-connector-openfunction/build.gradle +++ b/eventmesh-connectors/eventmesh-connector-openfunction/build.gradle @@ -17,7 +17,7 @@ dependencies { implementation project(":eventmesh-common") - implementation project(":eventmesh-sdks:eventmesh-sdk-java") + implementation project(":eventmesh-sdks:eventmesh-sdk-java:eventmesh-sdk-java-grpc") implementation project(":eventmesh-openconnect:eventmesh-openconnect-java") implementation "io.grpc:grpc-core" @@ -34,4 +34,4 @@ dependencies { compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' -} \ No newline at end of file +} diff --git a/eventmesh-examples/build.gradle b/eventmesh-examples/build.gradle index 9ef70836bd..26f3986a8b 100644 --- a/eventmesh-examples/build.gradle +++ b/eventmesh-examples/build.gradle @@ -22,7 +22,11 @@ configurations { } dependencies { - implementation project(":eventmesh-sdks:eventmesh-sdk-java") + implementation project(":eventmesh-sdks:eventmesh-sdk-java:eventmesh-sdk-java-tcp") + implementation project(":eventmesh-sdks:eventmesh-sdk-java:eventmesh-sdk-java-grpc") + implementation project(":eventmesh-sdks:eventmesh-sdk-java:eventmesh-sdk-java-http") + implementation project(":eventmesh-sdks:eventmesh-sdk-java:eventmesh-sdk-java-workflow") + implementation project(":eventmesh-sdks:eventmesh-sdk-java:eventmesh-sdk-java-catalog") implementation project(":eventmesh-common") implementation project(":eventmesh-storage-plugin:eventmesh-storage-api") implementation project(":eventmesh-connectors:eventmesh-connector-spring") diff --git a/eventmesh-examples/src/main/java/org/apache/eventmesh/grpc/pub/cloudevents/CloudEventsRequestInstance.java b/eventmesh-examples/src/main/java/org/apache/eventmesh/grpc/pub/cloudevents/CloudEventsRequestInstance.java index 8e0be97bb3..ba32ae4e99 100644 --- a/eventmesh-examples/src/main/java/org/apache/eventmesh/grpc/pub/cloudevents/CloudEventsRequestInstance.java +++ b/eventmesh-examples/src/main/java/org/apache/eventmesh/grpc/pub/cloudevents/CloudEventsRequestInstance.java @@ -18,7 +18,7 @@ package org.apache.eventmesh.grpc.pub.cloudevents; import org.apache.eventmesh.client.grpc.producer.EventMeshGrpcProducer; -import org.apache.eventmesh.client.tcp.common.EventMeshCommon; +import org.apache.eventmesh.common.EventMeshCommon; import org.apache.eventmesh.common.ExampleConstants; import org.apache.eventmesh.common.utils.ThreadUtils; import org.apache.eventmesh.grpc.GrpcAbstractDemo; diff --git a/eventmesh-examples/src/main/java/org/apache/eventmesh/grpc/pub/eventmeshmessage/RequestReplyInstance.java b/eventmesh-examples/src/main/java/org/apache/eventmesh/grpc/pub/eventmeshmessage/RequestReplyInstance.java index b49b584d5a..87a5e2388c 100644 --- a/eventmesh-examples/src/main/java/org/apache/eventmesh/grpc/pub/eventmeshmessage/RequestReplyInstance.java +++ b/eventmesh-examples/src/main/java/org/apache/eventmesh/grpc/pub/eventmeshmessage/RequestReplyInstance.java @@ -18,7 +18,7 @@ package org.apache.eventmesh.grpc.pub.eventmeshmessage; import org.apache.eventmesh.client.grpc.producer.EventMeshGrpcProducer; -import org.apache.eventmesh.client.tcp.common.EventMeshCommon; +import org.apache.eventmesh.common.EventMeshCommon; import org.apache.eventmesh.common.ExampleConstants; import org.apache.eventmesh.common.utils.ThreadUtils; import org.apache.eventmesh.grpc.GrpcAbstractDemo; @@ -45,7 +45,7 @@ public static void main(String[] args) throws Exception { for (int i = 0; i < MESSAGE_SIZE; i++) { eventMeshGrpcProducer.requestReply(buildEventMeshMessage(content, - ExampleConstants.EVENTMESH_GRPC_RR_TEST_TOPIC), + ExampleConstants.EVENTMESH_GRPC_RR_TEST_TOPIC), EventMeshCommon.DEFAULT_TIME_OUT_MILLS); ThreadUtils.sleep(1, TimeUnit.SECONDS); } diff --git a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/cloudevents/AsyncPublish.java b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/cloudevents/AsyncPublish.java index 666e2e3730..ee2603c6f9 100644 --- a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/cloudevents/AsyncPublish.java +++ b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/cloudevents/AsyncPublish.java @@ -19,8 +19,8 @@ import org.apache.eventmesh.client.tcp.EventMeshTCPClient; import org.apache.eventmesh.client.tcp.EventMeshTCPClientFactory; -import org.apache.eventmesh.client.tcp.common.EventMeshCommon; import org.apache.eventmesh.client.tcp.conf.EventMeshTCPClientConfig; +import org.apache.eventmesh.common.EventMeshCommon; import org.apache.eventmesh.common.ExampleConstants; import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.common.utils.ThreadUtils; diff --git a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/cloudevents/SyncRequest.java b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/cloudevents/SyncRequest.java index 4be5e2569d..5df2bf29fb 100644 --- a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/cloudevents/SyncRequest.java +++ b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/cloudevents/SyncRequest.java @@ -19,8 +19,8 @@ import org.apache.eventmesh.client.tcp.EventMeshTCPClient; import org.apache.eventmesh.client.tcp.EventMeshTCPClientFactory; -import org.apache.eventmesh.client.tcp.common.EventMeshCommon; import org.apache.eventmesh.client.tcp.conf.EventMeshTCPClientConfig; +import org.apache.eventmesh.common.EventMeshCommon; import org.apache.eventmesh.common.ExampleConstants; import org.apache.eventmesh.common.protocol.tcp.Package; import org.apache.eventmesh.common.protocol.tcp.UserAgent; diff --git a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/eventmeshmessage/AsyncPublish.java b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/eventmeshmessage/AsyncPublish.java index 222fbb7cd9..331ae947eb 100644 --- a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/eventmeshmessage/AsyncPublish.java +++ b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/eventmeshmessage/AsyncPublish.java @@ -19,8 +19,8 @@ import org.apache.eventmesh.client.tcp.EventMeshTCPClient; import org.apache.eventmesh.client.tcp.EventMeshTCPClientFactory; -import org.apache.eventmesh.client.tcp.common.EventMeshCommon; import org.apache.eventmesh.client.tcp.conf.EventMeshTCPClientConfig; +import org.apache.eventmesh.common.EventMeshCommon; import org.apache.eventmesh.common.ExampleConstants; import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; import org.apache.eventmesh.common.protocol.tcp.UserAgent; diff --git a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/eventmeshmessage/AsyncPublishBroadcast.java b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/eventmeshmessage/AsyncPublishBroadcast.java index 94a5a27b88..01093d0ee6 100644 --- a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/eventmeshmessage/AsyncPublishBroadcast.java +++ b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/eventmeshmessage/AsyncPublishBroadcast.java @@ -19,8 +19,8 @@ import org.apache.eventmesh.client.tcp.EventMeshTCPClient; import org.apache.eventmesh.client.tcp.EventMeshTCPClientFactory; -import org.apache.eventmesh.client.tcp.common.EventMeshCommon; import org.apache.eventmesh.client.tcp.conf.EventMeshTCPClientConfig; +import org.apache.eventmesh.common.EventMeshCommon; import org.apache.eventmesh.common.ExampleConstants; import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; import org.apache.eventmesh.common.protocol.tcp.UserAgent; diff --git a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/eventmeshmessage/SyncRequest.java b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/eventmeshmessage/SyncRequest.java index ed303e8d3e..6b0ab470c6 100644 --- a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/eventmeshmessage/SyncRequest.java +++ b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/eventmeshmessage/SyncRequest.java @@ -19,8 +19,8 @@ import org.apache.eventmesh.client.tcp.EventMeshTCPClient; import org.apache.eventmesh.client.tcp.EventMeshTCPClientFactory; -import org.apache.eventmesh.client.tcp.common.EventMeshCommon; import org.apache.eventmesh.client.tcp.conf.EventMeshTCPClientConfig; +import org.apache.eventmesh.common.EventMeshCommon; import org.apache.eventmesh.common.ExampleConstants; import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; import org.apache.eventmesh.common.protocol.tcp.Package; diff --git a/eventmesh-openconnect/eventmesh-openconnect-java/build.gradle b/eventmesh-openconnect/eventmesh-openconnect-java/build.gradle index d47a81a4ff..7a94b24bf8 100644 --- a/eventmesh-openconnect/eventmesh-openconnect-java/build.gradle +++ b/eventmesh-openconnect/eventmesh-openconnect-java/build.gradle @@ -28,8 +28,8 @@ dependencies { api project (":eventmesh-openconnect:eventmesh-openconnect-offsetmgmt-plugin:eventmesh-openconnect-offsetmgmt-api") implementation project (":eventmesh-openconnect:eventmesh-openconnect-offsetmgmt-plugin:eventmesh-openconnect-offsetmgmt-nacos") - implementation project(":eventmesh-sdks:eventmesh-sdk-java") + implementation project(":eventmesh-sdks:eventmesh-sdk-java:eventmesh-sdk-java-tcp") compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' -} \ No newline at end of file +} diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/build.gradle b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/build.gradle new file mode 100644 index 0000000000..db15554031 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/build.gradle @@ -0,0 +1,64 @@ +/* + * 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. + */ + +def grpcVersion = '1.43.2' + +dependencies { + api project(":eventmesh-common") + + implementation "com.fasterxml.jackson.core:jackson-databind" + implementation "com.fasterxml.jackson.core:jackson-core" + implementation "com.fasterxml.jackson.core:jackson-annotations" + implementation "org.apache.commons:commons-collections4" + + implementation "io.netty:netty-all" + implementation "org.apache.httpcomponents:httpclient" + + implementation "io.grpc:grpc-protobuf:${grpcVersion}" + implementation "io.grpc:grpc-stub:${grpcVersion}" + implementation "io.grpc:grpc-netty:${grpcVersion}" + implementation "io.grpc:grpc-netty-shaded:${grpcVersion}" + implementation "io.cloudevents:cloudevents-protobuf" + + // protocol + api "io.cloudevents:cloudevents-core" + api "io.cloudevents:cloudevents-json-jackson" + api "io.openmessaging:openmessaging-api" + + testImplementation project(":eventmesh-common") + + testImplementation "com.fasterxml.jackson.core:jackson-databind" + testImplementation "com.fasterxml.jackson.core:jackson-core" + testImplementation "com.fasterxml.jackson.core:jackson-annotations" + + testImplementation "io.netty:netty-all" + testImplementation "org.apache.httpcomponents:httpclient" + + implementation "io.grpc:grpc-protobuf:${grpcVersion}" + implementation "io.grpc:grpc-stub:${grpcVersion}" + implementation "com.google.protobuf:protobuf-java-util:3.21.5" + compileOnly 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok' + + testCompileOnly 'org.projectlombok:lombok' + testAnnotationProcessor 'org.projectlombok:lombok' + + testImplementation "org.assertj:assertj-core" + + testImplementation "org.mockito:mockito-inline" + testImplementation "org.mockito:mockito-junit-jupiter" +} diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/gradle.properties b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/gradle.properties new file mode 100644 index 0000000000..b1312a0905 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/gradle.properties @@ -0,0 +1,16 @@ +# +# 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. +# diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/catalog/EventMeshCatalogClient.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/catalog/EventMeshCatalogClient.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/catalog/EventMeshCatalogClient.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/catalog/EventMeshCatalogClient.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/catalog/config/EventMeshCatalogClientConfig.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/catalog/config/EventMeshCatalogClientConfig.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/catalog/config/EventMeshCatalogClientConfig.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/catalog/config/EventMeshCatalogClientConfig.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/config/EventMeshGrpcClientConfig.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/grpc/config/EventMeshGrpcClientConfig.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/config/EventMeshGrpcClientConfig.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/grpc/config/EventMeshGrpcClientConfig.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/consumer/EventMeshGrpcConsumer.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/grpc/consumer/EventMeshGrpcConsumer.java similarity index 99% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/consumer/EventMeshGrpcConsumer.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/grpc/consumer/EventMeshGrpcConsumer.java index 6ceefbe762..6943968f6d 100644 --- a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/consumer/EventMeshGrpcConsumer.java +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/grpc/consumer/EventMeshGrpcConsumer.java @@ -22,7 +22,7 @@ import org.apache.eventmesh.client.grpc.config.EventMeshGrpcClientConfig; import org.apache.eventmesh.client.grpc.util.EventMeshCloudEventBuilder; -import org.apache.eventmesh.client.tcp.common.EventMeshCommon; +import org.apache.eventmesh.common.EventMeshCommon; import org.apache.eventmesh.common.EventMeshThreadFactory; import org.apache.eventmesh.common.enums.EventMeshDataContentType; import org.apache.eventmesh.common.enums.EventMeshProtocolType; diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/consumer/ReceiveMsgHook.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/grpc/consumer/ReceiveMsgHook.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/consumer/ReceiveMsgHook.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/grpc/consumer/ReceiveMsgHook.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/consumer/SubStreamHandler.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/grpc/consumer/SubStreamHandler.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/consumer/SubStreamHandler.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/grpc/consumer/SubStreamHandler.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/exception/ProtocolNotSupportException.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/grpc/exception/ProtocolNotSupportException.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/exception/ProtocolNotSupportException.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/grpc/exception/ProtocolNotSupportException.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/producer/CloudEventProducer.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/grpc/producer/CloudEventProducer.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/producer/CloudEventProducer.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/grpc/producer/CloudEventProducer.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/producer/EventMeshGrpcProducer.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/grpc/producer/EventMeshGrpcProducer.java similarity index 98% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/producer/EventMeshGrpcProducer.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/grpc/producer/EventMeshGrpcProducer.java index 5003ed9489..db700276be 100644 --- a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/producer/EventMeshGrpcProducer.java +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/grpc/producer/EventMeshGrpcProducer.java @@ -18,7 +18,7 @@ package org.apache.eventmesh.client.grpc.producer; import org.apache.eventmesh.client.grpc.config.EventMeshGrpcClientConfig; -import org.apache.eventmesh.client.tcp.common.EventMeshCommon; +import org.apache.eventmesh.common.EventMeshCommon; import org.apache.eventmesh.common.EventMeshMessage; import org.apache.eventmesh.common.protocol.grpc.cloudevents.PublisherServiceGrpc; import org.apache.eventmesh.common.protocol.grpc.cloudevents.PublisherServiceGrpc.PublisherServiceBlockingStub; diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/producer/EventMeshMessageProducer.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/grpc/producer/EventMeshMessageProducer.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/producer/EventMeshMessageProducer.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/grpc/producer/EventMeshMessageProducer.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/producer/GrpcProducer.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/grpc/producer/GrpcProducer.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/producer/GrpcProducer.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/grpc/producer/GrpcProducer.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/util/EventMeshCloudEventBuilder.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/grpc/util/EventMeshCloudEventBuilder.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/util/EventMeshCloudEventBuilder.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/grpc/util/EventMeshCloudEventBuilder.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/selector/Selector.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/selector/Selector.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/selector/Selector.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/selector/Selector.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/selector/SelectorException.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/selector/SelectorException.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/selector/SelectorException.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/selector/SelectorException.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/selector/SelectorFactory.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/selector/SelectorFactory.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/selector/SelectorFactory.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/selector/SelectorFactory.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/selector/ServiceInstance.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/selector/ServiceInstance.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/selector/ServiceInstance.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/java/org/apache/eventmesh/client/selector/ServiceInstance.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/resources/log4j2.xml b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/resources/log4j2.xml similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/resources/log4j2.xml rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/main/resources/log4j2.xml diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/test/resources/application.properties b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/test/resources/application.properties similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/test/resources/application.properties rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/test/resources/application.properties diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/test/resources/log4j2.xml b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/test/resources/log4j2.xml similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/test/resources/log4j2.xml rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-catalog/src/test/resources/log4j2.xml diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/build.gradle b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/build.gradle new file mode 100644 index 0000000000..db15554031 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/build.gradle @@ -0,0 +1,64 @@ +/* + * 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. + */ + +def grpcVersion = '1.43.2' + +dependencies { + api project(":eventmesh-common") + + implementation "com.fasterxml.jackson.core:jackson-databind" + implementation "com.fasterxml.jackson.core:jackson-core" + implementation "com.fasterxml.jackson.core:jackson-annotations" + implementation "org.apache.commons:commons-collections4" + + implementation "io.netty:netty-all" + implementation "org.apache.httpcomponents:httpclient" + + implementation "io.grpc:grpc-protobuf:${grpcVersion}" + implementation "io.grpc:grpc-stub:${grpcVersion}" + implementation "io.grpc:grpc-netty:${grpcVersion}" + implementation "io.grpc:grpc-netty-shaded:${grpcVersion}" + implementation "io.cloudevents:cloudevents-protobuf" + + // protocol + api "io.cloudevents:cloudevents-core" + api "io.cloudevents:cloudevents-json-jackson" + api "io.openmessaging:openmessaging-api" + + testImplementation project(":eventmesh-common") + + testImplementation "com.fasterxml.jackson.core:jackson-databind" + testImplementation "com.fasterxml.jackson.core:jackson-core" + testImplementation "com.fasterxml.jackson.core:jackson-annotations" + + testImplementation "io.netty:netty-all" + testImplementation "org.apache.httpcomponents:httpclient" + + implementation "io.grpc:grpc-protobuf:${grpcVersion}" + implementation "io.grpc:grpc-stub:${grpcVersion}" + implementation "com.google.protobuf:protobuf-java-util:3.21.5" + compileOnly 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok' + + testCompileOnly 'org.projectlombok:lombok' + testAnnotationProcessor 'org.projectlombok:lombok' + + testImplementation "org.assertj:assertj-core" + + testImplementation "org.mockito:mockito-inline" + testImplementation "org.mockito:mockito-junit-jupiter" +} diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/gradle.properties b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/gradle.properties new file mode 100644 index 0000000000..b1312a0905 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/gradle.properties @@ -0,0 +1,16 @@ +# +# 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. +# diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/config/EventMeshGrpcClientConfig.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/config/EventMeshGrpcClientConfig.java new file mode 100644 index 0000000000..8d37802237 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/config/EventMeshGrpcClientConfig.java @@ -0,0 +1,88 @@ +/* + * 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.client.grpc.config; + +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class EventMeshGrpcClientConfig { + + @Builder.Default + private String serverAddr = "localhost"; + + @Builder.Default + private int serverPort = 10_205; + + @Builder.Default + private String env = "env"; + + @Builder.Default + private String consumerGroup = "DefaultConsumerGroup"; + + @Builder.Default + private String producerGroup = "DefaultProducerGroup"; + + @Builder.Default + private String idc = "default"; + + @Builder.Default + private String sys = "sys123"; + + @Builder.Default + private String userName = "username"; + + @Builder.Default + private String password = "passwd"; + + @Builder.Default + private String language = "JAVA"; + + @Builder.Default + private boolean useTls = false; + + @Builder.Default + private long timeOut = 5_000; + + @Override + public String toString() { + return "ClientConfig={ServerAddr=" + + serverAddr + + ",ServerPort=" + + serverPort + + ",env=" + + env + + ",idc=" + + idc + + ",producerGroup=" + + producerGroup + + ",consumerGroup=" + + consumerGroup + + ",sys=" + + sys + + ",userName=" + + userName + + ",password=***" + + ",useTls=" + + useTls + + ",timeOut=" + + timeOut + + "}"; + } +} diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/consumer/EventMeshGrpcConsumer.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/consumer/EventMeshGrpcConsumer.java new file mode 100644 index 0000000000..6943968f6d --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/consumer/EventMeshGrpcConsumer.java @@ -0,0 +1,338 @@ +/* + * 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.client.grpc.consumer; + +import static java.util.stream.Collectors.mapping; +import static java.util.stream.Collectors.toList; + +import org.apache.eventmesh.client.grpc.config.EventMeshGrpcClientConfig; +import org.apache.eventmesh.client.grpc.util.EventMeshCloudEventBuilder; +import org.apache.eventmesh.common.EventMeshCommon; +import org.apache.eventmesh.common.EventMeshThreadFactory; +import org.apache.eventmesh.common.enums.EventMeshDataContentType; +import org.apache.eventmesh.common.enums.EventMeshProtocolType; +import org.apache.eventmesh.common.protocol.HeartbeatItem; +import org.apache.eventmesh.common.protocol.SubscriptionItem; +import org.apache.eventmesh.common.protocol.grpc.cloudevents.CloudEvent; +import org.apache.eventmesh.common.protocol.grpc.cloudevents.CloudEvent.CloudEventAttributeValue; +import org.apache.eventmesh.common.protocol.grpc.cloudevents.ConsumerServiceGrpc; +import org.apache.eventmesh.common.protocol.grpc.cloudevents.ConsumerServiceGrpc.ConsumerServiceBlockingStub; +import org.apache.eventmesh.common.protocol.grpc.cloudevents.ConsumerServiceGrpc.ConsumerServiceStub; +import org.apache.eventmesh.common.protocol.grpc.cloudevents.HeartbeatServiceGrpc; +import org.apache.eventmesh.common.protocol.grpc.cloudevents.HeartbeatServiceGrpc.HeartbeatServiceBlockingStub; +import org.apache.eventmesh.common.protocol.grpc.common.ClientType; +import org.apache.eventmesh.common.protocol.grpc.common.EventMeshCloudEventUtils; +import org.apache.eventmesh.common.protocol.grpc.common.GrpcType; +import org.apache.eventmesh.common.protocol.grpc.common.ProtocolKey; +import org.apache.eventmesh.common.protocol.grpc.common.Response; +import org.apache.eventmesh.common.protocol.grpc.common.StatusCode; +import org.apache.eventmesh.common.utils.JsonUtils; + +import org.apache.commons.collections4.MapUtils; + +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.Collectors; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Data +public class EventMeshGrpcConsumer implements AutoCloseable { + + private static final String SDK_STREAM_URL = "grpc_stream"; + private ManagedChannel channel; + private final EventMeshGrpcClientConfig clientConfig; + + private final Map subscriptionMap = new ConcurrentHashMap<>(); + + private final ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), + new EventMeshThreadFactory("GRPCClientScheduler", true)); + + private ConsumerServiceBlockingStub consumerClient; + private ConsumerServiceStub consumerAsyncClient; + private HeartbeatServiceBlockingStub heartbeatClient; + + private ReceiveMsgHook listener; + private SubStreamHandler subStreamHandler; + + public EventMeshGrpcConsumer(final EventMeshGrpcClientConfig clientConfig) { + this.clientConfig = clientConfig; + } + + public void init() { + this.channel = ManagedChannelBuilder.forAddress(clientConfig.getServerAddr(), clientConfig.getServerPort()).usePlaintext() + .build(); + this.consumerClient = ConsumerServiceGrpc.newBlockingStub(channel); + this.consumerAsyncClient = ConsumerServiceGrpc.newStub(channel); + this.heartbeatClient = HeartbeatServiceGrpc.newBlockingStub(channel); + heartBeat(); + } + + /** + * Subscribes to an event at a specified URL(Webhook). + * + * @param subscriptionItems The list of subscription items. + * @param url The URL to subscribe to. + * @return A response containing information about the subscription result. + */ + public Response subscribe(final List subscriptionItems, final String url) { + log.info("Create subscription: {} , url: {}", subscriptionItems, url); + + addSubscription(subscriptionItems, url, GrpcType.WEBHOOK); + + return subscribeWebhook(subscriptionItems, url); + } + + /** + * Subscribes to a streaming. + * + * @param subscriptionItems The list of subscription items for streaming. + */ + public void subscribe(final List subscriptionItems) { + log.info("Create streaming subscription: {}", subscriptionItems); + + if (listener == null) { + log.error("Error in subscriber, no Event Listener is registered."); + return; + } + + addSubscription(subscriptionItems, SDK_STREAM_URL, GrpcType.STREAM); + + CloudEvent subscription = EventMeshCloudEventBuilder.buildEventSubscription(clientConfig, EventMeshProtocolType.EVENT_MESH_MESSAGE, null, + subscriptionItems); + synchronized (this) { + if (subStreamHandler == null) { + subStreamHandler = new SubStreamHandler<>(consumerAsyncClient, clientConfig, listener); + subStreamHandler.start(); + } + } + subStreamHandler.sendSubscription(subscription); + } + + private Response subscribeWebhook(List subscriptionItems, String url) { + final CloudEvent subscription = EventMeshCloudEventBuilder.buildEventSubscription(clientConfig, EventMeshProtocolType.EVENT_MESH_MESSAGE, + url, subscriptionItems); + try { + CloudEvent response = consumerClient.subscribe(subscription); + log.info("Received response:{}", response); + return Response.builder() + .respCode(EventMeshCloudEventUtils.getResponseCode(response)) + .respMsg(EventMeshCloudEventUtils.getResponseMessage(response)) + .respTime(EventMeshCloudEventUtils.getResponseTime(response)) + .build(); + } catch (Exception e) { + log.error("Error in subscribe.", e); + } + return null; + } + + private void addSubscription(final List subscriptionItems, final String url, final GrpcType grpcType) { + for (SubscriptionItem item : subscriptionItems) { + subscriptionMap.putIfAbsent(item.getTopic(), new SubscriptionInfo(item, url, grpcType)); + } + } + + private void removeSubscription(final List subscriptionItems) { + Objects.requireNonNull(subscriptionItems, "subscriptionItems can not be null"); + subscriptionItems.forEach(item -> subscriptionMap.remove(item.getTopic())); + } + + public Response unsubscribe(final List subscriptionItems, final String url) { + log.info("Removing subscription: {}, url:{}", subscriptionItems, url); + + removeSubscription(subscriptionItems); + + final CloudEvent cloudEvent = EventMeshCloudEventBuilder.buildEventSubscription(clientConfig, EventMeshProtocolType.EVENT_MESH_MESSAGE, url, + subscriptionItems); + try { + final CloudEvent response = consumerClient.unsubscribe(cloudEvent); + log.info("Received response:{}", response); + return Response.builder() + .respCode(EventMeshCloudEventUtils.getResponseCode(response)) + .respMsg(EventMeshCloudEventUtils.getResponseMessage(response)) + .respTime(EventMeshCloudEventUtils.getResponseTime(response)) + .build(); + } catch (Exception e) { + log.error("Error in unsubscribe.", e); + } + return null; + } + + public Response unsubscribe(final List subscriptionItems) { + Objects.requireNonNull(subscriptionItems, "subscriptionItems can not be null"); + log.info("Removing subscription stream: {}", subscriptionItems); + + removeSubscription(subscriptionItems); + + final CloudEvent cloudEvent = EventMeshCloudEventBuilder.buildEventSubscription(clientConfig, EventMeshProtocolType.EVENT_MESH_MESSAGE, null, + subscriptionItems); + + try { + final CloudEvent response = consumerClient.unsubscribe(cloudEvent); + Response parsedResponse = Response.builder() + .respCode(EventMeshCloudEventUtils.getResponseCode(response)) + .respMsg(EventMeshCloudEventUtils.getResponseMessage(response)) + .respTime(EventMeshCloudEventUtils.getResponseTime(response)) + .build(); + log.info("Received response:{}", parsedResponse); + + // there is no stream subscriptions, stop the subscription stream handler + synchronized (this) { + if (MapUtils.isEmpty(subscriptionMap) && subStreamHandler != null) { + subStreamHandler.close(); + } + } + return parsedResponse; + } catch (Exception e) { + log.error("Error in unsubscribe.", e); + } + return null; + } + + public synchronized void registerListener(final ReceiveMsgHook listener) { + if (this.listener == null) { + this.listener = listener; + } + } + + private void heartBeat() { + final Map attributeValueMap = EventMeshCloudEventBuilder.buildCommonCloudEventAttributes(clientConfig, + EventMeshProtocolType.EVENT_MESH_MESSAGE); + + scheduler.scheduleAtFixedRate(() -> { + if (MapUtils.isEmpty(subscriptionMap)) { + return; + } + Map ext = new HashMap<>(attributeValueMap); + ext.put(ProtocolKey.CONSUMERGROUP, CloudEventAttributeValue.newBuilder().setCeString(clientConfig.getConsumerGroup()).build()); + ext.put(ProtocolKey.CLIENT_TYPE, CloudEventAttributeValue.newBuilder().setCeInteger(ClientType.SUB.getType()).build()); + ext.put(ProtocolKey.DATA_CONTENT_TYPE, + CloudEventAttributeValue.newBuilder().setCeString(EventMeshDataContentType.JSON.getCode()).build()); + final CloudEvent.Builder heartbeatBuilder = CloudEvent.newBuilder().putAllAttributes(ext); + List heartbeatItems = subscriptionMap.entrySet().stream() + .map(entry -> HeartbeatItem.builder().topic(entry.getKey()).url(entry.getValue().getUrl()).build()).collect(toList()); + CloudEvent heartbeat = heartbeatBuilder.setTextData(JsonUtils.toJSONString(heartbeatItems)).build(); + + try { + CloudEvent cloudEventResp = heartbeatClient.heartbeat(heartbeat); + assert cloudEventResp != null; + Response response = Response.builder() + .respCode(EventMeshCloudEventUtils.getResponseCode(cloudEventResp)) + .respMsg(EventMeshCloudEventUtils.getResponseMessage(cloudEventResp)) + .respTime(EventMeshCloudEventUtils.getResponseTime(cloudEventResp)) + .build(); + log.debug("Grpc Consumer Heartbeat cloudEvent: {}", response); + if (StatusCode.CLIENT_RESUBSCRIBE.getRetCode().equals(response.getRespCode())) { + resubscribe(); + } + } catch (Exception e) { + log.error("Error in sending out heartbeat.", e); + } + }, 10_000, EventMeshCommon.HEARTBEAT, TimeUnit.MILLISECONDS); + + log.info("Grpc Consumer Heartbeat started."); + } + + private void resubscribe() { + if (subscriptionMap.isEmpty()) { + return; + } + final Collection values = subscriptionMap.values(); + final AtomicBoolean isStreamSub = new AtomicBoolean(false); + for (SubscriptionInfo info : values) { + if (info.grpcType == GrpcType.STREAM) { + isStreamSub.compareAndSet(false, true); + break; + } + } + final Map> subscriptionGroup = values.stream() + .collect(Collectors.groupingBy(SubscriptionInfo::getUrl, mapping(SubscriptionInfo::getSubscriptionItem, toList()))); + + subscriptionGroup.forEach((url, items) -> { + if (isStreamSub.get()) { + CloudEvent subscription = EventMeshCloudEventBuilder.buildEventSubscription(clientConfig, EventMeshProtocolType.EVENT_MESH_MESSAGE, + url, + items); + subStreamHandler.sendSubscription(subscription); + } else { + subscribeWebhook(items, url); + } + + }); + } + + @Override + public void close() { + if (this.subStreamHandler != null) { + this.subStreamHandler.close(); + } + + if (this.channel != null) { + channel.shutdown(); + } + + if (this.scheduler != null) { + scheduler.shutdown(); + } + } + + private static class SubscriptionInfo { + + private transient SubscriptionItem subscriptionItem; + private transient String url; + private GrpcType grpcType; + + SubscriptionInfo(final SubscriptionItem subscriptionItem, final String url, final GrpcType grpcType) { + this.subscriptionItem = subscriptionItem; + this.url = url; + this.grpcType = grpcType; + } + + public GrpcType getGrpcType() { + return grpcType; + } + + public SubscriptionItem getSubscriptionItem() { + return subscriptionItem; + } + + public void setSubscriptionItem(final SubscriptionItem subscriptionItem) { + this.subscriptionItem = subscriptionItem; + } + + public String getUrl() { + return url; + } + + public void setUrl(final String url) { + this.url = url; + } + } +} diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/consumer/ReceiveMsgHook.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/consumer/ReceiveMsgHook.java new file mode 100644 index 0000000000..24b8ca0ae4 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/consumer/ReceiveMsgHook.java @@ -0,0 +1,39 @@ +/* + * 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.client.grpc.consumer; + +import org.apache.eventmesh.common.enums.EventMeshProtocolType; + +import java.util.Optional; + +/** + * @param + */ +public interface ReceiveMsgHook { + + /** + * Handle the received message, return the response message. + * + * @param msg + * @return + */ + Optional handle(T msg) throws Exception; + + EventMeshProtocolType getProtocolType(); + +} diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/consumer/SubStreamHandler.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/consumer/SubStreamHandler.java new file mode 100644 index 0000000000..d34a0c79b1 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/consumer/SubStreamHandler.java @@ -0,0 +1,160 @@ +/* + * 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.client.grpc.consumer; + +import org.apache.eventmesh.client.grpc.config.EventMeshGrpcClientConfig; +import org.apache.eventmesh.client.grpc.util.EventMeshCloudEventBuilder; +import org.apache.eventmesh.common.enums.EventMeshDataContentType; +import org.apache.eventmesh.common.protocol.grpc.cloudevents.CloudEvent; +import org.apache.eventmesh.common.protocol.grpc.cloudevents.CloudEvent.CloudEventAttributeValue; +import org.apache.eventmesh.common.protocol.grpc.cloudevents.ConsumerServiceGrpc.ConsumerServiceStub; +import org.apache.eventmesh.common.protocol.grpc.common.EventMeshCloudEventUtils; +import org.apache.eventmesh.common.protocol.grpc.common.ProtocolKey; + +import java.io.Serializable; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.CountDownLatch; + +import io.grpc.stub.StreamObserver; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class SubStreamHandler extends Thread implements Serializable { + + private final transient CountDownLatch latch = new CountDownLatch(1); + + private final transient ConsumerServiceStub consumerAsyncClient; + + private final transient EventMeshGrpcClientConfig clientConfig; + + private transient StreamObserver sender; + + private final ReceiveMsgHook listener; + + public SubStreamHandler(final ConsumerServiceStub consumerAsyncClient, final EventMeshGrpcClientConfig clientConfig, + final ReceiveMsgHook listener) { + this.consumerAsyncClient = consumerAsyncClient; + this.clientConfig = clientConfig; + this.listener = listener; + } + + public void sendSubscription(final CloudEvent subscription) { + synchronized (this) { + if (this.sender == null) { + this.sender = consumerAsyncClient.subscribeStream(createReceiver()); + } + } + senderOnNext(subscription); + } + + private StreamObserver createReceiver() { + return new StreamObserver() { + + @Override + public void onNext(final CloudEvent message) { + T msg = EventMeshCloudEventBuilder.buildMessageFromEventMeshCloudEvent(message, listener.getProtocolType()); + if (msg instanceof Set) { + log.info("Received message from Server:{}", message); + } else { + log.info("Received message from Server.|seq={}|uniqueId={}|", + EventMeshCloudEventUtils.getSeqNum(message), EventMeshCloudEventUtils.getUniqueId(message)); + CloudEvent streamReply = null; + try { + Optional reply = listener.handle(msg); + if (reply.isPresent()) { + streamReply = buildReplyMessage(message, reply.get()); + } + } catch (Exception e) { + log.error("Error in handling reply message.|seq={}|uniqueId={}|", + EventMeshCloudEventUtils.getSeqNum(message), EventMeshCloudEventUtils.getUniqueId(message), e); + } + if (streamReply != null) { + log.info("Sending reply message to Server.|seq={}|uniqueId={}|", + EventMeshCloudEventUtils.getSeqNum(streamReply), EventMeshCloudEventUtils.getUniqueId(streamReply)); + senderOnNext(streamReply); + } + } + } + + @Override + public void onError(final Throwable t) { + log.error("Received Server side error", t); + } + + @Override + public void onCompleted() { + log.info("Finished receiving messages from server."); + close(); + } + }; + } + + private CloudEvent buildReplyMessage(final CloudEvent reqMessage, final T replyMessage) { + final CloudEvent cloudEvent = EventMeshCloudEventBuilder.buildEventMeshCloudEvent(replyMessage, + clientConfig, listener.getProtocolType()); + + return CloudEvent.newBuilder(cloudEvent).putAllAttributes(reqMessage.getAttributesMap()).putAllAttributes(cloudEvent.getAttributesMap()) + .putAttributes(ProtocolKey.DATA_CONTENT_TYPE, + CloudEventAttributeValue.newBuilder().setCeString(EventMeshDataContentType.JSON.getCode()).build()) + // Indicate that it is a subscription response + .putAttributes(ProtocolKey.SUB_MESSAGE_TYPE, CloudEventAttributeValue.newBuilder().setCeString(ProtocolKey.SUB_REPLY_MESSAGE).build()) + .build(); + } + + @Override + public void run() { + try { + latch.await(); + } catch (InterruptedException e) { + log.error("SubStreamHandler Thread interrupted", e); + Thread.currentThread().interrupt(); + } + } + + public void close() { + if (this.sender != null) { + senderOnComplete(); + } + + latch.countDown(); + + log.info("SubStreamHandler closed."); + } + + private void senderOnNext(final CloudEvent subscription) { + try { + synchronized (sender) { + sender.onNext(subscription); + } + } catch (Exception e) { + log.error("StreamObserver Error onNext", e); + } + } + + private void senderOnComplete() { + try { + synchronized (sender) { + sender.onCompleted(); + } + } catch (Exception e) { + log.error("StreamObserver Error onComplete", e); + } + } +} diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/exception/ProtocolNotSupportException.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/exception/ProtocolNotSupportException.java new file mode 100644 index 0000000000..ef89340a84 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/exception/ProtocolNotSupportException.java @@ -0,0 +1,80 @@ +/* + * 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.client.grpc.exception; + +public class ProtocolNotSupportException extends RuntimeException { + + /** + * Constructs a new runtime exception with {@code null} as its detail message. The cause is not initialized, and may subsequently be initialized + * by a call to {@link #initCause}. + */ + public ProtocolNotSupportException() { + super(); + } + + /** + * Constructs a new runtime exception with the specified detail message. The cause is not initialized, and may subsequently be initialized by a + * call to {@link #initCause}. + * + * @param message the detail message. The detail message is saved for later retrieval by the {@link #getMessage()} method. + */ + public ProtocolNotSupportException(String message) { + super(message); + } + + /** + * Constructs a new runtime exception with the specified detail message and cause.

Note that the detail message associated with {@code cause} + * is not automatically incorporated in this runtime exception's detail message. + * + * @param message the detail message (which is saved for later retrieval by the {@link #getMessage()} method). + * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is permitted, and + * indicates that the cause is nonexistent or unknown.) + * @since 1.4 + */ + public ProtocolNotSupportException(String message, Throwable cause) { + super(message, cause); + } + + /** + * Constructs a new runtime exception with the specified cause and a detail message of (cause==null ? null : cause.toString()) (which + * typically contains the class and detail message of + * cause). This constructor is useful for runtime exceptions + * that are little more than wrappers for other throwables. + * + * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is permitted, and + * indicates that the cause is nonexistent or unknown.) + * @since 1.4 + */ + public ProtocolNotSupportException(Throwable cause) { + super(cause); + } + + /** + * Constructs a new runtime exception with the specified detail message, cause, suppression enabled or disabled, and writable stack trace enabled + * or disabled. + * + * @param message the detail message. + * @param cause the cause. (A {@code null} value is permitted, and indicates that the cause is nonexistent or unknown.) + * @param enableSuppression whether or not suppression is enabled or disabled + * @param writableStackTrace whether or not the stack trace should be writable + * @since 1.7 + */ + protected ProtocolNotSupportException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/producer/CloudEventProducer.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/producer/CloudEventProducer.java new file mode 100644 index 0000000000..3dc1288012 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/producer/CloudEventProducer.java @@ -0,0 +1,108 @@ +/* + * 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.client.grpc.producer; + +import org.apache.eventmesh.client.grpc.config.EventMeshGrpcClientConfig; +import org.apache.eventmesh.client.grpc.util.EventMeshCloudEventBuilder; +import org.apache.eventmesh.common.enums.EventMeshProtocolType; +import org.apache.eventmesh.common.protocol.grpc.cloudevents.CloudEvent; +import org.apache.eventmesh.common.protocol.grpc.cloudevents.CloudEventBatch; +import org.apache.eventmesh.common.protocol.grpc.cloudevents.PublisherServiceGrpc.PublisherServiceBlockingStub; +import org.apache.eventmesh.common.protocol.grpc.common.EventMeshCloudEventUtils; +import org.apache.eventmesh.common.protocol.grpc.common.Response; +import org.apache.eventmesh.common.utils.LogUtil; + +import org.apache.commons.collections4.CollectionUtils; + +import java.util.List; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class CloudEventProducer implements GrpcProducer { + + private static final EventMeshProtocolType PROTOCOL_TYPE = EventMeshProtocolType.CLOUD_EVENTS; + + private final transient EventMeshGrpcClientConfig clientConfig; + + private final transient PublisherServiceBlockingStub publisherClient; + + public CloudEventProducer(final EventMeshGrpcClientConfig clientConfig, + final PublisherServiceBlockingStub publisherClient) { + this.clientConfig = clientConfig; + this.publisherClient = publisherClient; + } + + @Override + public Response publish(final List events) { + log.info("BatchPublish message, batch size={}", events.size()); + + if (CollectionUtils.isEmpty(events)) { + return null; + } + + final CloudEventBatch cloudEventBatch = EventMeshCloudEventBuilder.buildEventMeshCloudEventBatch(events, clientConfig, PROTOCOL_TYPE); + try { + final CloudEvent response = publisherClient.batchPublish(cloudEventBatch); + Response parsedResponse = Response.builder() + .respCode(EventMeshCloudEventUtils.getResponseCode(response)) + .respMsg(EventMeshCloudEventUtils.getResponseMessage(response)) + .respTime(EventMeshCloudEventUtils.getResponseTime(response)) + .build(); + + log.info("Received response:{}", parsedResponse); + return parsedResponse; + } catch (Exception e) { + log.error("Error in BatchPublish message {}", events, e); + } + return null; + } + + @Override + public Response publish(final io.cloudevents.CloudEvent cloudEvent) { + LogUtil.info(log, "Publish message: {}", cloudEvent::toString); + CloudEvent enhancedMessage = EventMeshCloudEventBuilder.buildEventMeshCloudEvent(cloudEvent, clientConfig, PROTOCOL_TYPE); + try { + final CloudEvent response = publisherClient.publish(enhancedMessage); + Response parsedResponse = Response.builder() + .respCode(EventMeshCloudEventUtils.getResponseCode(response)) + .respMsg(EventMeshCloudEventUtils.getResponseMessage(response)) + .respTime(EventMeshCloudEventUtils.getResponseTime(response)) + .build(); + log.info("Received response:{} ", parsedResponse); + return parsedResponse; + } catch (Exception e) { + log.error("Error in publishing message {}", cloudEvent, e); + } + return null; + } + + @Override + public io.cloudevents.CloudEvent requestReply(final io.cloudevents.CloudEvent cloudEvent, final long timeout) { + log.info("RequestReply message {}", cloudEvent); + final CloudEvent enhancedMessage = EventMeshCloudEventBuilder.buildEventMeshCloudEvent(cloudEvent, clientConfig, PROTOCOL_TYPE); + try { + final CloudEvent reply = publisherClient.requestReply(enhancedMessage); + log.info("Received reply message:{}", reply); + return EventMeshCloudEventBuilder.buildMessageFromEventMeshCloudEvent(reply, PROTOCOL_TYPE); + } catch (Exception e) { + log.error("Error in RequestReply message {}", cloudEvent, e); + } + return null; + } +} diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/producer/EventMeshGrpcProducer.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/producer/EventMeshGrpcProducer.java new file mode 100644 index 0000000000..db700276be --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/producer/EventMeshGrpcProducer.java @@ -0,0 +1,108 @@ +/* + * 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.client.grpc.producer; + +import org.apache.eventmesh.client.grpc.config.EventMeshGrpcClientConfig; +import org.apache.eventmesh.common.EventMeshCommon; +import org.apache.eventmesh.common.EventMeshMessage; +import org.apache.eventmesh.common.protocol.grpc.cloudevents.PublisherServiceGrpc; +import org.apache.eventmesh.common.protocol.grpc.cloudevents.PublisherServiceGrpc.PublisherServiceBlockingStub; +import org.apache.eventmesh.common.protocol.grpc.common.Response; +import org.apache.eventmesh.common.utils.LogUtil; + +import org.apache.commons.collections4.CollectionUtils; + +import java.util.List; + +import io.cloudevents.CloudEvent; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Data +public class EventMeshGrpcProducer implements AutoCloseable { + + private static final String PROTOCOL_TYPE = EventMeshCommon.EM_MESSAGE_PROTOCOL_NAME; + + private final transient EventMeshGrpcClientConfig clientConfig; + + private final transient ManagedChannel channel; + + private PublisherServiceBlockingStub publisherClient; + + private CloudEventProducer cloudEventProducer; + + private EventMeshMessageProducer eventMeshMessageProducer; + + public EventMeshGrpcProducer(EventMeshGrpcClientConfig clientConfig) { + this.clientConfig = clientConfig; + this.channel = ManagedChannelBuilder.forAddress(clientConfig.getServerAddr(), clientConfig.getServerPort()).usePlaintext().build(); + this.publisherClient = PublisherServiceGrpc.newBlockingStub(channel); + this.cloudEventProducer = new CloudEventProducer(clientConfig, publisherClient); + this.eventMeshMessageProducer = new EventMeshMessageProducer(clientConfig, publisherClient); + } + + public Response publish(T message) { + LogUtil.info(log, "Publish message: {}", message::toString); + if (message instanceof CloudEvent) { + return cloudEventProducer.publish((CloudEvent) message); + } else if (message instanceof EventMeshMessage) { + return eventMeshMessageProducer.publish((EventMeshMessage) message); + } else { + throw new IllegalArgumentException("Not support message " + message.getClass().getName()); + } + } + + @SuppressWarnings("unchecked") + public Response publish(List messageList) { + log.info("BatchPublish message: {}", messageList); + + if (CollectionUtils.isEmpty(messageList)) { + return null; + } + + T target = messageList.get(0); + if (target instanceof CloudEvent) { + return cloudEventProducer.publish((List) messageList); + } else if (target instanceof EventMeshMessage) { + return eventMeshMessageProducer.publish((List) messageList); + } else { + throw new IllegalArgumentException("Not support message " + target.getClass().getName()); + } + } + + public T requestReply(final T message, final long timeout) { + + if (message instanceof CloudEvent) { + CloudEvent cloudEvent = cloudEventProducer.requestReply((CloudEvent) message, timeout); + return (T) cloudEvent; + } else if (message instanceof EventMeshMessage) { + return (T) eventMeshMessageProducer.requestReply((EventMeshMessage) message, timeout); + } else { + throw new IllegalArgumentException("Not support message " + message.getClass().getName()); + } + } + + @Override + public void close() { + channel.shutdown(); + } +} diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/producer/EventMeshMessageProducer.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/producer/EventMeshMessageProducer.java new file mode 100644 index 0000000000..229fb29715 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/producer/EventMeshMessageProducer.java @@ -0,0 +1,111 @@ +/* + * 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.client.grpc.producer; + +import org.apache.eventmesh.client.grpc.config.EventMeshGrpcClientConfig; +import org.apache.eventmesh.client.grpc.util.EventMeshCloudEventBuilder; +import org.apache.eventmesh.common.EventMeshMessage; +import org.apache.eventmesh.common.enums.EventMeshProtocolType; +import org.apache.eventmesh.common.protocol.grpc.cloudevents.CloudEvent; +import org.apache.eventmesh.common.protocol.grpc.cloudevents.CloudEventBatch; +import org.apache.eventmesh.common.protocol.grpc.cloudevents.PublisherServiceGrpc.PublisherServiceBlockingStub; +import org.apache.eventmesh.common.protocol.grpc.common.EventMeshCloudEventUtils; +import org.apache.eventmesh.common.protocol.grpc.common.Response; + +import org.apache.commons.collections4.CollectionUtils; + +import java.util.List; +import java.util.concurrent.TimeUnit; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class EventMeshMessageProducer implements GrpcProducer { + + private static final EventMeshProtocolType PROTOCOL_TYPE = EventMeshProtocolType.EVENT_MESH_MESSAGE; + + private final EventMeshGrpcClientConfig clientConfig; + + private final PublisherServiceBlockingStub publisherClient; + + public EventMeshMessageProducer(EventMeshGrpcClientConfig clientConfig, PublisherServiceBlockingStub publisherClient) { + this.clientConfig = clientConfig; + this.publisherClient = publisherClient; + } + + @Override + public Response publish(EventMeshMessage message) { + + if (null == message) { + return null; + } + + log.debug("Publish message: {}", message); + CloudEvent cloudEvent = EventMeshCloudEventBuilder.buildEventMeshCloudEvent(message, clientConfig, PROTOCOL_TYPE); + try { + CloudEvent response = publisherClient.publish(cloudEvent); + Response parsedResponse = Response.builder() + .respCode(EventMeshCloudEventUtils.getResponseCode(response)) + .respMsg(EventMeshCloudEventUtils.getResponseMessage(response)) + .respTime(EventMeshCloudEventUtils.getResponseTime(response)) + .build(); + log.info("Received response:{}", parsedResponse); + return parsedResponse; + } catch (Exception e) { + log.error("Error in publishing message {}", message, e); + } + return null; + } + + @Override + public Response publish(List messages) { + + if (CollectionUtils.isEmpty(messages)) { + return null; + } + CloudEventBatch cloudEventBatch = EventMeshCloudEventBuilder.buildEventMeshCloudEventBatch(messages, clientConfig, PROTOCOL_TYPE); + try { + CloudEvent response = publisherClient.batchPublish(cloudEventBatch); + Response parsedResponse = Response.builder() + .respCode(EventMeshCloudEventUtils.getResponseCode(response)) + .respMsg(EventMeshCloudEventUtils.getResponseMessage(response)) + .respTime(EventMeshCloudEventUtils.getResponseTime(response)) + .build(); + log.info("Received response:{}", parsedResponse); + return parsedResponse; + } catch (Exception e) { + log.error("Error in BatchPublish message {}", messages, e); + } + return null; + } + + @Override + public EventMeshMessage requestReply(EventMeshMessage message, long timeout) { + log.info("RequestReply message:{}", message); + + final CloudEvent cloudEvent = EventMeshCloudEventBuilder.buildEventMeshCloudEvent(message, clientConfig, PROTOCOL_TYPE); + try { + final CloudEvent reply = publisherClient.withDeadlineAfter(timeout, TimeUnit.MILLISECONDS).requestReply(cloudEvent); + log.info("Received reply message:{}", reply); + return EventMeshCloudEventBuilder.buildMessageFromEventMeshCloudEvent(reply, PROTOCOL_TYPE); + } catch (Exception e) { + log.error("Error in RequestReply message {}", message, e); + } + return null; + } +} diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/producer/GrpcProducer.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/producer/GrpcProducer.java new file mode 100644 index 0000000000..4c63485b44 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/producer/GrpcProducer.java @@ -0,0 +1,36 @@ +/* + * 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.client.grpc.producer; + +import org.apache.eventmesh.common.protocol.grpc.common.Response; + +import java.util.List; + +/** + * + * @param + */ +public interface GrpcProducer { + + Response publish(T message); + + Response publish(List messages); + + T requestReply(T message, long timeout); + +} diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/util/EventMeshCloudEventBuilder.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/util/EventMeshCloudEventBuilder.java new file mode 100644 index 0000000000..f89715054b --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/java/org/apache/eventmesh/client/grpc/util/EventMeshCloudEventBuilder.java @@ -0,0 +1,286 @@ +/* + * 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.client.grpc.util; + +import org.apache.eventmesh.client.grpc.config.EventMeshGrpcClientConfig; +import org.apache.eventmesh.client.grpc.exception.ProtocolNotSupportException; +import org.apache.eventmesh.common.Constants; +import org.apache.eventmesh.common.EventMeshMessage; +import org.apache.eventmesh.common.enums.EventMeshProtocolType; +import org.apache.eventmesh.common.protocol.SubscriptionItem; +import org.apache.eventmesh.common.protocol.grpc.cloudevents.CloudEvent; +import org.apache.eventmesh.common.protocol.grpc.cloudevents.CloudEvent.CloudEventAttributeValue; +import org.apache.eventmesh.common.protocol.grpc.cloudevents.CloudEventBatch; +import org.apache.eventmesh.common.protocol.grpc.common.EventMeshCloudEventUtils; +import org.apache.eventmesh.common.protocol.grpc.common.ProtoSupport; +import org.apache.eventmesh.common.protocol.grpc.common.ProtocolKey; +import org.apache.eventmesh.common.utils.IPUtils; +import org.apache.eventmesh.common.utils.JsonUtils; +import org.apache.eventmesh.common.utils.RandomStringUtils; +import org.apache.eventmesh.common.utils.ThreadUtils; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; + +import java.net.URI; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; + +import io.cloudevents.SpecVersion; +import io.cloudevents.core.builder.CloudEventBuilder; +import io.cloudevents.core.format.EventFormat; +import io.cloudevents.core.provider.EventFormatProvider; +import io.cloudevents.protobuf.ProtobufFormat; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.google.protobuf.Any; +import com.google.protobuf.ByteString; +import com.google.protobuf.InvalidProtocolBufferException; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class EventMeshCloudEventBuilder { + + private static final String CLOUD_EVENT_TYPE = "org.apache.eventmesh"; + + private static final EventFormat eventProtoFormat = EventFormatProvider.getInstance().resolveFormat(ProtobufFormat.PROTO_CONTENT_TYPE); + + public static Map buildCommonCloudEventAttributes(EventMeshGrpcClientConfig clientConfig, + EventMeshProtocolType protocolType) { + final Map attributeValueMap = new HashMap<>(64); + attributeValueMap.put(ProtocolKey.ENV, CloudEventAttributeValue.newBuilder().setCeString(clientConfig.getEnv()).build()); + attributeValueMap.put(ProtocolKey.IDC, CloudEventAttributeValue.newBuilder().setCeString(clientConfig.getIdc()).build()); + attributeValueMap.put(ProtocolKey.IP, CloudEventAttributeValue.newBuilder().setCeString(IPUtils.getLocalAddress()).build()); + attributeValueMap.put(ProtocolKey.PID, CloudEventAttributeValue.newBuilder().setCeString(Long.toString(ThreadUtils.getPID())).build()); + attributeValueMap.put(ProtocolKey.SYS, CloudEventAttributeValue.newBuilder().setCeString(clientConfig.getSys()).build()); + attributeValueMap.put(ProtocolKey.LANGUAGE, CloudEventAttributeValue.newBuilder().setCeString(clientConfig.getLanguage()).build()); + attributeValueMap.put(ProtocolKey.USERNAME, CloudEventAttributeValue.newBuilder().setCeString(clientConfig.getUserName()).build()); + attributeValueMap.put(ProtocolKey.PASSWD, CloudEventAttributeValue.newBuilder().setCeString(clientConfig.getPassword()).build()); + attributeValueMap.put(ProtocolKey.PROTOCOL_TYPE, CloudEventAttributeValue.newBuilder().setCeString(protocolType.protocolTypeName()).build()); + attributeValueMap.put(ProtocolKey.PROTOCOL_VERSION, CloudEventAttributeValue.newBuilder().setCeString(SpecVersion.V1.toString()).build()); + + return attributeValueMap; + } + + public static CloudEvent buildEventSubscription(EventMeshGrpcClientConfig clientConfig, EventMeshProtocolType protocolType, String url, + List subscriptionItems) { + + if (CollectionUtils.isEmpty(subscriptionItems)) { + return null; + } + Set subscriptionItemSet = new HashSet<>(); + subscriptionItemSet.addAll(subscriptionItems); + + final Map attributeValueMap = buildCommonCloudEventAttributes(clientConfig, protocolType); + attributeValueMap.put(ProtocolKey.CONSUMERGROUP, CloudEventAttributeValue.newBuilder().setCeString(clientConfig.getConsumerGroup()).build()); + attributeValueMap.put(ProtocolKey.DATA_CONTENT_TYPE, CloudEventAttributeValue.newBuilder().setCeString("application/json").build()); + if (StringUtils.isNotBlank(url)) { + attributeValueMap.put(ProtocolKey.URL, CloudEventAttributeValue.newBuilder().setCeString(url).build()); + } + return CloudEvent.newBuilder() + .setId(RandomStringUtils.generateUUID()) + .setSource(URI.create("/").toString()) + .setSpecVersion(SpecVersion.V1.toString()) + .setType(CLOUD_EVENT_TYPE) + .setTextData(JsonUtils.toJSONString(subscriptionItemSet)) + .putAllAttributes(attributeValueMap) + .build(); + } + + /** + * @param message + * @param clientConfig + * @param protocolType + * @param + * @return CloudEvent + * @see context-attributes + */ + public static CloudEvent buildEventMeshCloudEvent(final T message, final EventMeshGrpcClientConfig clientConfig, + final EventMeshProtocolType protocolType) { + + switch (protocolType) { + case CLOUD_EVENTS: { + if (!(message instanceof io.cloudevents.CloudEvent)) { + throw new ClassCastException(message.getClass().getName() + " can not cast io.cloudevents.CloudEvent"); + } + return switchCloudEvent2EventMeshCloudEvent((io.cloudevents.CloudEvent) message, clientConfig, protocolType); + } + case EVENT_MESH_MESSAGE: { + if (!(message instanceof EventMeshMessage)) { + throw new ClassCastException(message.getClass().getName() + " can not cast" + EventMeshMessage.class.getName()); + } + return switchEventMeshMessage2EventMeshCloudEvent((EventMeshMessage) message, clientConfig, protocolType); + } + case OPEN_MESSAGE: + return null; + default: + throw new ProtocolNotSupportException("Protocol Type [" + protocolType + "] not support"); + } + } + + private static CloudEvent switchEventMeshMessage2EventMeshCloudEvent(EventMeshMessage message, EventMeshGrpcClientConfig clientConfig, + EventMeshProtocolType protocolType) { + final String ttl = message.getProp(Constants.EVENTMESH_MESSAGE_CONST_TTL) == null + ? Constants.DEFAULT_EVENTMESH_MESSAGE_TTL + : message.getProp(Constants.EVENTMESH_MESSAGE_CONST_TTL); + final Map props = message.getProp() == null ? new HashMap<>() : message.getProp(); + final String seqNum = message.getBizSeqNo() == null ? RandomStringUtils.generateNum(30) : message.getBizSeqNo(); + final String uniqueId = message.getUniqueId() == null ? RandomStringUtils.generateNum(30) : message.getUniqueId(); + final String dataContentType = props.computeIfAbsent(ProtocolKey.DATA_CONTENT_TYPE, key -> "text/plain"); + final Map attributeValueMap = buildCommonCloudEventAttributes(clientConfig, protocolType); + + attributeValueMap.put(ProtocolKey.TTL, CloudEventAttributeValue.newBuilder().setCeString(ttl).build()); + attributeValueMap.put(ProtocolKey.SEQ_NUM, CloudEventAttributeValue.newBuilder().setCeString(seqNum).build()); + attributeValueMap.put(ProtocolKey.UNIQUE_ID, CloudEventAttributeValue.newBuilder().setCeString(uniqueId).build()); + attributeValueMap.put(ProtocolKey.PROTOCOL_DESC, + CloudEventAttributeValue.newBuilder().setCeString(Constants.PROTOCOL_DESC_GRPC_CLOUD_EVENT).build()); + attributeValueMap.put(ProtocolKey.PRODUCERGROUP, + CloudEventAttributeValue.newBuilder().setCeString(clientConfig.getProducerGroup()).build()); + if (null != message.getTopic()) { + attributeValueMap.put(ProtocolKey.SUBJECT, CloudEventAttributeValue.newBuilder().setCeString(message.getTopic()).build()); + } + attributeValueMap.put(ProtocolKey.DATA_CONTENT_TYPE, CloudEventAttributeValue.newBuilder().setCeString("text/plain").build()); + props.forEach((key, value) -> attributeValueMap.put(key, CloudEventAttributeValue.newBuilder().setCeString(value).build())); + CloudEvent.Builder builder = CloudEvent.newBuilder() + .setId(RandomStringUtils.generateUUID()) + .setSource(URI.create("/").toString()) + .setSpecVersion(SpecVersion.V1.toString()) + .setType(CLOUD_EVENT_TYPE) + .putAllAttributes(attributeValueMap); + final String content = message.getContent(); + if (StringUtils.isNotEmpty(content)) { + if (ProtoSupport.isTextContent(dataContentType)) { + builder.setTextData(content); + } else if (ProtoSupport.isProtoContent(dataContentType)) { + try { + Any dataAsAny = Any.parseFrom(content.getBytes(Constants.DEFAULT_CHARSET)); + builder.setProtoData(dataAsAny); + } catch (InvalidProtocolBufferException e) { + throw new IllegalArgumentException("parse from byte[] to com.google.protobuf.Any error", e); + } + } else { + ByteString byteString = ByteString.copyFrom(content.getBytes(Constants.DEFAULT_CHARSET)); + builder.setBinaryData(byteString); + } + } + return builder.build(); + } + + private static CloudEvent switchCloudEvent2EventMeshCloudEvent(io.cloudevents.CloudEvent message, EventMeshGrpcClientConfig clientConfig, + EventMeshProtocolType protocolType) { + + CloudEventBuilder cloudEventBuilder = CloudEventBuilder.from(message); + + buildCloudEventIfAbsent(message, cloudEventBuilder, ProtocolKey.ENV, clientConfig.getEnv()); + buildCloudEventIfAbsent(message, cloudEventBuilder, ProtocolKey.IDC, clientConfig.getIdc()); + buildCloudEventIfAbsent(message, cloudEventBuilder, ProtocolKey.IP, Objects.requireNonNull(IPUtils.getLocalAddress())); + buildCloudEventIfAbsent(message, cloudEventBuilder, ProtocolKey.PID, Long.toString(ThreadUtils.getPID())); + buildCloudEventIfAbsent(message, cloudEventBuilder, ProtocolKey.SYS, clientConfig.getSys()); + buildCloudEventIfAbsent(message, cloudEventBuilder, ProtocolKey.LANGUAGE, Constants.LANGUAGE_JAVA); + buildCloudEventIfAbsent(message, cloudEventBuilder, ProtocolKey.PROTOCOL_TYPE, protocolType.protocolTypeName()); + buildCloudEventIfAbsent(message, cloudEventBuilder, ProtocolKey.PROTOCOL_DESC, Constants.PROTOCOL_DESC_GRPC_CLOUD_EVENT); + buildCloudEventIfAbsent(message, cloudEventBuilder, ProtocolKey.PROTOCOL_VERSION, message.getSpecVersion().toString()); + buildCloudEventIfAbsent(message, cloudEventBuilder, ProtocolKey.UNIQUE_ID, RandomStringUtils.generateNum(30)); + buildCloudEventIfAbsent(message, cloudEventBuilder, ProtocolKey.SEQ_NUM, RandomStringUtils.generateNum(30)); + buildCloudEventIfAbsent(message, cloudEventBuilder, ProtocolKey.USERNAME, clientConfig.getUserName()); + buildCloudEventIfAbsent(message, cloudEventBuilder, ProtocolKey.PASSWD, clientConfig.getPassword()); + buildCloudEventIfAbsent(message, cloudEventBuilder, ProtocolKey.PRODUCERGROUP, clientConfig.getProducerGroup()); + buildCloudEventIfAbsent(message, cloudEventBuilder, ProtocolKey.TTL, Constants.DEFAULT_EVENTMESH_MESSAGE_TTL); + + try { + return CloudEvent.parseFrom(eventProtoFormat.serialize(cloudEventBuilder.build())); + } catch (InvalidProtocolBufferException exc) { + log.error("Parse from CloudEvents CloudEvent bytes to EventMesh CloudEvent error", exc); + } + return null; + } + + private static void buildCloudEventIfAbsent(io.cloudevents.CloudEvent message, CloudEventBuilder cloudEventBuilder, + String extension, String value) { + if (Objects.isNull(message.getExtension(extension))) { + cloudEventBuilder.withExtension(extension, value); + } + } + + public static CloudEventBatch buildEventMeshCloudEventBatch(final List messageList, final EventMeshGrpcClientConfig clientConfig, + final EventMeshProtocolType protocolType) { + if (CollectionUtils.isEmpty(messageList)) { + return null; + } + List cloudEventList = messageList.stream().map(item -> buildEventMeshCloudEvent(item, clientConfig, protocolType)) + .collect(Collectors.toList()); + return CloudEventBatch.newBuilder().addAllEvents(cloudEventList).build(); + } + + @SuppressWarnings("unchecked") + public static T buildMessageFromEventMeshCloudEvent(final CloudEvent cloudEvent, final EventMeshProtocolType protocolType) { + + if (null == cloudEvent) { + return null; + } + final String seq = EventMeshCloudEventUtils.getSeqNum(cloudEvent); + final String uniqueId = EventMeshCloudEventUtils.getUniqueId(cloudEvent); + final String content = EventMeshCloudEventUtils.getDataContent(cloudEvent); + + // This is GRPC response cloudEvent + if (StringUtils.isEmpty(seq) && StringUtils.isEmpty(uniqueId)) { + // The SubscriptionItem collection contains the content for the subscription. + return (T) JsonUtils.parseTypeReferenceObject(content, + new TypeReference>>() { + + }); + } + if (null == protocolType) { + return null; + } + + switch (protocolType) { + case CLOUD_EVENTS: + return (T) switchEventMeshCloudEvent2CloudEvent(cloudEvent); + case EVENT_MESH_MESSAGE: + return (T) switchEventMeshCloudEvent2EventMeshMessage(cloudEvent); + case OPEN_MESSAGE: + default: + return null; + } + } + + private static io.cloudevents.CloudEvent switchEventMeshCloudEvent2CloudEvent(final CloudEvent cloudEvent) { + + return eventProtoFormat.deserialize(Objects.requireNonNull(cloudEvent).toByteArray()); + } + + private static EventMeshMessage switchEventMeshCloudEvent2EventMeshMessage(final CloudEvent cloudEvent) { + Map prop = new HashMap<>(); + Objects.requireNonNull(cloudEvent).getAttributesMap().forEach((key, value) -> prop.put(key, value.getCeString())); + return EventMeshMessage.builder() + .content(cloudEvent.getTextData()) + .topic(EventMeshCloudEventUtils.getSubject(cloudEvent)) + .bizSeqNo(EventMeshCloudEventUtils.getSeqNum(cloudEvent)) + .uniqueId(EventMeshCloudEventUtils.getUniqueId(cloudEvent)) + .prop(prop) + .build(); + } + +} \ No newline at end of file diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/resources/log4j2.xml b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/resources/log4j2.xml new file mode 100644 index 0000000000..90f56982b0 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/main/resources/log4j2.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/grpc/consumer/EventMeshGrpcConsumerTest.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/test/java/org/apache/eventmesh/client/grpc/consumer/EventMeshGrpcConsumerTest.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/grpc/consumer/EventMeshGrpcConsumerTest.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/test/java/org/apache/eventmesh/client/grpc/consumer/EventMeshGrpcConsumerTest.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/grpc/producer/CloudEventProducerTest.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/test/java/org/apache/eventmesh/client/grpc/producer/CloudEventProducerTest.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/grpc/producer/CloudEventProducerTest.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/test/java/org/apache/eventmesh/client/grpc/producer/CloudEventProducerTest.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/grpc/producer/EventMeshGrpcProducerTest.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/test/java/org/apache/eventmesh/client/grpc/producer/EventMeshGrpcProducerTest.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/grpc/producer/EventMeshGrpcProducerTest.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/test/java/org/apache/eventmesh/client/grpc/producer/EventMeshGrpcProducerTest.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/grpc/producer/EventMeshMessageProducerTest.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/test/java/org/apache/eventmesh/client/grpc/producer/EventMeshMessageProducerTest.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/grpc/producer/EventMeshMessageProducerTest.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/test/java/org/apache/eventmesh/client/grpc/producer/EventMeshMessageProducerTest.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/grpc/producer/MockCloudEvent.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/test/java/org/apache/eventmesh/client/grpc/producer/MockCloudEvent.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/grpc/producer/MockCloudEvent.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/test/java/org/apache/eventmesh/client/grpc/producer/MockCloudEvent.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/grpc/util/EventMeshCloudEventBuilderTest.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/test/java/org/apache/eventmesh/client/grpc/util/EventMeshCloudEventBuilderTest.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/grpc/util/EventMeshCloudEventBuilderTest.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/test/java/org/apache/eventmesh/client/grpc/util/EventMeshCloudEventBuilderTest.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/test/resources/application.properties b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/test/resources/application.properties new file mode 100644 index 0000000000..8bc9ce9a40 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/test/resources/application.properties @@ -0,0 +1,17 @@ +# +# 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. +# +server.port=8088 \ No newline at end of file diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/test/resources/log4j2.xml b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/test/resources/log4j2.xml new file mode 100644 index 0000000000..4297021f90 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-grpc/src/test/resources/log4j2.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/build.gradle b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/build.gradle new file mode 100644 index 0000000000..db15554031 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/build.gradle @@ -0,0 +1,64 @@ +/* + * 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. + */ + +def grpcVersion = '1.43.2' + +dependencies { + api project(":eventmesh-common") + + implementation "com.fasterxml.jackson.core:jackson-databind" + implementation "com.fasterxml.jackson.core:jackson-core" + implementation "com.fasterxml.jackson.core:jackson-annotations" + implementation "org.apache.commons:commons-collections4" + + implementation "io.netty:netty-all" + implementation "org.apache.httpcomponents:httpclient" + + implementation "io.grpc:grpc-protobuf:${grpcVersion}" + implementation "io.grpc:grpc-stub:${grpcVersion}" + implementation "io.grpc:grpc-netty:${grpcVersion}" + implementation "io.grpc:grpc-netty-shaded:${grpcVersion}" + implementation "io.cloudevents:cloudevents-protobuf" + + // protocol + api "io.cloudevents:cloudevents-core" + api "io.cloudevents:cloudevents-json-jackson" + api "io.openmessaging:openmessaging-api" + + testImplementation project(":eventmesh-common") + + testImplementation "com.fasterxml.jackson.core:jackson-databind" + testImplementation "com.fasterxml.jackson.core:jackson-core" + testImplementation "com.fasterxml.jackson.core:jackson-annotations" + + testImplementation "io.netty:netty-all" + testImplementation "org.apache.httpcomponents:httpclient" + + implementation "io.grpc:grpc-protobuf:${grpcVersion}" + implementation "io.grpc:grpc-stub:${grpcVersion}" + implementation "com.google.protobuf:protobuf-java-util:3.21.5" + compileOnly 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok' + + testCompileOnly 'org.projectlombok:lombok' + testAnnotationProcessor 'org.projectlombok:lombok' + + testImplementation "org.assertj:assertj-core" + + testImplementation "org.mockito:mockito-inline" + testImplementation "org.mockito:mockito-junit-jupiter" +} diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/gradle.properties b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/gradle.properties new file mode 100644 index 0000000000..b1312a0905 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/gradle.properties @@ -0,0 +1,16 @@ +# +# 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. +# diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/AbstractHttpClient.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/AbstractHttpClient.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/AbstractHttpClient.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/AbstractHttpClient.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/AbstractProducerHttpClient.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/AbstractProducerHttpClient.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/AbstractProducerHttpClient.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/AbstractProducerHttpClient.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/EventMeshRetObj.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/EventMeshRetObj.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/EventMeshRetObj.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/EventMeshRetObj.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/ProtocolConstant.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/ProtocolConstant.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/ProtocolConstant.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/ProtocolConstant.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/conf/EventMeshHttpClientConfig.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/conf/EventMeshHttpClientConfig.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/conf/EventMeshHttpClientConfig.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/conf/EventMeshHttpClientConfig.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/consumer/EventMeshHttpConsumer.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/consumer/EventMeshHttpConsumer.java similarity index 99% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/consumer/EventMeshHttpConsumer.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/consumer/EventMeshHttpConsumer.java index 6e9b94bec7..57eda0d92f 100644 --- a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/consumer/EventMeshHttpConsumer.java +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/consumer/EventMeshHttpConsumer.java @@ -22,8 +22,8 @@ import org.apache.eventmesh.client.http.conf.EventMeshHttpClientConfig; import org.apache.eventmesh.client.http.model.RequestParam; import org.apache.eventmesh.client.http.util.HttpUtils; -import org.apache.eventmesh.client.tcp.common.EventMeshCommon; import org.apache.eventmesh.common.Constants; +import org.apache.eventmesh.common.EventMeshCommon; import org.apache.eventmesh.common.EventMeshThreadFactory; import org.apache.eventmesh.common.ThreadPoolFactory; import org.apache.eventmesh.common.exception.EventMeshException; diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/model/RequestParam.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/model/RequestParam.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/model/RequestParam.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/model/RequestParam.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/CloudEventProducer.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/producer/CloudEventProducer.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/CloudEventProducer.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/producer/CloudEventProducer.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/EventMeshHttpProducer.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/producer/EventMeshHttpProducer.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/EventMeshHttpProducer.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/producer/EventMeshHttpProducer.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/EventMeshMessageProducer.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/producer/EventMeshMessageProducer.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/EventMeshMessageProducer.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/producer/EventMeshMessageProducer.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/EventMeshProtocolProducer.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/producer/EventMeshProtocolProducer.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/EventMeshProtocolProducer.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/producer/EventMeshProtocolProducer.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/OpenMessageProducer.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/producer/OpenMessageProducer.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/OpenMessageProducer.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/producer/OpenMessageProducer.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/RRCallback.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/producer/RRCallback.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/RRCallback.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/producer/RRCallback.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/RRCallbackResponseHandlerAdapter.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/producer/RRCallbackResponseHandlerAdapter.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/RRCallbackResponseHandlerAdapter.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/producer/RRCallbackResponseHandlerAdapter.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/ssl/MyX509TrustManager.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/ssl/MyX509TrustManager.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/ssl/MyX509TrustManager.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/ssl/MyX509TrustManager.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/util/HttpLoadBalanceUtils.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/util/HttpLoadBalanceUtils.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/util/HttpLoadBalanceUtils.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/util/HttpLoadBalanceUtils.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/util/HttpUtils.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/util/HttpUtils.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/util/HttpUtils.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/java/org/apache/eventmesh/client/http/util/HttpUtils.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/resources/log4j2.xml b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/resources/log4j2.xml new file mode 100644 index 0000000000..90f56982b0 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/main/resources/log4j2.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/AsyncPublishInstance.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/test/java/org/apache/eventmesh/client/http/demo/AsyncPublishInstance.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/AsyncPublishInstance.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/test/java/org/apache/eventmesh/client/http/demo/AsyncPublishInstance.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/AsyncSyncRequestInstance.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/test/java/org/apache/eventmesh/client/http/demo/AsyncSyncRequestInstance.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/AsyncSyncRequestInstance.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/test/java/org/apache/eventmesh/client/http/demo/AsyncSyncRequestInstance.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/SyncRequestInstance.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/test/java/org/apache/eventmesh/client/http/demo/SyncRequestInstance.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/SyncRequestInstance.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/test/java/org/apache/eventmesh/client/http/demo/SyncRequestInstance.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/util/HttpLoadBalanceUtilsTest.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/test/java/org/apache/eventmesh/client/http/util/HttpLoadBalanceUtilsTest.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/util/HttpLoadBalanceUtilsTest.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/test/java/org/apache/eventmesh/client/http/util/HttpLoadBalanceUtilsTest.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/util/HttpUtilsTest.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/test/java/org/apache/eventmesh/client/http/util/HttpUtilsTest.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/util/HttpUtilsTest.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/test/java/org/apache/eventmesh/client/http/util/HttpUtilsTest.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/test/resources/application.properties b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/test/resources/application.properties new file mode 100644 index 0000000000..8bc9ce9a40 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/test/resources/application.properties @@ -0,0 +1,17 @@ +# +# 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. +# +server.port=8088 \ No newline at end of file diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/test/resources/log4j2.xml b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/test/resources/log4j2.xml new file mode 100644 index 0000000000..4297021f90 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-http/src/test/resources/log4j2.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/build.gradle b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/build.gradle new file mode 100644 index 0000000000..db15554031 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/build.gradle @@ -0,0 +1,64 @@ +/* + * 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. + */ + +def grpcVersion = '1.43.2' + +dependencies { + api project(":eventmesh-common") + + implementation "com.fasterxml.jackson.core:jackson-databind" + implementation "com.fasterxml.jackson.core:jackson-core" + implementation "com.fasterxml.jackson.core:jackson-annotations" + implementation "org.apache.commons:commons-collections4" + + implementation "io.netty:netty-all" + implementation "org.apache.httpcomponents:httpclient" + + implementation "io.grpc:grpc-protobuf:${grpcVersion}" + implementation "io.grpc:grpc-stub:${grpcVersion}" + implementation "io.grpc:grpc-netty:${grpcVersion}" + implementation "io.grpc:grpc-netty-shaded:${grpcVersion}" + implementation "io.cloudevents:cloudevents-protobuf" + + // protocol + api "io.cloudevents:cloudevents-core" + api "io.cloudevents:cloudevents-json-jackson" + api "io.openmessaging:openmessaging-api" + + testImplementation project(":eventmesh-common") + + testImplementation "com.fasterxml.jackson.core:jackson-databind" + testImplementation "com.fasterxml.jackson.core:jackson-core" + testImplementation "com.fasterxml.jackson.core:jackson-annotations" + + testImplementation "io.netty:netty-all" + testImplementation "org.apache.httpcomponents:httpclient" + + implementation "io.grpc:grpc-protobuf:${grpcVersion}" + implementation "io.grpc:grpc-stub:${grpcVersion}" + implementation "com.google.protobuf:protobuf-java-util:3.21.5" + compileOnly 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok' + + testCompileOnly 'org.projectlombok:lombok' + testAnnotationProcessor 'org.projectlombok:lombok' + + testImplementation "org.assertj:assertj-core" + + testImplementation "org.mockito:mockito-inline" + testImplementation "org.mockito:mockito-junit-jupiter" +} diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/gradle.properties b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/gradle.properties new file mode 100644 index 0000000000..b1312a0905 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/gradle.properties @@ -0,0 +1,16 @@ +# +# 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. +# diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPClient.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPClient.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPClient.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPClient.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPClientFactory.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPClientFactory.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPClientFactory.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPClientFactory.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPPubClient.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPPubClient.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPPubClient.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPPubClient.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPSubClient.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPSubClient.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPSubClient.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPSubClient.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/AsyncRRCallback.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/common/AsyncRRCallback.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/AsyncRRCallback.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/common/AsyncRRCallback.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/MessageUtils.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/common/MessageUtils.java similarity index 99% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/MessageUtils.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/common/MessageUtils.java index 2232e539c9..07e9134425 100644 --- a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/MessageUtils.java +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/common/MessageUtils.java @@ -20,6 +20,7 @@ import static org.apache.eventmesh.common.Constants.CLOUD_EVENTS_PROTOCOL_NAME; import org.apache.eventmesh.common.Constants; +import org.apache.eventmesh.common.EventMeshCommon; import org.apache.eventmesh.common.protocol.SubscriptionItem; import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.SubscriptionType; diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/ReceiveMsgHook.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/common/ReceiveMsgHook.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/ReceiveMsgHook.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/common/ReceiveMsgHook.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/RequestContext.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/common/RequestContext.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/RequestContext.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/common/RequestContext.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/TcpClient.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/common/TcpClient.java similarity index 99% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/TcpClient.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/common/TcpClient.java index 4619f550e7..820dbd314c 100644 --- a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/TcpClient.java +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/common/TcpClient.java @@ -18,6 +18,7 @@ package org.apache.eventmesh.client.tcp.common; import org.apache.eventmesh.client.tcp.conf.EventMeshTCPClientConfig; +import org.apache.eventmesh.common.EventMeshCommon; import org.apache.eventmesh.common.EventMeshThreadFactory; import org.apache.eventmesh.common.ThreadPoolFactory; import org.apache.eventmesh.common.protocol.tcp.Package; diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/conf/EventMeshTCPClientConfig.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/conf/EventMeshTCPClientConfig.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/conf/EventMeshTCPClientConfig.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/conf/EventMeshTCPClientConfig.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/AbstractEventMeshTCPPubHandler.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/impl/AbstractEventMeshTCPPubHandler.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/AbstractEventMeshTCPPubHandler.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/impl/AbstractEventMeshTCPPubHandler.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/AbstractEventMeshTCPSubHandler.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/impl/AbstractEventMeshTCPSubHandler.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/AbstractEventMeshTCPSubHandler.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/impl/AbstractEventMeshTCPSubHandler.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/cloudevent/CloudEventTCPClient.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/impl/cloudevent/CloudEventTCPClient.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/cloudevent/CloudEventTCPClient.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/impl/cloudevent/CloudEventTCPClient.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/cloudevent/CloudEventTCPPubClient.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/impl/cloudevent/CloudEventTCPPubClient.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/cloudevent/CloudEventTCPPubClient.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/impl/cloudevent/CloudEventTCPPubClient.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/cloudevent/CloudEventTCPSubClient.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/impl/cloudevent/CloudEventTCPSubClient.java similarity index 99% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/cloudevent/CloudEventTCPSubClient.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/impl/cloudevent/CloudEventTCPSubClient.java index 836ad00dc5..221b12f6b3 100644 --- a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/cloudevent/CloudEventTCPSubClient.java +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/impl/cloudevent/CloudEventTCPSubClient.java @@ -18,13 +18,13 @@ package org.apache.eventmesh.client.tcp.impl.cloudevent; import org.apache.eventmesh.client.tcp.EventMeshTCPSubClient; -import org.apache.eventmesh.client.tcp.common.EventMeshCommon; import org.apache.eventmesh.client.tcp.common.MessageUtils; import org.apache.eventmesh.client.tcp.common.ReceiveMsgHook; import org.apache.eventmesh.client.tcp.common.RequestContext; import org.apache.eventmesh.client.tcp.common.TcpClient; import org.apache.eventmesh.client.tcp.conf.EventMeshTCPClientConfig; import org.apache.eventmesh.client.tcp.impl.AbstractEventMeshTCPSubHandler; +import org.apache.eventmesh.common.EventMeshCommon; import org.apache.eventmesh.common.exception.EventMeshException; import org.apache.eventmesh.common.protocol.SubscriptionItem; import org.apache.eventmesh.common.protocol.SubscriptionMode; diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/eventmeshmessage/EventMeshMessageTCPClient.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/impl/eventmeshmessage/EventMeshMessageTCPClient.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/eventmeshmessage/EventMeshMessageTCPClient.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/impl/eventmeshmessage/EventMeshMessageTCPClient.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/eventmeshmessage/EventMeshMessageTCPPubClient.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/impl/eventmeshmessage/EventMeshMessageTCPPubClient.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/eventmeshmessage/EventMeshMessageTCPPubClient.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/impl/eventmeshmessage/EventMeshMessageTCPPubClient.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/eventmeshmessage/EventMeshMessageTCPSubClient.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/impl/eventmeshmessage/EventMeshMessageTCPSubClient.java similarity index 98% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/eventmeshmessage/EventMeshMessageTCPSubClient.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/impl/eventmeshmessage/EventMeshMessageTCPSubClient.java index 7216597d7d..55554f525d 100644 --- a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/eventmeshmessage/EventMeshMessageTCPSubClient.java +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/impl/eventmeshmessage/EventMeshMessageTCPSubClient.java @@ -18,13 +18,13 @@ package org.apache.eventmesh.client.tcp.impl.eventmeshmessage; import org.apache.eventmesh.client.tcp.EventMeshTCPSubClient; -import org.apache.eventmesh.client.tcp.common.EventMeshCommon; import org.apache.eventmesh.client.tcp.common.MessageUtils; import org.apache.eventmesh.client.tcp.common.ReceiveMsgHook; import org.apache.eventmesh.client.tcp.common.RequestContext; import org.apache.eventmesh.client.tcp.common.TcpClient; import org.apache.eventmesh.client.tcp.conf.EventMeshTCPClientConfig; import org.apache.eventmesh.client.tcp.impl.AbstractEventMeshTCPSubHandler; +import org.apache.eventmesh.common.EventMeshCommon; import org.apache.eventmesh.common.exception.EventMeshException; import org.apache.eventmesh.common.protocol.SubscriptionItem; import org.apache.eventmesh.common.protocol.SubscriptionMode; diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/openmessage/OpenMessageTCPClient.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/impl/openmessage/OpenMessageTCPClient.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/openmessage/OpenMessageTCPClient.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/impl/openmessage/OpenMessageTCPClient.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/openmessage/OpenMessageTCPPubClient.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/impl/openmessage/OpenMessageTCPPubClient.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/openmessage/OpenMessageTCPPubClient.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/impl/openmessage/OpenMessageTCPPubClient.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/openmessage/OpenMessageTCPSubClient.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/impl/openmessage/OpenMessageTCPSubClient.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/openmessage/OpenMessageTCPSubClient.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/java/org/apache/eventmesh/client/tcp/impl/openmessage/OpenMessageTCPSubClient.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/resources/log4j2.xml b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/resources/log4j2.xml new file mode 100644 index 0000000000..90f56982b0 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/main/resources/log4j2.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/common/EventMeshTestCaseTopicSet.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/test/java/org/apache/eventmesh/client/tcp/common/EventMeshTestCaseTopicSet.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/common/EventMeshTestCaseTopicSet.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/test/java/org/apache/eventmesh/client/tcp/common/EventMeshTestCaseTopicSet.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/common/EventMeshTestUtils.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/test/java/org/apache/eventmesh/client/tcp/common/EventMeshTestUtils.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/common/EventMeshTestUtils.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/test/java/org/apache/eventmesh/client/tcp/common/EventMeshTestUtils.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/common/MessageUtilsTest.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/test/java/org/apache/eventmesh/client/tcp/common/MessageUtilsTest.java similarity index 99% rename from eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/common/MessageUtilsTest.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/test/java/org/apache/eventmesh/client/tcp/common/MessageUtilsTest.java index 4916cf5612..96025be305 100644 --- a/eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/common/MessageUtilsTest.java +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/test/java/org/apache/eventmesh/client/tcp/common/MessageUtilsTest.java @@ -18,6 +18,7 @@ package org.apache.eventmesh.client.tcp.common; import org.apache.eventmesh.common.Constants; +import org.apache.eventmesh.common.EventMeshCommon; import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.SubscriptionType; import org.apache.eventmesh.common.protocol.tcp.Command; diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/impl/EventMeshTCPClientFactoryTest.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/test/java/org/apache/eventmesh/client/tcp/impl/EventMeshTCPClientFactoryTest.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/impl/EventMeshTCPClientFactoryTest.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/test/java/org/apache/eventmesh/client/tcp/impl/EventMeshTCPClientFactoryTest.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/test/resources/application.properties b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/test/resources/application.properties new file mode 100644 index 0000000000..8bc9ce9a40 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/test/resources/application.properties @@ -0,0 +1,17 @@ +# +# 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. +# +server.port=8088 \ No newline at end of file diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/test/resources/log4j2.xml b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/test/resources/log4j2.xml new file mode 100644 index 0000000000..4297021f90 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-tcp/src/test/resources/log4j2.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/build.gradle b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/build.gradle new file mode 100644 index 0000000000..db15554031 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/build.gradle @@ -0,0 +1,64 @@ +/* + * 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. + */ + +def grpcVersion = '1.43.2' + +dependencies { + api project(":eventmesh-common") + + implementation "com.fasterxml.jackson.core:jackson-databind" + implementation "com.fasterxml.jackson.core:jackson-core" + implementation "com.fasterxml.jackson.core:jackson-annotations" + implementation "org.apache.commons:commons-collections4" + + implementation "io.netty:netty-all" + implementation "org.apache.httpcomponents:httpclient" + + implementation "io.grpc:grpc-protobuf:${grpcVersion}" + implementation "io.grpc:grpc-stub:${grpcVersion}" + implementation "io.grpc:grpc-netty:${grpcVersion}" + implementation "io.grpc:grpc-netty-shaded:${grpcVersion}" + implementation "io.cloudevents:cloudevents-protobuf" + + // protocol + api "io.cloudevents:cloudevents-core" + api "io.cloudevents:cloudevents-json-jackson" + api "io.openmessaging:openmessaging-api" + + testImplementation project(":eventmesh-common") + + testImplementation "com.fasterxml.jackson.core:jackson-databind" + testImplementation "com.fasterxml.jackson.core:jackson-core" + testImplementation "com.fasterxml.jackson.core:jackson-annotations" + + testImplementation "io.netty:netty-all" + testImplementation "org.apache.httpcomponents:httpclient" + + implementation "io.grpc:grpc-protobuf:${grpcVersion}" + implementation "io.grpc:grpc-stub:${grpcVersion}" + implementation "com.google.protobuf:protobuf-java-util:3.21.5" + compileOnly 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok' + + testCompileOnly 'org.projectlombok:lombok' + testAnnotationProcessor 'org.projectlombok:lombok' + + testImplementation "org.assertj:assertj-core" + + testImplementation "org.mockito:mockito-inline" + testImplementation "org.mockito:mockito-junit-jupiter" +} diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/gradle.properties b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/gradle.properties new file mode 100644 index 0000000000..b1312a0905 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/gradle.properties @@ -0,0 +1,16 @@ +# +# 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. +# diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/src/main/java/org/apache/eventmesh/client/selector/Selector.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/src/main/java/org/apache/eventmesh/client/selector/Selector.java new file mode 100644 index 0000000000..e6268667d8 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/src/main/java/org/apache/eventmesh/client/selector/Selector.java @@ -0,0 +1,26 @@ +/* + * 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.client.selector; + +/** + * Selector is the abstract of selecting registry service instances + */ +public interface Selector { + + ServiceInstance selectOne(String serverName) throws SelectorException; +} diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/src/main/java/org/apache/eventmesh/client/selector/SelectorException.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/src/main/java/org/apache/eventmesh/client/selector/SelectorException.java new file mode 100644 index 0000000000..f5c61aed48 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/src/main/java/org/apache/eventmesh/client/selector/SelectorException.java @@ -0,0 +1,31 @@ +/* + * 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.client.selector; + +public class SelectorException extends RuntimeException { + + private static final long serialVersionUID = 7126682512429265292L; + + public SelectorException(final String message) { + super(message); + } + + public SelectorException(final String message, final Throwable cause) { + super(message, cause); + } +} diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/src/main/java/org/apache/eventmesh/client/selector/SelectorFactory.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/src/main/java/org/apache/eventmesh/client/selector/SelectorFactory.java new file mode 100644 index 0000000000..cc23ee608e --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/src/main/java/org/apache/eventmesh/client/selector/SelectorFactory.java @@ -0,0 +1,37 @@ +/* + * 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.client.selector; + +import java.util.HashMap; +import java.util.Map; + +public class SelectorFactory { + + private static final Map SELECTOR_MAP = new HashMap<>(); + + public static Selector get(final String type) { + return SELECTOR_MAP.get(type); + } + + public static void register(final String type, final Selector selector) { + if (selector == null) { + return; + } + SELECTOR_MAP.put(type, selector); + } +} diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/src/main/java/org/apache/eventmesh/client/selector/ServiceInstance.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/src/main/java/org/apache/eventmesh/client/selector/ServiceInstance.java new file mode 100644 index 0000000000..16265dd468 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/src/main/java/org/apache/eventmesh/client/selector/ServiceInstance.java @@ -0,0 +1,42 @@ +/* + * 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.client.selector; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +import lombok.Data; + +@Data +public class ServiceInstance implements Serializable { + + private static final long serialVersionUID = -4622423079578878337L; + + private String host; + private int port; + private boolean isHealthy; + private Map metadata; + + public ServiceInstance() { + this.host = null; + this.port = 0; + this.isHealthy = true; + this.metadata = new HashMap<>(); + } +} diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/workflow/EventMeshWorkflowClient.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/src/main/java/org/apache/eventmesh/client/workflow/EventMeshWorkflowClient.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/workflow/EventMeshWorkflowClient.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/src/main/java/org/apache/eventmesh/client/workflow/EventMeshWorkflowClient.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/workflow/config/EventMeshWorkflowClientConfig.java b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/src/main/java/org/apache/eventmesh/client/workflow/config/EventMeshWorkflowClientConfig.java similarity index 100% rename from eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/workflow/config/EventMeshWorkflowClientConfig.java rename to eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/src/main/java/org/apache/eventmesh/client/workflow/config/EventMeshWorkflowClientConfig.java diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/src/main/resources/log4j2.xml b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/src/main/resources/log4j2.xml new file mode 100644 index 0000000000..90f56982b0 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/src/main/resources/log4j2.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/src/test/resources/application.properties b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/src/test/resources/application.properties new file mode 100644 index 0000000000..8bc9ce9a40 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/src/test/resources/application.properties @@ -0,0 +1,17 @@ +# +# 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. +# +server.port=8088 \ No newline at end of file diff --git a/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/src/test/resources/log4j2.xml b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/src/test/resources/log4j2.xml new file mode 100644 index 0000000000..4297021f90 --- /dev/null +++ b/eventmesh-sdks/eventmesh-sdk-java/eventmesh-sdk-java-workflow/src/test/resources/log4j2.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 645e6fb365..3f16a5bc8d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -126,3 +126,10 @@ include 'eventmesh-webhook:eventmesh-webhook-receive' include 'eventmesh-retry' include 'eventmesh-retry:eventmesh-retry-api' include 'eventmesh-retry:eventmesh-retry-rocketmq' + +include 'eventmesh-sdks:eventmesh-sdk-java:eventmesh-sdk-java-tcp' +include 'eventmesh-sdks:eventmesh-sdk-java:eventmesh-sdk-java-grpc' +include 'eventmesh-sdks:eventmesh-sdk-java:eventmesh-sdk-java-http' +include 'eventmesh-sdks:eventmesh-sdk-java:eventmesh-sdk-java-workflow' +include 'eventmesh-sdks:eventmesh-sdk-java:eventmesh-sdk-java-catalog' +