Hi,
Yes, very easy example which I have used before in here:
First I send my Receiver class:
public class Receiver{
public static void main(String [] s){
try{
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
public void configure() {
from("mina:tcp://localhost:6123").process(new Processor() {
public void process(Exchange e) {
System.out.println("Received exchange: " +
e.getIn().getBody()+" "+e.getIn().getHeaders()+" "+e.getProperties());
}
});
}
});
context.start();
}catch(Throwable ex){
ex.printStackTrace();
}
}
}
When I start the receiver program, indeed a TCP server at port 6123
startslistening for calls.
Now my Sender program:
public class Sender{
public static void main(String [] s){
try{
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
public void configure() {
from("direct:mycall").process(new Processor() {
public void process(Exchange e) {
System.out.println("Received exchange: " +
e.getIn().getBody()+" "+e.getIn().getHeaders()+" "+e.getProperties());
}
});
}
});
context.start();
// CALL DIRECT/BEAN (WORKS(SENDS ALL)
// Endpoint endpoint = context.getEndpoint("direct:mycall");
// Endpoint endpoint = context.getEndpoint("bean:mybean");
// CALL VIA TCP (NOT SENDING HEADERS/PROPERTIES)
Endpoint endpoint =
context.getEndpoint("mina:tcp://localhost:6123");
MinaExchange exchange =
(MinaExchange)endpoint.createExchange(ExchangePattern.In);
Message in = exchange.getIn();
in.setBody("tcp request");
in.setHeader("headerkey","headervalue");
exchange.setProperty("prop_key","prop_value");
Producer producer = endpoint.createProducer();
producer.start();
producer.process(exchange);
Message out = exchange.getOut();
System.out.println(out.getBody());
producer.stop();
context.stop();
}catch(Throwable ex){
ex.printStackTrace();
}
}
}
In the sender you can comment/uncomment the different endpoints and you ill
see the output printed from inside the processor.
Hope that helps.
Thank you
Georgios
davsclaus wrote:
>
> Georgios,
>
> Can you provide a small junit test that demonstrates this problem/bug?
> Would be much easier for discussing the problem and providing a patch for
> the bug.
>
> /Claus
>
>
>
> georgiosgeorgiadis wrote:
>>
>> I have found out that the message properties and headers soes not seem to
>> be passed when using MINA TCP communication. In direct pojo or bean,
>> everything seems working.
>>
>> Regards
>>
>> Georgios
>>
>>
>> georgiosgeorgiadis wrote:
>>>
>>> I am quite new to Camel, but I will need to use camel for implementing
>>> the following requirement:
>>>
>>> I will need a component to be listening to a specific TCP port. Do I
>>> need to have a custom written TCP server which will serve the TCP
>>> component, or Camel can automatically wrap my component with a Camel TCP
>>> listener (server) using some type of constructor? For example I have the
>>> component:
>>>
>>> public class MyComponent{
>>> public void doSomething(){
>>> }
>>> }
>>>
>>> possible Camel TCP wrapper
>>>
>>> Enpoint p = new CamelTCPEndpoint("localhost",5555,new MyComponent());
>>> p.start();
>>>
>>> My question is, does something like that exist or do I have to implement
>>> my own custom TCP servers/ listeners for my components? The general
>>> requirement is to have a component which calls a camel sender endpont
>>> which connects synchronously to a camel receiver TCP endpoint which
>>> propages the call to a component and send a reply all the way back to
>>> the sender, basically loosely coupled communication/routing between
>>> different environments.
>>>
>>> I am trying to reduce communication implementation to the minimum and
>>> just use configurations loaded from a file or repository.
>>>
>>> Thank you in advance
>>>
>>> Georgios
>>>
>>
>>
>
>
--
View this message in context:
http://www.nabble.com/Camel-TCP-receiver-endpoint-tp15430834s22882p15870389.html
Sent from the Camel - Users mailing list archive at Nabble.com.