Search in sources :

Example 1 with ReceiveMsgHook

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);
            }
        }
    });
}
Also used : SubClientImpl(org.apache.eventmesh.runtime.client.impl.SubClientImpl) ReceiveMsgHook(org.apache.eventmesh.runtime.client.hook.ReceiveMsgHook) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Package(org.apache.eventmesh.common.protocol.tcp.Package)

Example 2 with ReceiveMsgHook

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);
            }
        }
    });
}
Also used : SubClientImpl(org.apache.eventmesh.runtime.client.impl.SubClientImpl) ReceiveMsgHook(org.apache.eventmesh.runtime.client.hook.ReceiveMsgHook) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Package(org.apache.eventmesh.common.protocol.tcp.Package)

Example 3 with ReceiveMsgHook

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);
    }
}
Also used : ReceiveMsgHook(org.apache.eventmesh.runtime.client.hook.ReceiveMsgHook) PubClientImpl(org.apache.eventmesh.runtime.client.impl.PubClientImpl) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Package(org.apache.eventmesh.common.protocol.tcp.Package)

Example 4 with ReceiveMsgHook

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);
            }
        }
    });
}
Also used : SubClientImpl(org.apache.eventmesh.runtime.client.impl.SubClientImpl) ReceiveMsgHook(org.apache.eventmesh.runtime.client.hook.ReceiveMsgHook) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Package(org.apache.eventmesh.common.protocol.tcp.Package) EventMeshMessage(org.apache.eventmesh.common.protocol.tcp.EventMeshMessage)

Example 5 with ReceiveMsgHook

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);
                }
            }
        }
    });
}
Also used : SubClientImpl(org.apache.eventmesh.runtime.client.impl.SubClientImpl) ReceiveMsgHook(org.apache.eventmesh.runtime.client.hook.ReceiveMsgHook) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Package(org.apache.eventmesh.common.protocol.tcp.Package) EventMeshMessage(org.apache.eventmesh.common.protocol.tcp.EventMeshMessage)

Aggregations

ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)6 Package (org.apache.eventmesh.common.protocol.tcp.Package)6 ReceiveMsgHook (org.apache.eventmesh.runtime.client.hook.ReceiveMsgHook)6 SubClientImpl (org.apache.eventmesh.runtime.client.impl.SubClientImpl)4 EventMeshMessage (org.apache.eventmesh.common.protocol.tcp.EventMeshMessage)2 EventMeshClientImpl (org.apache.eventmesh.runtime.client.impl.EventMeshClientImpl)1 PubClientImpl (org.apache.eventmesh.runtime.client.impl.PubClientImpl)1