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.

Reply via email to