You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "itsavvy.ankur" <ia...@gmail.com> on 2015/04/02 07:03:26 UTC

Apache Camel-Mina2 ExchangePattern

I am trying to build a prototype using Apache Camel-Mina2 component. We have
our own protocol implementation on TCP and I need to intercept Client -
Server messages using a proxy Component. Existing - TCP Client ----> TCP
Server

New - TCP Client ----> Proxy Server -----> TCP Server

One of the issue in our protocol is that each Request is not guaranteed a
reply from the server, so some requests will be sent on the channel with an
optional response. However some requests will also get back a response.

Protocol Semantics : Hi ----> <---- Hello How Are You ------> Are You okay
-----> <-----Yes

As you can see messages with ----> are from client to server and <---- are
responses from Server ( on a single stream /line).

Now given the above problem, Camel-Mina2 works on a InOut message exchange
pattern. The ExchangePattern Enumeration also has an InOptionalOut use case.

Any suggestions how I can configure my endpoints? I  would like to know if
it is possible to make use of an InOptionalOut exchange pattern. So
essentially not worry about the response for certain types of messages. Can
I handle this programmatically - Read the Message Body and decide if a
Request needs a Response or just needs to be written out  ? 

Sample implementation is as below:

SimpleRegistry reg = new SimpleRegistry();
        reg.put("ProtocolCodec", new ProtocolCodec());
        CamelContext context = new DefaultCamelContext(reg);

        context.addRoutes(new RouteBuilder() {

            @Override
            public void configure() throws Exception {
                // TODO Auto-generated method stub
               
from("mina2:tcp://localhost:9888?sync=true&codec=#ProtocolCodec&disconnectOnNoReply=false").
               
to("mina2:tcp://localhost:9889?sync=true&codec=#ProtocolCodec&disconnectOnNoReply=false&clientMode=true");

            }
        }); 

        context.start();





--
View this message in context: http://camel.465427.n5.nabble.com/Apache-Camel-Mina2-ExchangePattern-tp5765184.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Apache Camel-Mina2 ExchangePattern

Posted by "itsavvy.ankur" <ia...@gmail.com>.
Hi Willem, can you help me with an example of how to do that ? 
I am now able to tweak Camel-Mina2 for my use case.

However run into another problem where the synchronous (blocking) nature of
legacy TCP clients expect a response on write which is asynchronous in
Mina2Producer. This causes a EOFException at the client when it attempts to
read and data is not available. Do you think I can resolve this ? Any
examples you can provide will help.

Thanks.



--
View this message in context: http://camel.465427.n5.nabble.com/Apache-Camel-Mina2-ExchangePattern-tp5765184p5765256.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Apache Camel-Mina2 ExchangePattern

Posted by Willem Jiang <wi...@gmail.com>.
If you just want to do the proxy, it could be quit simple to use the mina API dirtily, you just need to tell the response handler to send the message to channel which receive the request.


--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.iteye.com (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem



On April 2, 2015 at 1:59:32 PM, itsavvy.ankur (iamtheone.ankur@gmail.com) wrote:
> Hi Willem,
> Thanks for your response. I can check the message body for the two command
> headers that just need to be written out but not expect a reply.
> I think the underlying implementation for Mina2Producer will block my use
> case.
> I cannot do sync=false and with sync=true the Mina2Producer implementation
> always checks for a response within a specific timeout.
>  
> May be need to write my own implementation? Any ideas of doing this out of
> the box ?
>  
> Thanks.
> On 2 Apr 2015 11:24, "Willem.Jiang [via Camel]" <
> ml-node+s465427n5765186h11@n5.nabble.com> wrote:
>  
> > Current Camel-Mina2 producer just wait for the response when the endpoint
> > sync option is true, it doesn’t support to set the reply mode dynamically.
> >
> > BTW, can you tell if Message exchange pattern by just looking up the
> > message content?
> >
> >
> > --
> > Willem Jiang
> >
> > Red Hat, Inc.
> > Web: http://www.redhat.com
> > Blog: http://willemjiang.blogspot.com (English)
> > http://jnn.iteye.com (Chinese)
> > Twitter: willemjiang
> > Weibo: 姜宁willem
> >
> >
> >
> > On April 2, 2015 at 1:03:58 PM, itsavvy.ankur ([hidden email]
> > ) wrote:
> >
> > > I am trying to build a prototype using Apache Camel-Mina2 component. We
> > have
> > > our own protocol implementation on TCP and I need to intercept Client -
> > > Server messages using a proxy Component. Existing - TCP Client ----> TCP
> > > Server
> > >
> > > New - TCP Client ----> Proxy Server -----> TCP Server
> > >
> > > One of the issue in our protocol is that each Request is not guaranteed
> > a
> > > reply from the server, so some requests will be sent on the channel with
> > an
> > > optional response. However some requests will also get back a response.
> > >
> > > Protocol Semantics : Hi ----> <---- Hello How Are You ------> Are You
> > okay
> > > -----> <-----Yes
> > >
> > > As you can see messages with ----> are from client to server and <----
> > are
> > > responses from Server ( on a single stream /line).
> > >
> > > Now given the above problem, Camel-Mina2 works on a InOut message
> > exchange
> > > pattern. The ExchangePattern Enumeration also has an InOptionalOut use
> > case.
> > >
> > > Any suggestions how I can configure my endpoints? I would like to know
> > if
> > > it is possible to make use of an InOptionalOut exchange pattern. So
> > > essentially not worry about the response for certain types of messages.
> > Can
> > > I handle this programmatically - Read the Message Body and decide if a
> > > Request needs a Response or just needs to be written out ?
> > >
> > > Sample implementation is as below:
> > >
> > > SimpleRegistry reg = new SimpleRegistry();
> > > reg.put("ProtocolCodec", new ProtocolCodec());
> > > CamelContext context = new DefaultCamelContext(reg);
> > >
> > > context.addRoutes(new RouteBuilder() {
> > >
> > > @Override
> > > public void configure() throws Exception {
> > > // TODO Auto-generated method stub
> > >
> > >
> > from("mina2:tcp://localhost:9888?sync=true&codec=#ProtocolCodec&disconnectOnNoReply=false").  
> >
> > >
> > >
> > to("mina2:tcp://localhost:9889?sync=true&codec=#ProtocolCodec&disconnectOnNoReply=false&clientMode=true");  
> >
> > >
> > > }
> > > });
> > >
> > > context.start();
> > >
> > >
> > >
> > >
> > >
> > > --
> > > View this message in context:
> > http://camel.465427.n5.nabble.com/Apache-Camel-Mina2-ExchangePattern-tp5765184.html  
> >
> > > Sent from the Camel - Users mailing list archive at Nabble.com.
> > >
> >
> >
> >
> > ------------------------------
> > If you reply to this email, your message will be added to the discussion
> > below:
> >
> > http://camel.465427.n5.nabble.com/Apache-Camel-Mina2-ExchangePattern-tp5765184p5765186.html  
> > To unsubscribe from Apache Camel-Mina2 ExchangePattern, click here
> >  
> > .
> > NAML
> >  
> >
>  
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/Apache-Camel-Mina2-ExchangePattern-tp5765184p5765187.html  
> Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Apache Camel-Mina2 ExchangePattern

Posted by "itsavvy.ankur" <ia...@gmail.com>.
Hi Willem,
Thanks for your response. I can check the message body for the two command
headers that just need to be written out but not expect a reply.
I think the underlying implementation for Mina2Producer will block my use
case.
I cannot do sync=false and with sync=true the Mina2Producer implementation
always checks for a response within a specific timeout.

May be need to write my own implementation?  Any ideas of doing this out of
the box ?

Thanks.
On 2 Apr 2015 11:24, "Willem.Jiang [via Camel]" <
ml-node+s465427n5765186h11@n5.nabble.com> wrote:

> Current Camel-Mina2 producer just wait for the response when the endpoint
> sync option is true, it doesn’t support to set the reply mode dynamically.
>
> BTW, can you tell if Message exchange pattern by just looking up the
> message content?
>
>
> --
> Willem Jiang
>
> Red Hat, Inc.
> Web: http://www.redhat.com
> Blog: http://willemjiang.blogspot.com (English)
> http://jnn.iteye.com (Chinese)
> Twitter: willemjiang
> Weibo: 姜宁willem
>
>
>
> On April 2, 2015 at 1:03:58 PM, itsavvy.ankur ([hidden email]
> <http:///user/SendEmail.jtp?type=node&node=5765186&i=0>) wrote:
>
> > I am trying to build a prototype using Apache Camel-Mina2 component. We
> have
> > our own protocol implementation on TCP and I need to intercept Client -
> > Server messages using a proxy Component. Existing - TCP Client ----> TCP
> > Server
> >
> > New - TCP Client ----> Proxy Server -----> TCP Server
> >
> > One of the issue in our protocol is that each Request is not guaranteed
> a
> > reply from the server, so some requests will be sent on the channel with
> an
> > optional response. However some requests will also get back a response.
> >
> > Protocol Semantics : Hi ----> <---- Hello How Are You ------> Are You
> okay
> > -----> <-----Yes
> >
> > As you can see messages with ----> are from client to server and <----
> are
> > responses from Server ( on a single stream /line).
> >
> > Now given the above problem, Camel-Mina2 works on a InOut message
> exchange
> > pattern. The ExchangePattern Enumeration also has an InOptionalOut use
> case.
> >
> > Any suggestions how I can configure my endpoints? I would like to know
> if
> > it is possible to make use of an InOptionalOut exchange pattern. So
> > essentially not worry about the response for certain types of messages.
> Can
> > I handle this programmatically - Read the Message Body and decide if a
> > Request needs a Response or just needs to be written out ?
> >
> > Sample implementation is as below:
> >
> > SimpleRegistry reg = new SimpleRegistry();
> > reg.put("ProtocolCodec", new ProtocolCodec());
> > CamelContext context = new DefaultCamelContext(reg);
> >
> > context.addRoutes(new RouteBuilder() {
> >
> > @Override
> > public void configure() throws Exception {
> > // TODO Auto-generated method stub
> >
> >
> from("mina2:tcp://localhost:9888?sync=true&codec=#ProtocolCodec&disconnectOnNoReply=false").
>
> >
> >
> to("mina2:tcp://localhost:9889?sync=true&codec=#ProtocolCodec&disconnectOnNoReply=false&clientMode=true");
>
> >
> > }
> > });
> >
> > context.start();
> >
> >
> >
> >
> >
> > --
> > View this message in context:
> http://camel.465427.n5.nabble.com/Apache-Camel-Mina2-ExchangePattern-tp5765184.html
>
> > Sent from the Camel - Users mailing list archive at Nabble.com.
> >
>
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://camel.465427.n5.nabble.com/Apache-Camel-Mina2-ExchangePattern-tp5765184p5765186.html
>  To unsubscribe from Apache Camel-Mina2 ExchangePattern, click here
> <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5765184&code=aWFtdGhlb25lLmFua3VyQGdtYWlsLmNvbXw1NzY1MTg0fC01MTEzNTA1MDg=>
> .
> 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/Apache-Camel-Mina2-ExchangePattern-tp5765184p5765187.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Apache Camel-Mina2 ExchangePattern

Posted by Willem Jiang <wi...@gmail.com>.
Current Camel-Mina2 producer just wait for the response when the endpoint sync option is true, it doesn’t support to set the reply mode dynamically.

BTW, can you tell if Message exchange pattern by just looking up the message content?


--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.iteye.com (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem



On April 2, 2015 at 1:03:58 PM, itsavvy.ankur (iamtheone.ankur@gmail.com) wrote:
> I am trying to build a prototype using Apache Camel-Mina2 component. We have
> our own protocol implementation on TCP and I need to intercept Client -
> Server messages using a proxy Component. Existing - TCP Client ----> TCP
> Server
>  
> New - TCP Client ----> Proxy Server -----> TCP Server
>  
> One of the issue in our protocol is that each Request is not guaranteed a
> reply from the server, so some requests will be sent on the channel with an
> optional response. However some requests will also get back a response.
>  
> Protocol Semantics : Hi ----> <---- Hello How Are You ------> Are You okay
> -----> <-----Yes
>  
> As you can see messages with ----> are from client to server and <---- are
> responses from Server ( on a single stream /line).
>  
> Now given the above problem, Camel-Mina2 works on a InOut message exchange
> pattern. The ExchangePattern Enumeration also has an InOptionalOut use case.
>  
> Any suggestions how I can configure my endpoints? I would like to know if
> it is possible to make use of an InOptionalOut exchange pattern. So
> essentially not worry about the response for certain types of messages. Can
> I handle this programmatically - Read the Message Body and decide if a
> Request needs a Response or just needs to be written out ?
>  
> Sample implementation is as below:
>  
> SimpleRegistry reg = new SimpleRegistry();
> reg.put("ProtocolCodec", new ProtocolCodec());
> CamelContext context = new DefaultCamelContext(reg);
>  
> context.addRoutes(new RouteBuilder() {
>  
> @Override
> public void configure() throws Exception {
> // TODO Auto-generated method stub
>  
> from("mina2:tcp://localhost:9888?sync=true&codec=#ProtocolCodec&disconnectOnNoReply=false").  
>  
> to("mina2:tcp://localhost:9889?sync=true&codec=#ProtocolCodec&disconnectOnNoReply=false&clientMode=true");  
>  
> }
> });
>  
> context.start();
>  
>  
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/Apache-Camel-Mina2-ExchangePattern-tp5765184.html  
> Sent from the Camel - Users mailing list archive at Nabble.com.
>