You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by "dr.jeff" <jl...@systechnologies.com> on 2007/04/19 15:47:30 UTC

[camel] How to use consumers producers

I have a SOAP client component that I am hooking up like this:
               
from("queue:requests").to("soap.client:http://a.b.c:80/soap-service");
               
from("soap.client:http://a.b.c:80/soap-service").to("queue.responses");
(This is part of a bigger flow that is pulling in messages from a socket and
putting them in the request queue, then looking at the responses and making
decisions about eg. getting more messages.)
The way I have gotten this to work is to make something that implements
Consumer<Exchange>, Producer<Exchange>, saves the processor from
createConsumer(), and does this:
	public void process(Exchange exchange) {
		Message in = exchange.getIn();
		Object request = in.getBody();
		Object response = clientPort.someOperation(request); //call the SOAP
service here
		Exchange exchange2 = endpoint.createExchange();
	                Message out = exchange2.getIn();
	                out.setBody(response);
	                processor.process(exchange2);		
	}
This all works, but it can't be right. What happened to getOut() for the
first exchange? I't just ignored here.
Surely I'm missing the intended way to use these components.
-- 
View this message in context: http://www.nabble.com/-camel--How-to-use-consumers-producers-tf3607252s2354.html#a10078142
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: [camel] How to use consumers producers

Posted by James Strachan <ja...@gmail.com>.
On 4/19/07, dr.jeff <jl...@systechnologies.com> wrote:
>
> I have a SOAP client component that I am hooking up like this:
>
> from("queue:requests").to("soap.client:http://a.b.c:80/soap-service");
 >
> from("soap.client:http://a.b.c:80/soap-service").to("queue.responses");
> (This is part of a bigger flow that is pulling in messages from a socket and
> putting them in the request queue, then looking at the responses and making
> decisions about eg. getting more messages.)
> The way I have gotten this to work is to make something that implements
> Consumer<Exchange>, Producer<Exchange>, saves the processor from
> createConsumer(), and does this:
>         public void process(Exchange exchange) {
>                 Message in = exchange.getIn();
>                 Object request = in.getBody();
>                 Object response = clientPort.someOperation(request); //call the SOAP
> service here
>                 Exchange exchange2 = endpoint.createExchange();
>                         Message out = exchange2.getIn();
>                         out.setBody(response);
>                         processor.process(exchange2);
>         }
> This all works, but it can't be right. What happened to getOut() for the
> first exchange? I't just ignored here.
> Surely I'm missing the intended way to use these components.

So first off; we've not got that many examples yet of request/response
style processing; so we might need to tidy a few things up in that
area - apologies; we should have that sorted soon.

Am thinking the processor of the clientPort, should put the output in
the exchange.getOut() like this...

public void process(Exchange exchange) {
               Message in = exchange.getIn();
               Object request = in.getBody();
               //call the SOAP service here
               Object response = clientPort.someOperation(request);
               exchange.getOut().setBody(response);
}

then thats the soap endpoint being processed.

then you could for example do

from("queue:requests").pipeline("soap.client:http://a.b.c:80/soap-service",
"file:/mydirectory");

or whatever - basically passing the output of the soap client to some
external destination such as a file or jms queue or whatever.

If you use the direct: component (which Hiram just added if you're
watching the commit log)

http://cwiki.apache.org/CAMEL/direct.html

then you could process the pipeline synchronously from the start.

e.g. if you had

from("direct:requests").to("soap.client:http://a.b.c:80/soap-service");

and you then invoked things like this...

        CamelClient client = ...;
        Exchange exchange = client.send("direct:requests", new
Processor<Exchange>() {
            public void process(Exchange exchange) {
                // now lets fire in a message
                Message in = exchange.getIn();
                in.setBody("<hello>world</hello>");
            }
        });
				System.out.println("Received output: " + exchange.getOut().getBody());

i.e. with one exchange invoke an endpoint and extract the out body.

Does that help at all?

-- 
James
-------
http://macstrac.blogspot.com/