use of org.apache.eventmesh.runtime.client.hook.ReceiveMsgHook in project incubator-eventmesh by apache.
the class CCSubClient method main.
public static void main(String[] args) throws Exception {
SubClientImpl subClient = new SubClientImpl("127.0.0.1", 10000, UserAgentUtils.createUserAgent());
subClient.init();
subClient.heartbeat();
subClient.listen();
subClient.justSubscribe("TEST-TOPIC-TCP-SYNC", SubscriptionMode.CLUSTERING, SubscriptionType.SYNC);
subClient.registerBusiHandler(new ReceiveMsgHook() {
@Override
public void handle(Package msg, ChannelHandlerContext ctx) {
logger.error("Received message: -----------------------------------------" + msg.toString());
if (msg.getHeader().getCommand() == Command.REQUEST_TO_CLIENT) {
Package rrResponse = MessageUtils.rrResponse(msg);
ctx.writeAndFlush(rrResponse);
}
}
});
}
use of org.apache.eventmesh.runtime.client.hook.ReceiveMsgHook in project incubator-eventmesh by apache.
the class SyncSubClient method main.
public static void main(String[] args) throws Exception {
SubClientImpl client = new SubClientImpl("127.0.0.1", 10000, MessageUtils.generateSubServer());
client.init();
client.heartbeat();
client.justSubscribe(ClientConstants.SYNC_TOPIC, SubscriptionMode.CLUSTERING, SubscriptionType.SYNC);
client.registerBusiHandler(new ReceiveMsgHook() {
@Override
public void handle(Package msg, ChannelHandlerContext ctx) {
if (msg.getHeader().getCommand() == Command.REQUEST_TO_CLIENT) {
logger.error("receive message -------------------------------" + msg);
}
}
});
}
use of org.apache.eventmesh.runtime.client.hook.ReceiveMsgHook in project incubator-eventmesh by apache.
the class AsyncPubClient method main.
public static void main(String[] args) throws Exception {
PubClientImpl pubClient = new PubClientImpl("127.0.0.1", 10000, UserAgentUtils.createUserAgent());
pubClient.init();
pubClient.heartbeat();
pubClient.registerBusiHandler(new ReceiveMsgHook() {
@Override
public void handle(Package msg, ChannelHandlerContext ctx) {
logger.error("receive msg-----------------------------" + msg.toString());
}
});
for (int i = 0; i < 1; i++) {
ThreadUtils.randomSleep(0, 500);
pubClient.broadcast(MessageUtils.asyncMessage(ClientConstants.ASYNC_TOPIC, i), 5000);
}
}
use of org.apache.eventmesh.runtime.client.hook.ReceiveMsgHook in project incubator-eventmesh by apache.
the class AsyncSubClient method main.
public static void main(String[] args) throws Exception {
SubClientImpl client = new SubClientImpl("127.0.0.1", 10002, MessageUtils.generateSubServer());
client.init();
client.heartbeat();
client.justSubscribe(ClientConstants.ASYNC_TOPIC, SubscriptionMode.CLUSTERING, SubscriptionType.ASYNC);
client.registerBusiHandler(new ReceiveMsgHook() {
@Override
public void handle(Package msg, ChannelHandlerContext ctx) {
if (msg.getBody() instanceof EventMeshMessage) {
String body = ((EventMeshMessage) msg.getBody()).getBody();
logger.error("receive message -------------------------------" + body);
}
}
});
}
use of org.apache.eventmesh.runtime.client.hook.ReceiveMsgHook in project incubator-eventmesh by apache.
the class BroadCastSubClient method main.
public static void main(String[] args) throws Exception {
SubClientImpl client = new SubClientImpl("127.0.0.1", 10000, MessageUtils.generateSubServer());
client.init();
client.heartbeat();
client.justSubscribe(ClientConstants.BROADCAST_TOPIC, SubscriptionMode.BROADCASTING, SubscriptionType.ASYNC);
client.registerBusiHandler(new ReceiveMsgHook() {
@Override
public void handle(Package msg, ChannelHandlerContext ctx) {
if (msg.getHeader().getCommand() == Command.BROADCAST_MESSAGE_TO_CLIENT) {
if (msg.getBody() instanceof EventMeshMessage) {
String body = ((EventMeshMessage) msg.getBody()).getBody();
logger.error("receive message -------------------------------" + body);
}
}
}
});
}
Aggregations