Search in sources :

Example 1 with SubClientImpl

use of org.apache.eventmesh.runtime.client.impl.SubClientImpl 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 SubClientImpl

use of org.apache.eventmesh.runtime.client.impl.SubClientImpl 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 SubClientImpl

use of org.apache.eventmesh.runtime.client.impl.SubClientImpl 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 4 with SubClientImpl

use of org.apache.eventmesh.runtime.client.impl.SubClientImpl 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)4 Package (org.apache.eventmesh.common.protocol.tcp.Package)4 ReceiveMsgHook (org.apache.eventmesh.runtime.client.hook.ReceiveMsgHook)4 SubClientImpl (org.apache.eventmesh.runtime.client.impl.SubClientImpl)4 EventMeshMessage (org.apache.eventmesh.common.protocol.tcp.EventMeshMessage)2