Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.

4.9.6. Subscribe to a Topic Exchange


To subscribe to topic exchange, create a queue and bind it to the exchange with the desired routing key.
The following example uses qpid-config to create a queue named news and bind it to the amq.topic exchange with a wildcard that matches everything.news, where everything is any number of period-separated terms:
qpid-config add queue news
qpid-config bind amq.topic news "#.news"
Copy to Clipboard Toggle word wrap
Now you can listen to the news queue for all messages whose routing key ends with .news:
Python
rxnews = ssn.receiver("news")
Copy to Clipboard Toggle word wrap
You can also do the entire operation (create, bind, and listen) in code, by using an address like the one in the following example:
AMQP 0-10

Python
rxnews = ssn.receiver("news;{create: always, node: {type:queue}, link:{x-bindings:[{exchange: 'amq.topic', queue: 'news', key: '#.news'}]}}")
Copy to Clipboard Toggle word wrap

AMQP 1.0

C++
Receiver rxnews = ssn.createReceiver("amq.topic/#.news;{node:{capabilities:[shared]}, link:{name: 'news'}}");
Copy to Clipboard Toggle word wrap

You could also create an ephemeral subscription for your application, if you do not care about queuing messages when your application is disconnected or sharing responsibility for messages. This method creates and binds a temporary private queue for your application:
Python
rxnews = ssn.receiver("amq.topic/#.news");
Copy to Clipboard Toggle word wrap
In topic exchange binding key wildcard matching, the # symbol will match any number of period-separated terms. The # will match exactly one term.
Nach oben
Red Hat logoGithubredditYoutubeTwitter

Lernen

Testen, kaufen und verkaufen

Communitys

Über Red Hat Dokumentation

Wir helfen Red Hat Benutzern, mit unseren Produkten und Diensten innovativ zu sein und ihre Ziele zu erreichen – mit Inhalten, denen sie vertrauen können. Entdecken Sie unsere neuesten Updates.

Mehr Inklusion in Open Source

Red Hat hat sich verpflichtet, problematische Sprache in unserem Code, unserer Dokumentation und unseren Web-Eigenschaften zu ersetzen. Weitere Einzelheiten finden Sie in Red Hat Blog.

Über Red Hat

Wir liefern gehärtete Lösungen, die es Unternehmen leichter machen, plattform- und umgebungsübergreifend zu arbeiten, vom zentralen Rechenzentrum bis zum Netzwerkrand.

Theme

© 2025 Red Hat