Questo contenuto non è disponibile nella lingua selezionata.
4.8.6. Subscribe to a Fanout Exchange
- Subscribe to the exchange using an ephemeral subscription. This creates and binds a temporary private queue that is destroyed when your application disconnects. This approach makes sense when you do not need to share responsibility for the messages between multiple consumers, and you do not care about messages that are sent when your application is not running or is disconnected.
- Subscribe to a queue that is bound to the exchange. This allows messages to be buffered in the queue when your application is disconnected, and allows several consumers to share responsibility for the messages in the queue.
To implement the private, ephemeral subscription, create a receiver using the name of the fanout exchange as the receiver's address. For example:
- Python
rx = receiver("amq.fanout")
rx = receiver("amq.fanout")
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
To implement a shareable subscription that persists across consumer application restarts, create a queue, and subscribe to that queue.
qpid-config
:
qpid-config add queue shared-q qpid-config bind amq.fanout shared-q
qpid-config add queue shared-q
qpid-config bind amq.fanout shared-q
--durable
option.
qpid-config
command to view the exchange bindings after issuing these commands. On MRG Messaging 2.2 and below use the command qpid-config exchanges -b
. On MRG Messaging 2.3 and above use the command qpid-config exchanges -r
.
- Python
rx = receiver("shared-q")
rx = receiver("shared-q")
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
qpid-config
:
- Python
rx = receiver("shared-q;{create: always, link: {x-bindings: [{exchange: 'amq.fanout', queue: 'shared-q'}]}}")
rx = receiver("shared-q;{create: always, link: {x-bindings: [{exchange: 'amq.fanout', queue: 'shared-q'}]}}")
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
- C++
Receiver receiver = session.createReceiver("amq.fanout;{node: {capabilities:[shared]}, link: {name: 'shared-q'}}");
Receiver receiver = session.createReceiver("amq.fanout;{node: {capabilities:[shared]}, link: {name: 'shared-q'}}");
Copy to Clipboard Copied! Toggle word wrap Toggle overflow