You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by xiangqiuzhao <xi...@gmail.com> on 2011/07/03 17:14:35 UTC

how to route one request with socket communications by many times?

If my client application want to send message to my Camel with socket, and
application communication protocol is send three bytes like 'REQ' to server
first, and the server response three bytes like 'ANS' to client for affirm
the request, then client begin to send application message package to
server, these processes show one time whole reqeust。

like that, how to implement in Camel? 

i know use from("mina:tcp://localhost:9999").processRef(...) can complete
request and recv response one time, but my application needs twice request
and response in the same socket handle. how to ?

--
View this message in context: http://camel.465427.n5.nabble.com/how-to-route-one-request-with-socket-communications-by-many-times-tp4547395p4547395.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: how to route one request with socket communications by many times?

Posted by Willem Jiang <wi...@gmail.com>.
I don't think your processor need to handle the customer protocol. 
You just need to put the message that you want Camel process into the 
exchange.
Then Camel will handle the rest of it.

On Thu Jul 28 09:33:53 2011, xiangqiuzhao wrote:
> i take a look at mina Consumer, i have some question
> 
> MyConsumer must handle the processor in the DSL by "from().process()"? if
> have some processes how to write? why the mina call the process(exchange)
> only once? or it's recursive auto?
> 
> the mina consumer code like :
> 
> //received message
> try {
>                  getProcessor().process(exchange);
>              } catch (Throwable e) {
>                  getExceptionHandler().handleException(e);
>              }
> 
> //write message to request
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/how-to-route-one-request-with-socket-communications-by-many-times-tp4547395p4640914.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
         http://jnn.javaeye.com (Chinese)
Twitter: willemjiang 
Weibo: willemjiang 


Re: how to route one request with socket communications by many times?

Posted by xiangqiuzhao <xi...@gmail.com>.
i take a look at mina Consumer, i have some question

MyConsumer must handle the processor in the DSL by "from().process()"? if
have some processes how to write? why the mina call the process(exchange)
only once? or it's recursive auto?

the mina consumer code like :

//received message
try {
                getProcessor().process(exchange);
            } catch (Throwable e) {
                getExceptionHandler().handleException(e);
            }

//write message to request


--
View this message in context: http://camel.465427.n5.nabble.com/how-to-route-one-request-with-socket-communications-by-many-times-tp4547395p4640914.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: how to route one request with socket communications by many times?

Posted by Willem Jiang <wi...@gmail.com>.
You can take a look at the code of mina or netty component and add some 
custom process to handle your protocol.

On 7/27/11 6:06 PM, xiangqiuzhao wrote:
> how to implement the transport protocol ?
> i create myComponent and myConsumer extends DefaultConsumer,
> where to add my protocol handle when i received client request.
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/how-to-route-one-request-with-socket-communications-by-many-times-tp4547395p4638219.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>


-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Weibo: willemjiang

Re: how to route one request with socket communications by many times?

Posted by xiangqiuzhao <xi...@gmail.com>.
how to implement the transport protocol ?
i create myComponent and myConsumer extends DefaultConsumer,
where to add my protocol handle when i received client request.

--
View this message in context: http://camel.465427.n5.nabble.com/how-to-route-one-request-with-socket-communications-by-many-times-tp4547395p4638219.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: how to route one request with socket communications by many times?

Posted by Willem Jiang <wi...@gmail.com>.
Hi,
Maybe you need to implement the transport protocol yourself, and 
integrate it with Camel by using the camel component[1]

[1]http://camel.apache.org/creating-a-new-camel-component.html

On 7/4/11 9:10 AM, xiangqiuzhao wrote:
> yes, i means to be an application level handshake, but my client provide by
> other systems , like c or c++ implements, so you can't decide the clients
> use uuid to distinguish the twice interaction.
>
> by the way, what the principle about the message exchange in Camel, use
> something like MQ ?
>
> excuse for expression with poor english
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/how-to-route-one-request-with-socket-communications-by-many-times-tp4547395p4548548.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>


-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Weibo: willemjiang

Re: how to route one request with socket communications by many times?

Posted by xiangqiuzhao <xi...@gmail.com>.
yes, i means to be an application level handshake, but my client provide by
other systems , like c or c++ implements, so you can't decide the clients
use uuid to distinguish the twice interaction.

by the way, what the principle about the message exchange in Camel, use
something like MQ ? 

excuse for expression with poor english 

--
View this message in context: http://camel.465427.n5.nabble.com/how-to-route-one-request-with-socket-communications-by-many-times-tp4547395p4548548.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: how to route one request with socket communications by many times?

Posted by Ashwin Karpe <ak...@fusesource.com>.
Hi,

The only way to do this would be to introduce a unique correlationId for the
2 messages during the client server interaction. This would help the client
and server co-ordinate their behavior in a multi-threaded routing
environment like Camel and maintain ordered message processing consistent
with the handshake you mention.

The handshake you have specified seem to be more of an application level
handshake to achieve some kind of message level guarantees (aka
WS-ReliableMessaging). These are not a function of the TCP/IP, Mina or
Camel.

Please see the sample below, illustrating how you could design your
client/server in Camel to accomplish what you are looking for... Please feel
free to change as you see fit. This is not meant to be the final product,
just something I cobbled up as part of my response :)

Cheers,

Ashwin...

=====================================================


Client
=====
import java.util.UUID;
...

public class MyClient {
  @EndpointInject(uri="mina:tcp://localhost:9999")
  ProducerTemplate producer;
  
  public void sendMessage(String message) {
    if (whatever) {
      UUID uuid = UUID.randomUUID();
      String response = producer.requestBody(uuid +":"+"REQ");
      if (response.equalsIgnoreCase(uuid+":"+"ANS")) {
            producer.sendBody(message);
      }
    }
  }
}

Server
====


RouteBuilder builder = new RouteBuilder() {
    public void configure() {

        from("mina:tcp://localhost:9999")
            .process(new Processor() {
                 public void process(Exchange exchange) throws Exception {
                      String message =
exchange.getIn().getBody(String.class);
                      if (message.contains("REQ") {
                               // Preserve incoming UUID in a HashMap
                               ...
                               // Send answer
                              
exchange.getIn().setBody(message.replace("REQ","ANS");
                      } else {
                               // Match UUID with HashMap UUIDs.
                               // If match found do something...
                               // Remove UUID from HashMap...
                      }
                 }
            });
    }
};

=============================================

-----
---------------------------------------------------------
Ashwin Karpe
Apache Camel Committer & Sr Principal Consultant
FUSESource (a Progress Software Corporation subsidiary)
http://fusesource.com 

Blog: http://opensourceknowledge.blogspot.com 
CamelOne 2011: http://fusesource.com/camel2011 
---------------------------------------------------------
--
View this message in context: http://camel.465427.n5.nabble.com/how-to-route-one-request-with-socket-communications-by-many-times-tp4547395p4547585.html
Sent from the Camel - Users mailing list archive at Nabble.com.