Questo contenuto non è disponibile nella lingua selezionata.

4.8.6. Subscribe to a Fanout Exchange


When subscribing to a fanout exchange you have two options:
  1. 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.
  2. 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.
Private, ephemeral subscription

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")
Copy to Clipboard Toggle word wrap
Shareable subscription

To implement a shareable subscription that persists across consumer application restarts, create a queue, and subscribe to that queue.

You can create and bind the queue using qpid-config:
qpid-config add queue shared-q 
qpid-config bind amq.fanout shared-q
Copy to Clipboard Toggle word wrap
Note: To make the queue persistent across broker restarts, use the --durable option.
Use the 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.
Once you have created and bound the queue, in your application create a receiver that listens to this queue:
Python
rx = receiver("shared-q")
Copy to Clipboard Toggle word wrap
You could also create and bind the queue in the application code, rather than using qpid-config:
AMQP 0-10

Python
rx = receiver("shared-q;{create: always, link: {x-bindings: [{exchange: 'amq.fanout', queue: 'shared-q'}]}}")
Copy to Clipboard Toggle word wrap

AMQP 1.0

C++
Receiver receiver = session.createReceiver("amq.fanout;{node: {capabilities:[shared]}, link: {name: 'shared-q'}}");
Copy to Clipboard Toggle word wrap

Torna in cima
Red Hat logoGithubredditYoutubeTwitter

Formazione

Prova, acquista e vendi

Community

Informazioni sulla documentazione di Red Hat

Aiutiamo gli utenti Red Hat a innovarsi e raggiungere i propri obiettivi con i nostri prodotti e servizi grazie a contenuti di cui possono fidarsi. Esplora i nostri ultimi aggiornamenti.

Rendiamo l’open source più inclusivo

Red Hat si impegna a sostituire il linguaggio problematico nel codice, nella documentazione e nelle proprietà web. Per maggiori dettagli, visita il Blog di Red Hat.

Informazioni su Red Hat

Forniamo soluzioni consolidate che rendono più semplice per le aziende lavorare su piattaforme e ambienti diversi, dal datacenter centrale all'edge della rete.

Theme

© 2025 Red Hat