Akka + Camel + 上下文提供者

Akka + Camel + Context-Provider

尊敬的Camel/Akka/Netty师傅们!

我创建了使用 tcp 连接的 UntypedConsumerActor:

public class TcpEndpoint extends UntypedConsumerActor {

    private static final Logger log = LoggerFactory.getLogger(TcpEndpoint.class);

    public static Props props = Props.create(TcpEndpoint.class);

    @Override
    public String getEndpointUri() {
        return "netty4:tcp://localhost:8000?decoders=#fdDecoder,#fdHandler";
    }

    @Override
    public void onReceive(Object message) throws Throwable {
        log.error("onReceived");
    }

}

如果要为 netty 组件配置解码器,我创建了 ContextProvider:

public class FDCamelContext implements ContextProvider {

    public DefaultCamelContext getContext(ExtendedActorSystem system) {
        JndiRegistry registry = new JndiRegistry();
        registry.bind("fdDecoder", new FDDecoder());
        registry.bind("fdHandler", new FDHandler());

        DefaultCamelContext context = new DefaultCamelContext(registry);
        return context;
    }
}

现在,当我发送消息时,没有调用 onReceive 方法。为什么?当我设置 DefaultContextProvider 并将 netty 配置为使用文本行时,一切都按预期工作。

好的,我发现问题了。也许对某人有帮助:

需要触发 channelRead 事件:

ctx.fireChannelRead(msg);