Newbie questions
Christian Migowski
chrismfwrd at gmail.com
Tue Aug 11 11:08:28 EDT 2009
Hi,
On Tue, Aug 11, 2009 at 10:13 AM, Bozo Juretic<bjuretic at inet.hr> wrote:
> Hi all,
>
> I have two newbie questions; I couldn't find examples dealing with those
> two, so perhaps someone can give me a hand here.
>
> 1. What is the best way to implement reconnecting mechanism for TCP
> client in which the connection with the server should be up at all
> times. I need to send periodic "ping status" messages to the server as
> well. At the start of app I need to connect to host (and retry if host
> is not available), and if the connection goes down I need to reconnect
> up with the server in some smart way (perhaps you have reconnecting
> strategies implemented somewhere in netty code?).
As far as I know, there is not (yet) automatic reconnection in Netty -
ie. you need to implement it by yourself. Pass a reference of the
ClientBootStrap to the handler where you want to handle the reconnect
and then use it in channelClosed()
for example (don't use it as-it-is!):
while(ch.isConnected()) {
ChannelFuture f = bootstrap.connect(new InetSocketAddress(host, port));
f.awaitUninterruptibly();
ch = f.getChannel();
}
The "ping" mechanism can be implemented very well using a
IdleChannelHandler in your pipeline - there are examples within Netty
for this (package timeout).
> 2. What is the best way to send incoming JMS message payload to the
> server and send back the response to the client via another JMS
> responseQueue? I have a JMS listener which gets the payload from
> requestQueue, and now I guess that I need a local memory queue on which
> to push this data; netty would then check the memory queue and send the
> data to the server if the data if found. Do you have any example for
> this queue mechanism, or any comments if I got this wrong?
My application is doing the same, I get messages from JMS, send them
with Netty, store them in a hashmap (in my app it is allowed to have
multiple outstanding requests), upon response I remove this message
from the hashmap and acknowledge the message on the JMS destination (I
use a consumer and call receive() instead of implementing a message
listener bec. I want control over the receiving thread).
hope this helps,
regards,
christian!
More information about the netty-users
mailing list