gbensa opened a new issue #5828: Netty UDP connector doesn't work
URL: https://github.com/apache/pulsar/issues/5828
 
 
   NettyServerHandler doesn't work for UDP as it will receive DatagramPacket 
instead of byte[]
   
   I managed to make the UDP connector working using a new 
NettyUDPServerHandler :
   
   public class NettyUDPServerHandler extends 
SimpleChannelInboundHandler<DatagramPacket> {
   
       private static final Logger logger = 
LoggerFactory.getLogger(NettyUDPServerHandler.class);
       private NettySource nettySource;
   
       public NettyUDPServerHandler(NettySource nettySource) {
           this.nettySource = nettySource;
       }
       
       @Override
       protected void channelRead0(ChannelHandlerContext channelHandlerContext, 
DatagramPacket packet) throws Exception {
           ByteBuf buf = packet.content();
           byte[] bytes = new byte[buf.readableBytes()];
           buf.readBytes(bytes);
           buf.retain();
           nettySource.consume(new NettyRecord(Optional.ofNullable(""), bytes));
       }
   
       @Override
       public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
           logger.error("Error when processing incoming data", cause);
           ctx.close();
       }
   
       @Data
       static private class NettyRecord implements Record<byte[]>, Serializable 
{
           private final Optional<String> key;
           private final byte[] value;
       }
   
   }

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to