完整的源链接:https://github.com/kcy0142/camel_netty_test
@Configuration
public class ChannelHandlerFactoryByteArrayDecoder implements ChannelHandlerFactory {
@Bean(name="vpaByteDecoder")
@Qualifier("vpaByteDecoder")
public ChannelHandler newChannelHandler() {
return (ChannelHandler) new VpaByteDecoder();
}
public class VpaByteDecoder extends ByteToMessageDecoder{
}
}
我的路由器是
from("netty4:tcp://localhost:8004?textline=true&sync=true&decoders=#vpaByteDecoder&encoders=#stringEncoder").
并且像这样调用错误
io.netty.channel.ChannelPipelineException: config.ChannelHandlerFactoryDecoder$VpaByteDecoder is not a @Sharable handler, so can't be added or removed multiple times.
ByteToMessageDecoder不应该共享。所以我实现了ChannelHandlerFactory
我不知道原因。这个方式让我了解了解问题的方法。
答案 0 :(得分:0)
它的工厂类应该被命名为bean方法,而不是像这样,并删除@Bean
@Component(name="vpaByteDecoder")
public class ChannelHandlerFactoryByteArrayDecoder implements ChannelHandlerFactory {