Search in sources :

Example 1 with EventMeshClientImpl

use of org.apache.eventmesh.runtime.client.impl.EventMeshClientImpl in project incubator-eventmesh by apache.

the class CClientDemo method main.

public static void main(String[] args) throws Exception {
    EventMeshClientImpl client = new EventMeshClientImpl("127.0.0.1", 10000);
    client.init();
    client.heartbeat();
    client.justSubscribe(ASYNC_TOPIC, SubscriptionMode.CLUSTERING, SubscriptionType.ASYNC);
    client.justSubscribe(BROADCAST_TOPIC, SubscriptionMode.BROADCASTING, SubscriptionType.ASYNC);
    client.listen();
    client.registerSubBusiHandler(new ReceiveMsgHook() {

        @Override
        public void handle(Package msg, ChannelHandlerContext ctx) {
            if (msg.getHeader().getCmd() == Command.ASYNC_MESSAGE_TO_CLIENT || msg.getHeader().getCmd() == Command.BROADCAST_MESSAGE_TO_CLIENT) {
                logger.error("receive message-------------------------------------" + msg);
            }
        }
    });
    for (int i = 0; i < 10000; i++) {
        // ThreadUtil.randomSleep(0,200);
        // broadcast message
        client.broadcast(MessageUtils.broadcastMessage("TEST-TOPIC-TCP-BROADCAST", i), 5000);
        // asynchronous message
        client.publish(MessageUtils.asyncMessage(ASYNC_TOPIC, i), 5000);
    }
// 
// Thread.sleep(10000);
// client.close();
}
Also used : ReceiveMsgHook(org.apache.eventmesh.runtime.client.hook.ReceiveMsgHook) EventMeshClientImpl(org.apache.eventmesh.runtime.client.impl.EventMeshClientImpl) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Package(org.apache.eventmesh.common.protocol.tcp.Package)

Aggregations

ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 Package (org.apache.eventmesh.common.protocol.tcp.Package)1 ReceiveMsgHook (org.apache.eventmesh.runtime.client.hook.ReceiveMsgHook)1 EventMeshClientImpl (org.apache.eventmesh.runtime.client.impl.EventMeshClientImpl)1