Este conteúdo não está disponível no idioma selecionado.

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.
Voltar ao topo
Red Hat logoGithubredditYoutubeTwitter

Aprender

Experimente, compre e venda

Comunidades

Sobre a documentação da Red Hat

Ajudamos os usuários da Red Hat a inovar e atingir seus objetivos com nossos produtos e serviços com conteúdo em que podem confiar. Explore nossas atualizações recentes.

Tornando o open source mais inclusivo

A Red Hat está comprometida em substituir a linguagem problemática em nosso código, documentação e propriedades da web. Para mais detalhes veja o Blog da Red Hat.

Sobre a Red Hat

Fornecemos soluções robustas que facilitam o trabalho das empresas em plataformas e ambientes, desde o data center principal até a borda da rede.

Theme

© 2025 Red Hat