이 콘텐츠는 선택한 언어로 제공되지 않습니다.

4.6.3. Subscribe to the Default Exchange


To subscribe to the Default Exchange, create a receiver and pass the name of the queue to the constructor. For example, to subscribe to the queue "quick-publish", using the Python API:
C++
Receiver receiver = session.createReceiver('quick-publish');
Copy to Clipboard Toggle word wrap
Python
receiver = session.receiver('quick-publish')
Copy to Clipboard Toggle word wrap
This receiver can now be used to retrieve messages from the quick-publish queue.
To obtain a browse-only view that does not remove messages from the queue:
C++
Receiver receiver = session.createReceiver('quick-publish; {mode: browse}');
Copy to Clipboard Toggle word wrap
Python
receiver = session.receiver('quick-publish; {mode: browse}')
Copy to Clipboard Toggle word wrap
If you want to create and subscribe a queue that does not yet exist, for example for your application to request its own copies of messages, use the create parameter:
C++
Receiver receiver = session.createReceiver("my-own-copies-please; {create: always, node: {type: 'queue'}}");
Copy to Clipboard Toggle word wrap
Python
receiver = session.receiver("my-own-copies-please; {create: always, node: {type: 'queue'}}")
Copy to Clipboard Toggle word wrap
If the queue "my-own-copies-please" already exists, then your receiver will connect to that queue. If the queue does not exist, then it will be created (all of this assumes sufficient privileges, of course).
One thing to bear in mind is that if an exchange named "my-own-copies-please" exists, your receiver will silently connect to that in preference to creating a queue. This is not what you intended, and will have unpredictable results. To avoid this, you can use the assert parameter, like this:
C++
try {
  Receiver receiver = session.createReceiver("my-own-copies-please; {create: always, assert: always, node: {type: 'queue'}}");
} catch(const std::exception& error) {
  std::cerr << error.what() << std::endl;
}
Copy to Clipboard Toggle word wrap
Python
try:
  receiver = session.receiver("my-own-copies-please; {create: always, assert: always, node: {type: 'queue'}}")
except MessagingError m:
  print m
Copy to Clipboard Toggle word wrap
Now if "my-own-copies-please" already exists and is an exchange, the receiver constructor will raise an exception: "expected queue, got topic".
Note that although it is an instance of a Direct Exchange, the Default Exchange does not allow multiple bindings using the same key. Each queue is bound to the Default Exchange uniquely. This means that you can only connect to a queue to get messages sent to it; you cannot bind another queue to the exchange in parallel to receive copies of the messages, as you can with other Direct Exchanges.
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat