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

4.7.3. Create a Direct Exchange from an application


You can create a Direct Exchange in an application as a side effect of creating a sender or a receiver. For example, the following example creates a direct exchange called engineering:
Python
sender = session.sender('engineering;{create: always, node:{type:topic, x-declare:{type:direct}}}')
Copy to Clipboard Toggle word wrap
In the case where an exchange named engineering already exists, the sender will not try to create a new one, but will connect to the existing one. You need to be careful, however, because if a queue with the name engineering already exists, then your sender will silently connect to that queue.
To ensure that your sender will connect to a new or existing exchange called engineering, you can use assert, as in this example:
Python
try:
  sender = session.sender('engineering;{create: always, node:{type:topic, x-declare:{type:direct}}, assert: always}')
except MessagingError, m:
  print m
Copy to Clipboard Toggle word wrap
When you use assert: always, node: {type: topic}; if engineering exists and is a queue, rather than an exchange, the sender constructor will raise an exception: "expected topic, got queue".
Note that while you can use assert to verify that it is an exchange and not a queue, you cannot verify what type of exchange it is.
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