Creating and Using a Custom Subscription¶
Advanced Feature
Custom subscriptions are intended for advanced users with specific requirements. They do not support header-based server-side filtering or retrieving past messages. Please read the getting started guide for more information on choosing the right subscription type.
In this guide, we will walk through setting using a dedicated subscription and consuming messages from it.
Prerequisites¶
Before starting, ensure you meet the following requirements:
- A basic understanding of the AMQP 1.0 protocol.
- Registration for the SWIM service at DWD. If you are not registered, please contact vl.kundenservice@dwd.de.
Step 1: Requesting a Subscription¶
Since there is no online subscription management interface available, you will need to contact vl.kundenservice@dwd.de to request a subscription. After processing your request, you will receive the subscription and connection details from DWD. The subscription is unique and will only be readable by the user it was created for.
Subscription States¶
- PAUSED: The default state for a new data queue. In this state, you will only receive technical and heartbeat messages.
- ACTIVE: Once activated by contacting DWD, data messages will be delivered.
You can also pause data delivery at any time by emailing DWD to set the queue state back to PAUSED.
Example Subscription Name¶
Your subscription name will have the following format:
For example:swim_user.weather.aviation.metar.4b9506ea-2f7c-4958-a01c-d85b13ac5f2e
Step 2: Receiving Your First Message¶
We will guide you through consuming your first message using Python. Although this example is Python-specific, the concepts apply to other AMQP 1.0 compatible libraries.
Setting Up Your Environment¶
-
Setup Python (if not already done):
Please refer to the official docs to setup python. We recommend setting up a virtual environment for this example, too.
-
Install the Qpid Proton Library:
Note: Version
0.40.0was used for this tutorial. While newer versions may work, using this version ensures compatibility with this how-to.
Connecting to the Broker¶
Replace the placeholders with your connection details:
from proton import ProtonException
from proton.utils import BlockingConnection
conn = BlockingConnection(
"amqps://swimt.dwd.de",
user="swim_user",
password="your_password"
)
Creating a Receiver and Fetching Messages¶
-
Create a receiver using your subscription name:
receiver = conn.create_receiver( "/queues/swim_user.weather.aviation.metar." "4b9506ea-2f7c-4958-a01c-d85b13ac5f2e" )Note: The
/queues/prefix is required when talking to RabbitMQ. It cleanly separates names in different endpoints, e.g., from anexchangeof the same name. -
Receive the first message:
Displaying the Message Content¶
Decode and print the message body using json:
Optional: Acknowledging the Message¶
To acknowledge and remove the message from the queue:
Skip this step if you want to keep the message in the queue.
Closing the Connection¶
After processing, close the connection to the broker:
Congratulations!¶
You have successfully received your first SWIM message!
Next Steps¶
- Implement a consumer loop.
For further assistance, contact swim.service@dwd.de.