You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Cristiano Costantini <cr...@gmail.com> on 2013/09/04 12:26:12 UTC

MultipleConsumer on a vm: endpoint

Hi All,

I've switched and endpoint using seda: with options multipleConsumers=true
and waitForTaskToComplete=Never to using vm: component.

After this, the application does not respect anymore the
multipleConsumers=true options and two concurrent consumer steal the
message.

I may have other issue which I'm going to investigate, but to avoid waste
time I please ask you if I'm missing some detail by switching from seda: to
vm: (it is the first time I use vm: and I was expecting the same behavior
of the seda:endpoint)

I'm using Camel 2.10.6 inside Servicemix 4.5.2.

Thank you very much!

Cristiano

Re: MultipleConsumer on a vm: endpoint

Posted by Christian Posta <ch...@gmail.com>.
I've submitted a patch and tests for this.


On Fri, Sep 13, 2013 at 5:55 AM, Claus Ibsen <cl...@gmail.com> wrote:

> Hi
>
> I logged a ticket to not forget about this
> https://issues.apache.org/jira/browse/CAMEL-6746
>
> On Thu, Sep 5, 2013 at 10:19 AM, Claus Ibsen <cl...@gmail.com>
> wrote:
> > On Thu, Sep 5, 2013 at 10:15 AM, Cristiano Costantini
> > <cr...@gmail.com> wrote:
> >>> Yeah multipleConsumers is not support for vm. As the consumers is not
> >>> static shared.
> >>>
> >>> Hi,
> >> is that something intentional (sharing statically the consumers had
> other
> >> issues) or something, let say, a patch for is welcome?
> >>
> >> Thank you,
> >> Cristiano
> >
> > Yeah I think it could be doable to have them static as well on the
> > VmComponent. The consumer implementation is from the same camel-core
> > JAR which is shared, so that ought to be okay.
> >
> > Yeah we love contributions
> > http://camel.apache.org/contributing.html
> >
> >
> > --
> > Claus Ibsen
> > -----------------
> > Red Hat, Inc.
> > Email: cibsen@redhat.com
> > Twitter: davsclaus
> > Blog: http://davsclaus.com
> > Author of Camel in Action: http://www.manning.com/ibsen
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
>



-- 
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta

Re: MultipleConsumer on a vm: endpoint

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

I logged a ticket to not forget about this
https://issues.apache.org/jira/browse/CAMEL-6746

On Thu, Sep 5, 2013 at 10:19 AM, Claus Ibsen <cl...@gmail.com> wrote:
> On Thu, Sep 5, 2013 at 10:15 AM, Cristiano Costantini
> <cr...@gmail.com> wrote:
>>> Yeah multipleConsumers is not support for vm. As the consumers is not
>>> static shared.
>>>
>>> Hi,
>> is that something intentional (sharing statically the consumers had other
>> issues) or something, let say, a patch for is welcome?
>>
>> Thank you,
>> Cristiano
>
> Yeah I think it could be doable to have them static as well on the
> VmComponent. The consumer implementation is from the same camel-core
> JAR which is shared, so that ought to be okay.
>
> Yeah we love contributions
> http://camel.apache.org/contributing.html
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: MultipleConsumer on a vm: endpoint

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Sep 5, 2013 at 10:15 AM, Cristiano Costantini
<cr...@gmail.com> wrote:
>> Yeah multipleConsumers is not support for vm. As the consumers is not
>> static shared.
>>
>> Hi,
> is that something intentional (sharing statically the consumers had other
> issues) or something, let say, a patch for is welcome?
>
> Thank you,
> Cristiano

Yeah I think it could be doable to have them static as well on the
VmComponent. The consumer implementation is from the same camel-core
JAR which is shared, so that ought to be okay.

Yeah we love contributions
http://camel.apache.org/contributing.html


-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: MultipleConsumer on a vm: endpoint

Posted by Cristiano Costantini <cr...@gmail.com>.
> Yeah multipleConsumers is not support for vm. As the consumers is not
> static shared.
>
> Hi,
is that something intentional (sharing statically the consumers had other
issues) or something, let say, a patch for is welcome?

Thank you,
Cristiano

Re: MultipleConsumer on a vm: endpoint

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Yeah multipleConsumers is not support for vm. As the consumers is not
static shared.

On Wed, Sep 4, 2013 at 4:38 PM, Cristiano Costantini
<cr...@gmail.com> wrote:
> Hi Claus,
> that what I would expect and it works if all the consumers are on the same
> CamelContext.
>
> If I start two consumers on two different CamelContext, only one is reached
> by the route, and apparently it is the first one which is registered.
>
> thank you for your interest,
>
> Cristiano
>
>
>
>
>
> 2013/9/4 Claus Ibsen <cl...@gmail.com>
>
>> When you have mutipleConsumers=true and have 2+ consumers on the queue
>> name. Then each of them get a copy of the exchange, to process in
>> parallel.
>>
>> Its kinda like Topics in JMS land.
>>
>> Are you saying you expect something else to happen?
>>
>> On Wed, Sep 4, 2013 at 12:26 PM, Cristiano Costantini
>> <cr...@gmail.com> wrote:
>> > Hi All,
>> >
>> > I've switched and endpoint using seda: with options
>> multipleConsumers=true
>> > and waitForTaskToComplete=Never to using vm: component.
>> >
>> > After this, the application does not respect anymore the
>> > multipleConsumers=true options and two concurrent consumer steal the
>> > message.
>> >
>> > I may have other issue which I'm going to investigate, but to avoid waste
>> > time I please ask you if I'm missing some detail by switching from seda:
>> to
>> > vm: (it is the first time I use vm: and I was expecting the same behavior
>> > of the seda:endpoint)
>> >
>> > I'm using Camel 2.10.6 inside Servicemix 4.5.2.
>> >
>> > Thank you very much!
>> >
>> > Cristiano
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> Red Hat, Inc.
>> Email: cibsen@redhat.com
>> Twitter: davsclaus
>> Blog: http://davsclaus.com
>> Author of Camel in Action: http://www.manning.com/ibsen
>>



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: MultipleConsumer on a vm: endpoint

Posted by Cristiano Costantini <cr...@gmail.com>.
Hi Claus,
that what I would expect and it works if all the consumers are on the same
CamelContext.

If I start two consumers on two different CamelContext, only one is reached
by the route, and apparently it is the first one which is registered.

thank you for your interest,

Cristiano





2013/9/4 Claus Ibsen <cl...@gmail.com>

> When you have mutipleConsumers=true and have 2+ consumers on the queue
> name. Then each of them get a copy of the exchange, to process in
> parallel.
>
> Its kinda like Topics in JMS land.
>
> Are you saying you expect something else to happen?
>
> On Wed, Sep 4, 2013 at 12:26 PM, Cristiano Costantini
> <cr...@gmail.com> wrote:
> > Hi All,
> >
> > I've switched and endpoint using seda: with options
> multipleConsumers=true
> > and waitForTaskToComplete=Never to using vm: component.
> >
> > After this, the application does not respect anymore the
> > multipleConsumers=true options and two concurrent consumer steal the
> > message.
> >
> > I may have other issue which I'm going to investigate, but to avoid waste
> > time I please ask you if I'm missing some detail by switching from seda:
> to
> > vm: (it is the first time I use vm: and I was expecting the same behavior
> > of the seda:endpoint)
> >
> > I'm using Camel 2.10.6 inside Servicemix 4.5.2.
> >
> > Thank you very much!
> >
> > Cristiano
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
>

Re: MultipleConsumer on a vm: endpoint

Posted by Claus Ibsen <cl...@gmail.com>.
When you have mutipleConsumers=true and have 2+ consumers on the queue
name. Then each of them get a copy of the exchange, to process in
parallel.

Its kinda like Topics in JMS land.

Are you saying you expect something else to happen?

On Wed, Sep 4, 2013 at 12:26 PM, Cristiano Costantini
<cr...@gmail.com> wrote:
> Hi All,
>
> I've switched and endpoint using seda: with options multipleConsumers=true
> and waitForTaskToComplete=Never to using vm: component.
>
> After this, the application does not respect anymore the
> multipleConsumers=true options and two concurrent consumer steal the
> message.
>
> I may have other issue which I'm going to investigate, but to avoid waste
> time I please ask you if I'm missing some detail by switching from seda: to
> vm: (it is the first time I use vm: and I was expecting the same behavior
> of the seda:endpoint)
>
> I'm using Camel 2.10.6 inside Servicemix 4.5.2.
>
> Thank you very much!
>
> Cristiano



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: MultipleConsumer on a vm: endpoint

Posted by Cristiano Costantini <cr...@gmail.com>.
More info:

I see that VmComponent implementation simply extends the SedaEndpoint and
instead of using its queues:

    private final Map<String, QueueReference> queues = new HashMap<String,
QueueReference>();

uses a static map:

    protected static final Map<String, QueueReference> QUEUES = new
HashMap<String, QueueReference>();


well, this is ok and smart, but it happen that when you get the consumers
in SedaEndpoint

    public Set<SedaConsumer> getConsumers() {
        return new HashSet<SedaConsumer>(consumers);
    }

it does not returns all the consumers from any camel context.
In my previous example when I was using 1 producer in one context and 2
consumers in two other different contexts, the getConsumers() was returning
a set with only one consumer.

Now I'm starting thinking that this is a bug ;-)

Cristiano




2013/9/4 Cristiano Costantini <cr...@gmail.com>

> Hi all again,
> I have investigated the behavior and I get to the conclusion that vm: does
> not support the option "multipleConsumers" between different contexts (on
> the same JVM).
> Could anyone please confirm if this is the expected behavior or if it is a
> bug?
>
> thank you!
> Cristiano
>
>
> PS. Here are my clues and the code I have used to make the test:
>
> 1. if start multiple consumers on "seda:test" or "vm:test" on the same
> CamelContext I get a
> "Failed to start route route2 because of Multiple consumers for the same
> endpoint is not allowed" (Expected Behavior)
>
> 2. if start multiple consumers on "seda:test" from
> different CamelContext I get no errors but no message is exchanged
> (Expected Behavior)
>
> 3. if start multiple consumers on "vm:test" from different CamelContext
> get no errors, and only one consumer get the message (???? I don't if it is
> the desired behavior or if it should work as case 1 as vm: should see that
> there are multiple consumers for the same endpoint)
>
> 4. if start multiple consumers on "seda:test?multipleConsumers=true" or
> "vm:test?multipleConsumers=true" on the same CamelContext  t works and each
> consumer get the message  (Expected Behavior)
>
> 5. if start multiple consumers on "seda:test?multipleConsumers=true" using
> different CamelContext   get no errors and again no message is exchanged
> (Expected Behavior as each camel context is independent)
>
> 6. if start multiple consumers on "vm:test?multipleConsumers=true" using
> different CamelContext I get no errors, but only one consumer get the
> message (Unexpected Behavior!!)
>
>
> Here the class I have used to make the test:
>
> package eu.protectrail.esb.camel;
>
> import org.apache.camel.CamelContext;
> import org.apache.camel.Exchange;
> import org.apache.camel.Processor;
> import org.apache.camel.ProducerTemplate;
> import org.apache.camel.builder.RouteBuilder;
> import org.apache.camel.impl.DefaultCamelContext;
>
> public class CamelSedaVmTests {
>
>   public static class TestConsumer {
>     private final String id;
>     private final CamelContext context;
>
>     public TestConsumer(String id, CamelContext context) {
>       this.id = id;
>       this.context = context;
>     };
>
>     public void registerRoutes(final String endpoint) throws Exception {
>       context.addRoutes(new RouteBuilder() {
>         @Override
>         public void configure() {
>           from(endpoint).process(new Processor() {
>             @Override
>             public void process(Exchange exchange) throws Exception {
>               System.out.println(id + " has received " +
> exchange.getIn().getBody(String.class));
>             }
>           });
>         }
>       });
>     }
>
>   }
>   public static class TestProducer {
>
>     private final CamelContext context;
>
>     public TestProducer(CamelContext context) {
>       this.context = context;
>     };
>
>     public void produce(String body, String endpoint) {
>       ProducerTemplate template = context.createProducerTemplate();
>       template.sendBody(endpoint, body);
>     }
>   }
>
>   public static void main(String[] args) throws Exception {
>
>     // NOTE: uncomment the endpoint to test and set shareContext value to
>     // true to use the same camel context for all the routes
>
>     // final String endpoint = "seda:test";
>     // final String endpoint = "vm:test";
>     // final String endpoint = "seda:test?multipleConsumers=true";
>     final String endpoint = "vm:test?multipleConsumers=true";
>     boolean shareContext = false;
>
>     TestConsumer consumerOne;
>     TestConsumer consumerTwo;
>     TestProducer producer;
>
>     if (!shareContext) {
>       // Test using 3 different contexts for the 2 consumer and the
> producer
>       DefaultCamelContext contextUno = new DefaultCamelContext();
>       DefaultCamelContext contextDue = new DefaultCamelContext();
>       DefaultCamelContext contextProducer = new DefaultCamelContext();
>
>       consumerOne = new TestConsumer("one", contextUno);
>       consumerTwo = new TestConsumer("two", contextDue);
>       producer = new TestProducer(contextProducer);
>
>       contextUno.start();
>       contextDue.start();
>       contextProducer.start();
>
>     } else {
>       // Test using the same contexts for consumer and producers
>       DefaultCamelContext sameContext = new DefaultCamelContext();
>       consumerOne = new TestConsumer("one", sameContext);
>       consumerTwo = new TestConsumer("two", sameContext);
>       producer = new TestProducer(sameContext);
>
>       sameContext.start();
>     }
>
>     consumerOne.registerRoutes(endpoint);
>     consumerTwo.registerRoutes(endpoint);
>
>     Thread.sleep(1000);
>     System.out.println("-- START --");
>     producer.produce("foo", endpoint);
>
>     Thread.sleep(1000);
>     producer.produce("bar", endpoint);
>
>     Thread.sleep(1000);
>     producer.produce("baz", endpoint);
>
>     System.out.println("-- END --");
>   }
> }
>
>
>
> 2013/9/4 Cristiano Costantini <cr...@gmail.com>
>
>> Hi All,
>>
>> I've switched and endpoint using seda: with options
>> multipleConsumers=true and waitForTaskToComplete=Never to using vm:
>> component.
>>
>> After this, the application does not respect anymore the
>> multipleConsumers=true options and two concurrent consumer steal the
>> message.
>>
>> I may have other issue which I'm going to investigate, but to avoid waste
>> time I please ask you if I'm missing some detail by switching from seda: to
>> vm: (it is the first time I use vm: and I was expecting the same behavior
>> of the seda:endpoint)
>>
>> I'm using Camel 2.10.6 inside Servicemix 4.5.2.
>>
>> Thank you very much!
>>
>> Cristiano
>>
>
>

Re: MultipleConsumer on a vm: endpoint

Posted by Cristiano Costantini <cr...@gmail.com>.
Hi all again,
I have investigated the behavior and I get to the conclusion that vm: does
not support the option "multipleConsumers" between different contexts (on
the same JVM).
Could anyone please confirm if this is the expected behavior or if it is a
bug?

thank you!
Cristiano


PS. Here are my clues and the code I have used to make the test:

1. if start multiple consumers on "seda:test" or "vm:test" on the same
CamelContext I get a
"Failed to start route route2 because of Multiple consumers for the same
endpoint is not allowed" (Expected Behavior)

2. if start multiple consumers on "seda:test" from different CamelContext I
get no errors but no message is exchanged (Expected Behavior)

3. if start multiple consumers on "vm:test" from different CamelContext
get no errors, and only one consumer get the message (???? I don't if it is
the desired behavior or if it should work as case 1 as vm: should see that
there are multiple consumers for the same endpoint)

4. if start multiple consumers on "seda:test?multipleConsumers=true" or
"vm:test?multipleConsumers=true" on the same CamelContext  t works and each
consumer get the message  (Expected Behavior)

5. if start multiple consumers on "seda:test?multipleConsumers=true" using
different CamelContext   get no errors and again no message is exchanged
(Expected Behavior as each camel context is independent)

6. if start multiple consumers on "vm:test?multipleConsumers=true" using
different CamelContext I get no errors, but only one consumer get the
message (Unexpected Behavior!!)


Here the class I have used to make the test:

package eu.protectrail.esb.camel;

import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;

public class CamelSedaVmTests {

  public static class TestConsumer {
    private final String id;
    private final CamelContext context;

    public TestConsumer(String id, CamelContext context) {
      this.id = id;
      this.context = context;
    };

    public void registerRoutes(final String endpoint) throws Exception {
      context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() {
          from(endpoint).process(new Processor() {
            @Override
            public void process(Exchange exchange) throws Exception {
              System.out.println(id + " has received " +
exchange.getIn().getBody(String.class));
            }
          });
        }
      });
    }

  }
  public static class TestProducer {

    private final CamelContext context;

    public TestProducer(CamelContext context) {
      this.context = context;
    };

    public void produce(String body, String endpoint) {
      ProducerTemplate template = context.createProducerTemplate();
      template.sendBody(endpoint, body);
    }
  }

  public static void main(String[] args) throws Exception {

    // NOTE: uncomment the endpoint to test and set shareContext value to
    // true to use the same camel context for all the routes

    // final String endpoint = "seda:test";
    // final String endpoint = "vm:test";
    // final String endpoint = "seda:test?multipleConsumers=true";
    final String endpoint = "vm:test?multipleConsumers=true";
    boolean shareContext = false;

    TestConsumer consumerOne;
    TestConsumer consumerTwo;
    TestProducer producer;

    if (!shareContext) {
      // Test using 3 different contexts for the 2 consumer and the producer
      DefaultCamelContext contextUno = new DefaultCamelContext();
      DefaultCamelContext contextDue = new DefaultCamelContext();
      DefaultCamelContext contextProducer = new DefaultCamelContext();

      consumerOne = new TestConsumer("one", contextUno);
      consumerTwo = new TestConsumer("two", contextDue);
      producer = new TestProducer(contextProducer);

      contextUno.start();
      contextDue.start();
      contextProducer.start();

    } else {
      // Test using the same contexts for consumer and producers
      DefaultCamelContext sameContext = new DefaultCamelContext();
      consumerOne = new TestConsumer("one", sameContext);
      consumerTwo = new TestConsumer("two", sameContext);
      producer = new TestProducer(sameContext);

      sameContext.start();
    }

    consumerOne.registerRoutes(endpoint);
    consumerTwo.registerRoutes(endpoint);

    Thread.sleep(1000);
    System.out.println("-- START --");
    producer.produce("foo", endpoint);

    Thread.sleep(1000);
    producer.produce("bar", endpoint);

    Thread.sleep(1000);
    producer.produce("baz", endpoint);

    System.out.println("-- END --");
  }
}



2013/9/4 Cristiano Costantini <cr...@gmail.com>

> Hi All,
>
> I've switched and endpoint using seda: with options multipleConsumers=true
> and waitForTaskToComplete=Never to using vm: component.
>
> After this, the application does not respect anymore the
> multipleConsumers=true options and two concurrent consumer steal the
> message.
>
> I may have other issue which I'm going to investigate, but to avoid waste
> time I please ask you if I'm missing some detail by switching from seda: to
> vm: (it is the first time I use vm: and I was expecting the same behavior
> of the seda:endpoint)
>
> I'm using Camel 2.10.6 inside Servicemix 4.5.2.
>
> Thank you very much!
>
> Cristiano
>