I found a way, which seems to work for me.
The solution was to create a custom component which extends the
NettyComponent.
The corresponing endpoint will have an reference to the used listener
channel (Consumer).
@Override
protected void doStart() throws Exception
{
super.doStart();
Field nettyServerBootstrapFactory =
GsPblConsumer.class.getSuperclass().getDeclaredField("nettyServerBootstrapFactory");
nettyServerBootstrapFactory.setAccessible(true);
Object nsbf = nettyServerBootstrapFactory.get(this);
Field channel = nsbf.getClass().getDeclaredField("channel");
channel.setAccessible(true);
channelToShare = (Channel) channel.get(nsbf);
getEndpoint().setSharedChannel(channelToShare);
}
This channel will be used for the Producer to send the messages.
@Override
public boolean process(Exchange exchange, AsyncCallback callback)
{
...
// get a channel from the pool
Channel existing;
try {
if (getConfiguration().isShareChannel() &&
getEndpoint().hasChannelToShare())
existing = getEndpoint().getSharedChannel();
else
existing = pool.borrowObject();
if (existing != null) {
LOG.trace("Got channel from pool {}", existing);
}
} catch (Exception e) {
exchange.setException(e);
callback.done(true);
return true;
}
...
}
Does anybody know a better solution?
Thanks,
Jörg
--
View this message in context:
http://camel.465427.n5.nabble.com/publish-subscribe-with-camel-netty4-tp5801431p5802787.html
Sent from the Camel - Users mailing list archive at Nabble.com.