You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by lujan99 <lu...@gmail.com> on 2010/09/17 22:08:48 UTC

SEDA with request-response

I Use a route where my Bean make a call to a webservice, I use SEDA to
support multiple request.
This are request-response how can I do to not block ? because if I use
request-response with seda with first request seda block until is completed,
and then process next request, If I don't use request-response all request
are processed simultaneously.

        <route>
          <from uri="activemq:test99"/>
          <to uri="seda:bar?concurrentConsumers=5"/>
        </route>

        <route>
          <from uri="seda:bar?concurrentConsumers=5"/>

          <to uri="bean:TestG1"/>
        </route>

can u help me?
-- 
View this message in context: http://camel.465427.n5.nabble.com/SEDA-with-request-response-tp2844259p2844259.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: SEDA with request-response

Posted by lujan99 <lu...@gmail.com>.
what do you think about this code:
 (I need to know how dangerous is this code)


 config:
        <template id="camelTemplate"/>
        <route>
          <from uri="activemq:test99"/>
          <to
uri="seda:bar?concurrentConsumers=5&amp;waitForTaskToComplete=Never"/>
        </route>

        <route>
          <from
uri="seda:bar?concurrentConsumers=5&amp;waitForTaskToComplete=Never"/>
          <to uri="bean:TestG1"/>
        </route>
        
        ...
      <bean id="TestG1" class="CamelBean99.TestG1">
        <property name="producerTemplate" ref="camelTemplate"/>
      </bean>


      my GROOVY bean:

  class TestG1 implements Processor {

    private static final transient Log LOG = LogFactory.getLog(TestG1.class
);
    int counter;
    ProducerTemplate producerTemplate;

        void process(Exchange exchange) {
          synchronized (this.counter) {this.counter++;
            LOG.info("DO THAT ${Thread.currentThread().id} ${this}
${counter}");
          }
          sleep(5000);
          String o=exchange.in.getBody(String.class);
          if(exchange.in.headers["JMSReplyTo"]!=null){
              producerTemplate.sendBody(
'activemq:'+exchange.in.headers["JMSReplyTo"],"${o} ${counter} ${new
Date().calendarDate.toString()}");
              }
          synchronized (this.counter) {this.counter--;
          LOG.info("DO END ${Thread.currentThread().id} ${this} ${counter}")
          }
        }
}

log output:

[07:13:20] INFO [CamelBean99.TestG1] - DO THAT 26 CamelBean99.TestG1@189346e
1
[07:13:20] INFO [CamelBean99.TestG1] - DO THAT 23 CamelBean99.TestG1@189346e
2
[07:13:20] INFO [CamelBean99.TestG1] - DO THAT 24 CamelBean99.TestG1@189346e
3
[07:13:20] INFO [CamelBean99.TestG1] - DO THAT 25 CamelBean99.TestG1@189346e
4
[07:13:20] INFO [CamelBean99.TestG1] - DO THAT 27 CamelBean99.TestG1@189346e
5
[07:13:26] INFO [CamelBean99.TestG1] - DO END 26 CamelBean99.TestG1@189346e
4
[07:13:26] INFO [CamelBean99.TestG1] - DO END 27 CamelBean99.TestG1@189346e
3
[07:13:26] INFO [CamelBean99.TestG1] - DO END 24 CamelBean99.TestG1@189346e
2
[07:13:26] INFO [CamelBean99.TestG1] - DO END 23 CamelBean99.TestG1@189346e
1
[07:13:26] INFO [CamelBean99.TestG1] - DO END 25 CamelBean99.TestG1@189346e
0
-- 
View this message in context: http://camel.465427.n5.nabble.com/SEDA-with-request-response-tp2844259p2844659.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: SEDA with request-response

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Sep 17, 2010 at 10:08 PM, lujan99 <lu...@gmail.com> wrote:
>
> I Use a route where my Bean make a call to a webservice, I use SEDA to
> support multiple request.
> This are request-response how can I do to not block ? because if I use
> request-response with seda with first request seda block until is completed,
> and then process next request, If I don't use request-response all request
> are processed simultaneously.
>

For request/reply the SEDA blocks by default.
Otherwise you have to deal with the Future handle.

In Camel 3 we may improve this and allow non blocking req/reply over
SEDA out of the box.


>        <route>
>          <from uri="activemq:test99"/>
>          <to uri="seda:bar?concurrentConsumers=5"/>
>        </route>
>
>        <route>
>          <from uri="seda:bar?concurrentConsumers=5"/>
>
>          <to uri="bean:TestG1"/>
>        </route>
>
> can u help me?
> --
> View this message in context: http://camel.465427.n5.nabble.com/SEDA-with-request-response-tp2844259p2844259.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus