...
Whenever an event is published into the channel, it will deliver a copy of the message to each of the output channels. Additionally, each output channel will have only one subscriber and that subscriber is only allowed to consume the message once. In this scenario, each of the subscribers gets the message once, and the consumed copies will automatically disappear from their channels.
Components that support publish-subscribe channel
The following Apache Camel components support the publish-subscribe channel pattern:
JMS
ActiveMQ
SEDA
XMPP
JMS Publish-Subscribe
In JMS, a publish-subscribe channel is represented by a topic. For example, you can specify the endpoint URI for a JMS topic called StockQuotes
as follows:
Code Block |
---|
jms:topic:StockQuotes |
ActiveMQ
In ActiveMQ, a publish-subscribe channel is represented by a topic. For example, you can specify the endpoint URI for an ActiveMQ topic called StockQuotes
, as follows:
Code Block |
---|
activemq:topic:StockQuotes |
Static Subscription Lists
We can also implement publish-subscribe logic within the Apache Camel application, and a simple approach is to define a static subscription list. This is where the target endpoints are all explicitly listed at the end of the route. The following example shows how to simulate a publish-subscribe channel with a single publisher, seda:a
, and three subscribers, seda:b
, seda:c
, and seda:d
:
...