此内容没有您所选择的语言版本。

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.
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat