You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ravi <ra...@esq.com> on 2011/09/05 12:18:59 UTC

Synchronous Routing

Hi, 
I am trying to create a route:

from(A:reader).process(convertToXml()).to(B:writer)

Reader is reading message, processor transforming message to xml and writer
is writing xml message to some destination.

I want the flow some what like:

One message read -> Convert to XML -> Write to Destination

Once above flow is completed then:

Second message read -> Convert to XML -> Write to Destination

So i want [from] to [to] should follow Synchronous approach, but the problem
is that reader component is not waiting for writer component. And it send
another message without waiting for a message is  completely written to the
destination.



--
View this message in context: http://camel.465427.n5.nabble.com/Synchronous-Routing-tp4769944p4769944.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Synchronous Routing

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Sep 5, 2011 at 2:41 PM, ravi <ra...@esq.com> wrote:
> Following is the way i am using to send exchange:
>
> Map&lt;String, Object&gt; msgBody;
>
> //Populating msgBody with Key Values
>
> exchange.getIn().setBody(msgBody);
> processor.process(exchange);
>
>
> And how can i identify whether Exchange is processed or not ?
>

That is the synchronous way, so when the process method is done, the
exchange ought to be completed synchronously.
It could also be the fact that your producer writes the message async,
but signal to Camel that the exchange is done.


> --
> View this message in context: http://camel.465427.n5.nabble.com/Synchronous-Routing-tp4769944p4770361.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Synchronous Routing

Posted by ravi <ra...@esq.com>.
Following is the way i am using to send exchange:

Map&lt;String, Object&gt; msgBody;

//Populating msgBody with Key Values

exchange.getIn().setBody(msgBody);
processor.process(exchange);


And how can i identify whether Exchange is processed or not ?

--
View this message in context: http://camel.465427.n5.nabble.com/Synchronous-Routing-tp4769944p4770361.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Synchronous Routing

Posted by Claus Ibsen <cl...@gmail.com>.
The consumer thread keeps running, so you need logic in the read()
method to wait until Camel have processed the exchange.
How do you send the message from the read method to Camel?


On Mon, Sep 5, 2011 at 2:10 PM, ravi <ra...@esq.com> wrote:
> I am using DefaultConsumer which is reading row from a Database (A:reader
> where A is a custom Component ).
>
>
>
> The code to activate Consumer is:
>
> public Consumer createConsumer(Processor processor) throws Exception {
>        return new DefaultConsumer(this, processor) {
>            @Override
>            public void start() throws Exception {
>                super.start();
>                                activateConsumer(this);
>            }}}
>
> protected void activateConsumer(DefaultConsumer consumer) throws IOException
> {
>        thread = new Thread()
>        {
>                @Override
>                public void run() {
>                        while(keepRunning == true)
>                        {
>                                read();
>                        }
>                }
>        };
>        thread.setName("Thread: " + getEndpointUri());
>        thread.setDaemon(true);
>        thread.start();
> }
>
> And the CAMEL Version is 2.7.0
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Synchronous-Routing-tp4769944p4770271.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Synchronous Routing

Posted by ravi <ra...@esq.com>.
I am using DefaultConsumer which is reading row from a Database (A:reader
where A is a custom Component ). 



The code to activate Consumer is:

public Consumer createConsumer(Processor processor) throws Exception {
        return new DefaultConsumer(this, processor) {
            @Override
            public void start() throws Exception {
                super.start();
				activateConsumer(this);
            }}}

protected void activateConsumer(DefaultConsumer consumer) throws IOException 
{
	thread = new Thread() 
	{
		@Override
		public void run() {
			while(keepRunning == true)
			{
				read();
			}
		}
	};
	thread.setName("Thread: " + getEndpointUri());
	thread.setDaemon(true);
	thread.start();
}

And the CAMEL Version is 2.7.0

--
View this message in context: http://camel.465427.n5.nabble.com/Synchronous-Routing-tp4769944p4770271.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Synchronous Routing

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Sep 5, 2011 at 12:18 PM, ravi <ra...@esq.com> wrote:
> Hi,
> I am trying to create a route:
>
> from(A:reader).process(convertToXml()).to(B:writer)
>
> Reader is reading message, processor transforming message to xml and writer
> is writing xml message to some destination.
>
> I want the flow some what like:
>
> One message read -> Convert to XML -> Write to Destination
>
> Once above flow is completed then:
>
> Second message read -> Convert to XML -> Write to Destination
>
> So i want [from] to [to] should follow Synchronous approach, but the problem
> is that reader component is not waiting for writer component. And it send
> another message without waiting for a message is  completely written to the
> destination.

It really depends on how you consumer on A is implemented, whether it
can support this.
What kind of consumer are you using?

And what version of Camel are you using?



>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Synchronous-Routing-tp4769944p4769944.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/