spotify/netty-zmtp

Question: Can you use communicate with both the server and client as netty-zmtp?

vshank77 opened this issue · 3 comments

My server pipeline looks like below:

    serverBootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
            newCachedThreadPool(), newCachedThreadPool()));
    serverBootstrap.setPipelineFactory(new ChannelPipelineFactory() {
        private final Executor executor = new OrderedMemoryAwareThreadPoolExecutor(
                getRuntime().availableProcessors(), 1024 * 1024, 128 * 1024 * 1024);

        public ChannelPipeline getPipeline() throws Exception {
            return Channels.pipeline(new ExecutionHandler(executor), new ZMTP20Codec(new ZMTPSession(
                    Addressed, 1024, null, ROUTER), false), new ServerHandler());
        }
    });

My Client pipeline looks below:

    clientBootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(
            newCachedThreadPool(), newCachedThreadPool()));
    clientBootstrap.setPipelineFactory(new ChannelPipelineFactory() {
        public ChannelPipeline getPipeline() throws Exception {
            return Channels.pipeline(new ZMTP20Codec(new ZMTPSession(Addressed, 1024), false),
                    new OneToOneDecoder() {
                        @Override
                        protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg)
                                throws Exception {
                            System.out.println(msg);
                            return null;
                        }
                    });
        }
    });

However if I try to send a message to server, I get the following exception

 Caused by: java.lang.IllegalArgumentException: unsupported message type: class com.spotify.netty.handler.codec.zmtp.ZMTPMessage
    at org.jboss.netty.channel.socket.nio.SocketSendBufferPool.acquire(SocketSendBufferPool.java:52)
    at org.jboss.netty.channel.socket.nio.AbstractNioWorker.write0(AbstractNioWorker.java:193)
    at org.jboss.netty.channel.socket.nio.AbstractNioWorker.writeFromTaskLoop(AbstractNioWorker.java:151)
    at org.jboss.netty.channel.socket.nio.AbstractNioChannel$WriteTask.run(AbstractNioChannel.java:335)
    at org.jboss.netty.channel.socket.nio.AbstractNioSelector.processTaskQueue(AbstractNioSelector.java:372)
    at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:296)
    at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89)
    at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
    at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
    at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)

Can you please help?

Are you waiting for the channel to become connected before attempting to send the message?

Yes, I can actually confirm that the server and client are in-fact connected.

My use-case is pretty simple - I am trying to connect to a ZMQ server and I am unable to setup the client bootstrap correctly. All the integration examples on the test package only show ZMTP server and ZMQ socket client - can you please write a quick test the other way around (ZMQ server socket, ZMTP client sending and receiving a ZMTPFrame) to pick up from?

Thanks in advance