-
Notifications
You must be signed in to change notification settings - Fork 642
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sync request/response for sdk in rocketmq-connector (#634)
fix sync request/response for sdk in rocketmq-connector
- Loading branch information
Showing
14 changed files
with
253 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...esh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/cloudevents/SyncRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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.tcp.demo.pub.cloudevents; | ||
|
||
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.protocol.tcp.EventMeshMessage; | ||
import org.apache.eventmesh.common.protocol.tcp.Package; | ||
import org.apache.eventmesh.common.protocol.tcp.UserAgent; | ||
import org.apache.eventmesh.tcp.common.EventMeshTestUtils; | ||
|
||
import io.cloudevents.CloudEvent; | ||
import io.cloudevents.core.provider.EventFormatProvider; | ||
import io.cloudevents.jackson.JsonFormat; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
@Slf4j | ||
public class SyncRequest { | ||
|
||
private static EventMeshTCPClient<CloudEvent> client; | ||
|
||
public static void main(String[] agrs) throws Exception { | ||
UserAgent userAgent = EventMeshTestUtils.generateClient1(); | ||
EventMeshTCPClientConfig eventMeshTcpClientConfig = EventMeshTCPClientConfig.builder() | ||
.host("127.0.0.1") | ||
.port(10002) | ||
.userAgent(userAgent) | ||
.build(); | ||
try { | ||
client = EventMeshTCPClientFactory.createEventMeshTCPClient( | ||
eventMeshTcpClientConfig, CloudEvent.class); | ||
client.init(); | ||
|
||
CloudEvent event = EventMeshTestUtils.generateCloudEventV1SyncRR(); | ||
log.info("begin send rr msg=================={}", event); | ||
Package response = client.rr(event, EventMeshCommon.DEFAULT_TIME_OUT_MILLS); | ||
CloudEvent replyEvent = EventFormatProvider.getInstance().resolveFormat(JsonFormat.CONTENT_TYPE) | ||
.deserialize(response.getBody().toString().getBytes(StandardCharsets.UTF_8)); | ||
String content = new String(replyEvent.getData().toBytes(), StandardCharsets.UTF_8); | ||
log.info("receive rr reply==================={}|{}", response, content); | ||
|
||
} catch (Exception e) { | ||
log.warn("SyncRequest failed", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...sh-examples/src/main/java/org/apache/eventmesh/tcp/demo/sub/cloudevents/SyncResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* 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.tcp.demo.sub.cloudevents; | ||
|
||
import org.apache.eventmesh.client.tcp.EventMeshTCPClient; | ||
import org.apache.eventmesh.client.tcp.EventMeshTCPClientFactory; | ||
import org.apache.eventmesh.client.tcp.common.MessageUtils; | ||
import org.apache.eventmesh.client.tcp.common.ReceiveMsgHook; | ||
import org.apache.eventmesh.client.tcp.conf.EventMeshTCPClientConfig; | ||
import org.apache.eventmesh.common.protocol.SubscriptionMode; | ||
import org.apache.eventmesh.common.protocol.SubscriptionType; | ||
import org.apache.eventmesh.common.protocol.tcp.Command; | ||
import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; | ||
import org.apache.eventmesh.common.protocol.tcp.Package; | ||
import org.apache.eventmesh.common.protocol.tcp.UserAgent; | ||
import org.apache.eventmesh.tcp.common.EventMeshTestUtils; | ||
|
||
import io.cloudevents.CloudEvent; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
@Slf4j | ||
public class SyncResponse implements ReceiveMsgHook<CloudEvent> { | ||
|
||
public static SyncResponse handler = new SyncResponse(); | ||
|
||
private static EventMeshTCPClient<CloudEvent> client; | ||
|
||
public static void main(String[] agrs) throws Exception { | ||
UserAgent userAgent = EventMeshTestUtils.generateClient2(); | ||
EventMeshTCPClientConfig eventMeshTcpClientConfig = EventMeshTCPClientConfig.builder() | ||
.host("127.0.0.1") | ||
.port(10002) | ||
.userAgent(userAgent) | ||
.build(); | ||
try { | ||
client = EventMeshTCPClientFactory | ||
.createEventMeshTCPClient(eventMeshTcpClientConfig, CloudEvent.class); | ||
client.init(); | ||
|
||
client.subscribe("TEST-TOPIC-TCP-SYNC", SubscriptionMode.CLUSTERING, SubscriptionType.SYNC); | ||
// Synchronize RR messages | ||
client.registerSubBusiHandler(handler); | ||
|
||
client.listen(); | ||
|
||
} catch (Exception e) { | ||
log.warn("SyncResponse failed", e); | ||
} | ||
} | ||
|
||
@Override | ||
public void handle(CloudEvent event, ChannelHandlerContext ctx) { | ||
String content = new String(event.getData().toBytes(), StandardCharsets.UTF_8); | ||
log.info("receive sync rr msg================{}|{}", event, content); | ||
Package pkg = MessageUtils.buildPackage(event, Command.RESPONSE_TO_SERVER); | ||
ctx.writeAndFlush(pkg); | ||
} | ||
|
||
} |
Oops, something went wrong.