简体   繁体   中英

Apache Camel Mina2 not receiving data using Socket

I have been trying to send data through socket programming to Apache Camel and I am trying to use Apache Mina2 . The idea is to send the data over TCP to Camel. For TCP, I am using socket programing. This is what my code is for Mina2 :

public void configure() throws Exception {
from("mina2:tcp://localhost:6789?sync=false")
    .process(new LogProcessor());
}

LogProcessor only prints the body of the received message using exchange.getIn().getBody(String.class)

This piece of code works fine with Apache Mina as below:

from("mina:tcp://localhost:6789?textline=true&sync=true")
    .process(new LogProcessor());

The socket programming client code that I am using is as below:

  try
      {
         Socket client = new Socket();




         client.connect(new InetSocketAddress("localhost", 6789));

         OutputStream outToServer = client.getOutputStream();
         DataOutputStream out = new DataOutputStream(outToServer);
         System.out.println("After Dataoutput stream");
         out.writeBytes("Content gets received in server\n");

         client.close();
      }

The same piece of code works fine for Mina but does not work with Mina2 . I am unable to figure out what is causing the problem. Do I need to add some parameters in the from clause of Camel.

Kindly help..

It is caused by mina2 consumer doesn't take the response from the in message. You need to setup the out message in your LogProcessor just like this.

 exchange.getOut().getBody("response message");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM