You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by souciance <so...@gmail.com> on 2016/05/23 15:18:50 UTC

Camel netty detect client disconnect

Hello,

Is there any way for the camel netty 4 component to detect when a client
channel has disconnected? I need to clear out some data specific to clients
when they disconnect. 

I know if I write my own handler than I can access the netty methods to
listen for disconnect events but was wondering if these are exposed via
Camel or if there is another recommended approach? Otherwise I would be
duplicating a lot of the code already written here:
https://github.com/apache/camel/blob/337a6756480354afea7531a1a4216de9d232f211/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/handlers/ServerChannelHandler.java

Best
Souciance



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-netty-detect-client-disconnect-tp5782966.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel netty detect client disconnect

Posted by souciance <so...@gmail.com>.
Just in case anyone else runs into this, I had to reuse a lot of the code
found here:
https://github.com/apache/camel/blob/master/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ServerChannelHandler.java

You can then generate a unique client id like this:

uniqueClientId =
String.valueOf(ctx.channel().hashCode()).concat(String.valueOf(ctx.channel().remoteAddress())).concat(String.valueOf(ctx.channel().localAddress()));

From the channel inactive method you can generate a message to put on the
exchange. In your route, you have to catch the message, do your disconnect
cleanup and then stop processing the exchange otherwise you will client
channel disconnect error since channel will have disconnected although the
route is actually an InOut.


On Mon, May 23, 2016 at 5:18 PM, souciance [via Camel] <
ml-node+s465427n5782966h9@n5.nabble.com> wrote:

> Hello,
>
> Is there any way for the camel netty 4 component to detect when a client
> channel has disconnected? I need to clear out some data specific to clients
> when they disconnect.
>
> I know if I write my own handler than I can access the netty methods to
> listen for disconnect events but was wondering if these are exposed via
> Camel or if there is another recommended approach? Otherwise I would be
> duplicating a lot of the code already written here:
>
> https://github.com/apache/camel/blob/337a6756480354afea7531a1a4216de9d232f211/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/handlers/ServerChannelHandler.java
>
> Best
> Souciance
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://camel.465427.n5.nabble.com/Camel-netty-detect-client-disconnect-tp5782966.html
> To start a new topic under Camel - Users, email
> ml-node+s465427n465428h31@n5.nabble.com
> To unsubscribe from Camel - Users, click here
> <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=465428&code=c291Y2lhbmNlLmVxZGFtLnJhc2h0aUBnbWFpbC5jb218NDY1NDI4fDE1MzI5MTE2NTY=>
> .
> NAML
> <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://camel.465427.n5.nabble.com/Camel-netty-detect-client-disconnect-tp5782966p5783059.html
Sent from the Camel - Users mailing list archive at Nabble.com.