Skip to content

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:


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:

<user>.<service>.<uuid>
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

  1. 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.

  2. Install the Qpid Proton Library:

    pip install python-qpid-proton==0.40.0
    

    Note: Version 0.40.0 was 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

  1. 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 an exchange of the same name.

  2. Receive the first message:

    msg = receiver.receive(timeout=10)
    

Displaying the Message Content

Decode and print the message body using json:

import json

print(json.loads(msg.body.tobytes().decode("utf-8")))

Optional: Acknowledging the Message

To acknowledge and remove the message from the queue:

receiver.accept()

Skip this step if you want to keep the message in the queue.

Closing the Connection

After processing, close the connection to the broker:

conn.close()

Congratulations!

You have successfully received your first SWIM message!

Next Steps

For further assistance, contact swim.service@dwd.de.