You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Hendy Irawan <he...@soluvas.com> on 2009/12/05 10:31:08 UTC

Implementing Publish Subscribe Channel

Hi,

I was trying to make a publish-subscribe mechanism by using (only)
@EndpointInject and @Consume, so that I can have somewhat POJO style routing
with minimal XML configuration.

It turned out that this didn't work because multiple consumers don't work
with this setup.

After reading http://camel.apache.org/publish-subscribe-channel.html it
seems that there are only three ways Camel supports Publish Subscribe:
1. JMS Topic
2. XMPP Room
3. Explicit routes via multicast

Option 1 and 2 is overkill because it requires external server.

So the functionality is basically there in Camel (option 3), however, I
cannot do it dynamically because it involves explicitly setting up the
routes, instead of doing it dynamically via @Consume.

Spring Integration seem to support this by allowing to create a
PublishSubscribeChannel explicitly.

Is it planned to support easy "dynamic" Publish Subscribe Channel via
annotations (i.e. without explicit configuration)? Thank you.
-- 
View this message in context: http://old.nabble.com/Implementing-Publish-Subscribe-Channel-tp26654086p26654086.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Implementing Publish Subscribe Channel

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Dec 16, 2009 at 2:29 PM, Hendy Irawan <he...@soluvas.com> wrote:
>
>
> Claus Ibsen-2 wrote:
>>
>> I got some time today and have implemented this feature. See the
>> ticket and wiki page for details.
>
> Thank you VERY much Dr. Claus.. Exactly what the patient asked :-)

You are welcome, its a good new feature for Camel. Just keep us on the
toes in case the patient needs to visit the doctor again :)

> --
> View this message in context: http://old.nabble.com/Implementing-Publish-Subscribe-Channel-tp26654086p26811032.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

Re: Implementing Publish Subscribe Channel

Posted by Hendy Irawan <he...@soluvas.com>.

Claus Ibsen-2 wrote:
> 
> I got some time today and have implemented this feature. See the
> ticket and wiki page for details.

Thank you VERY much Dr. Claus.. Exactly what the patient asked :-)
-- 
View this message in context: http://old.nabble.com/Implementing-Publish-Subscribe-Channel-tp26654086p26811032.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Implementing Publish Subscribe Channel

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

I got some time today and have implemented this feature. See the
ticket and wiki page for details.


On Wed, Dec 9, 2009 at 1:22 PM, Hendy Irawan <he...@soluvas.com> wrote:
>
> Hi Claus,
>
>
> Claus Ibsen-2 wrote:
>>
>> Hi Hendry
>>
>> I am a bit busy over the next week or so, due to new book deadline and
>> a other engagements.
>>
>> However I haven't forgotten about this use-case and I think we can
>> improve the seda component
>> to let it support multiple consumers by sending a copy of the exchange
>> to each recipient.
>>
>> Then you should be able to use it as a event broadcaster kinda thingy.
>>
>> Fell free to create a ticket in JIRA
>>
>
> I've made an improvement request in JIRA:
> https://issues.apache.org/activemq/browse/CAMEL-2272
>
> I wish I could implement it myself. I'm not too familiar with Camel
> internals.
>
> I tried contributing cometd client for Camel yet I'm blocked with a strange
> consumer implementation issue:
> http://old.nabble.com/cometd-client-connector-for-Camel-to26635861.html#a26674507
>
> Not really sure what I'm doing wrong.
> --
> View this message in context: http://old.nabble.com/Implementing-Publish-Subscribe-Channel-tp26654086p26709358.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

Re: Implementing Publish Subscribe Channel

Posted by Hendy Irawan <he...@soluvas.com>.
Hi Claus,


Claus Ibsen-2 wrote:
> 
> Hi Hendry
> 
> I am a bit busy over the next week or so, due to new book deadline and
> a other engagements.
> 
> However I haven't forgotten about this use-case and I think we can
> improve the seda component
> to let it support multiple consumers by sending a copy of the exchange
> to each recipient.
> 
> Then you should be able to use it as a event broadcaster kinda thingy.
> 
> Fell free to create a ticket in JIRA
> 

I've made an improvement request in JIRA:
https://issues.apache.org/activemq/browse/CAMEL-2272

I wish I could implement it myself. I'm not too familiar with Camel
internals.

I tried contributing cometd client for Camel yet I'm blocked with a strange
consumer implementation issue:
http://old.nabble.com/cometd-client-connector-for-Camel-to26635861.html#a26674507

Not really sure what I'm doing wrong.
-- 
View this message in context: http://old.nabble.com/Implementing-Publish-Subscribe-Channel-tp26654086p26709358.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Implementing Publish Subscribe Channel

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

I am a bit busy over the next week or so, due to new book deadline and
a other engagements.

However I haven't forgotten about this use-case and I think we can
improve the seda component
to let it support multiple consumers by sending a copy of the exchange
to each recipient.

Then you should be able to use it as a event broadcaster kinda thingy.

Fell free to create a ticket in JIRA



On Sun, Dec 6, 2009 at 6:50 PM, Hendy Irawan <he...@soluvas.com> wrote:
>
> Hi Claus,
>
>
> Claus Ibsen-2 wrote:
>>
>> No seda does *not* support multiple consumers. Its meant to be used
>> with a single consumer only.
>> In 2.1 this is even enforced. Often end users had copy paste mistakes
>> and didnt want multiple consumers to the same seda endpoint.
>> Hence why we enforced this now in 2.1.
>>
>> What is your use case sine you need this? I am interesting in what you
>> are trying to solve?
>>
>>
>> What you could do is to extend seda, and have support multiple
>> consumers and have the Exchange being copied before its handed out to
>> every
>> consumers.
>>
>> Mind that when you copy the Exchange / Message if the body is not a
>> simple type such as String then you may only copy a reference to it
>> and thus have multiple consumers work on it concurrently, and thus you
>> need to be aware of thread safety issues.
>>
>> And there is a new interface in Camel 2.1, MultipleConsumersSupport,
>> which indicates whether an endpoint supports multiple consumers or
>> not.
>> You need to implement this and return true in your own component.
>>
>
> I'm not sure if a separate component is needed for this, because from my
> experience the <multicast> element works fine. And that's what I'm trying to
> get, using the <multicast> functionality in a @Consume'r.
>
> Maybe something like this (proposal):
>
> @Consume(uri="someuri", multicast=true)
>
> My use case is using Camel as event publisher. Exactly like Spring
> Application Events.
>
> @EndpointInject(uri="seda:events.form")
> ProducerTemplate formEvents;
>
> ...
> formEvents.sendBody(new FormEvent(...));
> ...
>
> then there are one or more event Listeners like this:
>
> @Consume(uri="seda:events.form")
> public void handleFormEvent(FormEvent event) { ... }
>
> BTW, the producer and consumer URI may not be the same. i.e. the publisher
> of the event may route it in some way and there may be multiple producers.
> However as far as consumers are concerned, they have this inbox URI (e.g.
> "seda:events.form") that all events will come together. Then multiple
> consumers can process the messages (it's InOnly, no need to reply).
>
> I can do this with <multicast>, but my "problem" is that I want it to be
> "dynamic" i.e. just @Consume annotation is needed, no change in routes.
> Because the consumers can be created and disposed dynamically.
> --
> View this message in context: http://old.nabble.com/Implementing-Publish-Subscribe-Channel-tp26654086p26667205.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

Re: Implementing Publish Subscribe Channel

Posted by Hendy Irawan <he...@soluvas.com>.
Hi Claus,


Claus Ibsen-2 wrote:
> 
> No seda does *not* support multiple consumers. Its meant to be used
> with a single consumer only.
> In 2.1 this is even enforced. Often end users had copy paste mistakes
> and didnt want multiple consumers to the same seda endpoint.
> Hence why we enforced this now in 2.1.
> 
> What is your use case sine you need this? I am interesting in what you
> are trying to solve?
> 
> 
> What you could do is to extend seda, and have support multiple
> consumers and have the Exchange being copied before its handed out to
> every
> consumers.
> 
> Mind that when you copy the Exchange / Message if the body is not a
> simple type such as String then you may only copy a reference to it
> and thus have multiple consumers work on it concurrently, and thus you
> need to be aware of thread safety issues.
> 
> And there is a new interface in Camel 2.1, MultipleConsumersSupport,
> which indicates whether an endpoint supports multiple consumers or
> not.
> You need to implement this and return true in your own component.
> 

I'm not sure if a separate component is needed for this, because from my
experience the <multicast> element works fine. And that's what I'm trying to
get, using the <multicast> functionality in a @Consume'r.

Maybe something like this (proposal):

@Consume(uri="someuri", multicast=true)

My use case is using Camel as event publisher. Exactly like Spring
Application Events.

@EndpointInject(uri="seda:events.form")
ProducerTemplate formEvents;

...
formEvents.sendBody(new FormEvent(...));
...

then there are one or more event Listeners like this:

@Consume(uri="seda:events.form")
public void handleFormEvent(FormEvent event) { ... }

BTW, the producer and consumer URI may not be the same. i.e. the publisher
of the event may route it in some way and there may be multiple producers.
However as far as consumers are concerned, they have this inbox URI (e.g.
"seda:events.form") that all events will come together. Then multiple
consumers can process the messages (it's InOnly, no need to reply).

I can do this with <multicast>, but my "problem" is that I want it to be
"dynamic" i.e. just @Consume annotation is needed, no change in routes.
Because the consumers can be created and disposed dynamically.
-- 
View this message in context: http://old.nabble.com/Implementing-Publish-Subscribe-Channel-tp26654086p26667205.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Implementing Publish Subscribe Channel

Posted by Claus Ibsen <cl...@gmail.com>.
On Sun, Dec 6, 2009 at 4:51 PM, Hendy Irawan <he...@soluvas.com> wrote:
>
>
>
> Claus Ibsen-2 wrote:
>>
>> Maybe spring event can be used also?
>> http://camel.apache.org/event.html
>>
>
> I guess that'd mean my message has to be an ApplicationEvent.
>

Dont know if Spring enforces to implement an interface but I would
envision they did.


>
> Claus Ibsen-2 wrote:
>>
>> You can create you own component that offers topic like functionally.
>> You could extend the seda or direct component and implement the logic
>> missing.
>>
>
> Thanks for the encouragement. :-)
>
>
> Claus Ibsen-2 wrote:
>>
>> I would assume adding @Consume to any POJO does not require any routes
>> to pre existing and cannot see why its not dynamic.
>>
>
> Yes indeed, unfortunately @Consume breaks when there are two @Consume'rs on
> the same endpoint that is not a publish-subscribe channel. It seems like
> it's doing round-robin (?) instead of multicast.
>
> For example, I'd like:
>
> /* bean1 */
> @Consume("seda:mychannel") public void Yeeha(String msg) { }
> /* bean2 */
> @Consume("seda:mychannel") public void Yaahi(String msg) { }
>
> to behave as if an explicit route is specified (with multicast):
>
> <from uri="seda:channel">
> <multicast>
>  <to uri="bean:bean1" />
>  <to uri="bean:bean2" />
> </multicast>
> </from>
>
> but right now, it seems messages are being routed round-robin when using the
> @Consumer. That's why I said doing multicast dynamically (with @Consume)
> seem to be not possible.
>

No seda does *not* support multiple consumers. Its meant to be used
with a single consumer only.
In 2.1 this is even enforced. Often end users had copy paste mistakes
and didnt want multiple consumers to the same seda endpoint.
Hence why we enforced this now in 2.1.

What is your use case sine you need this? I am interesting in what you
are trying to solve?


What you could do is to extend seda, and have support multiple
consumers and have the Exchange being copied before its handed out to
every
consumers.

Mind that when you copy the Exchange / Message if the body is not a
simple type such as String then you may only copy a reference to it
and thus have multiple consumers work on it concurrently, and thus you
need to be aware of thread safety issues.

And there is a new interface in Camel 2.1, MultipleConsumersSupport,
which indicates whether an endpoint supports multiple consumers or
not.
You need to implement this and return true in your own component.




> Thank you.
> --
> View this message in context: http://old.nabble.com/Implementing-Publish-Subscribe-Channel-tp26654086p26666101.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

Re: Implementing Publish Subscribe Channel

Posted by Hendy Irawan <he...@soluvas.com>.


Claus Ibsen-2 wrote:
> 
> Maybe spring event can be used also?
> http://camel.apache.org/event.html
> 

I guess that'd mean my message has to be an ApplicationEvent.


Claus Ibsen-2 wrote:
> 
> You can create you own component that offers topic like functionally.
> You could extend the seda or direct component and implement the logic
> missing.
> 

Thanks for the encouragement. :-)


Claus Ibsen-2 wrote:
> 
> I would assume adding @Consume to any POJO does not require any routes
> to pre existing and cannot see why its not dynamic.
> 

Yes indeed, unfortunately @Consume breaks when there are two @Consume'rs on
the same endpoint that is not a publish-subscribe channel. It seems like
it's doing round-robin (?) instead of multicast.

For example, I'd like:

/* bean1 */
@Consume("seda:mychannel") public void Yeeha(String msg) { }
/* bean2 */
@Consume("seda:mychannel") public void Yaahi(String msg) { }

to behave as if an explicit route is specified (with multicast):

<from uri="seda:channel">
<multicast>
  <to uri="bean:bean1" />
  <to uri="bean:bean2" />
</multicast>
</from>

but right now, it seems messages are being routed round-robin when using the
@Consumer. That's why I said doing multicast dynamically (with @Consume)
seem to be not possible.

Thank you.
-- 
View this message in context: http://old.nabble.com/Implementing-Publish-Subscribe-Channel-tp26654086p26666101.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Implementing Publish Subscribe Channel

Posted by Claus Ibsen <cl...@gmail.com>.
On Sat, Dec 5, 2009 at 10:31 AM, Hendy Irawan <he...@soluvas.com> wrote:
>
> Hi,
>
> I was trying to make a publish-subscribe mechanism by using (only)
> @EndpointInject and @Consume, so that I can have somewhat POJO style routing
> with minimal XML configuration.
>
> It turned out that this didn't work because multiple consumers don't work
> with this setup.
>
> After reading http://camel.apache.org/publish-subscribe-channel.html it
> seems that there are only three ways Camel supports Publish Subscribe:
> 1. JMS Topic
> 2. XMPP Room
> 3. Explicit routes via multicast
>
> Option 1 and 2 is overkill because it requires external server.
>

Maybe spring event can be used also?
http://camel.apache.org/event.html


> So the functionality is basically there in Camel (option 3), however, I
> cannot do it dynamically because it involves explicitly setting up the
> routes, instead of doing it dynamically via @Consume.
>

You can create you own component that offers topic like functionally.
You could extend the seda or direct component and implement the logic
missing.


> Spring Integration seem to support this by allowing to create a
> PublishSubscribeChannel explicitly.
>
> Is it planned to support easy "dynamic" Publish Subscribe Channel via
> annotations (i.e. without explicit configuration)? Thank you.

I would assume adding @Consume to any POJO does not require any routes
to pre existing and cannot see why its not dynamic.


Why dont you create a small sample what you want as its easier to
discuss based on that.

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

Just see Camel 2.1 which have 5 or so new components all contributed by others.


> --
> View this message in context: http://old.nabble.com/Implementing-Publish-Subscribe-Channel-tp26654086p26654086.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