• CLI

sdk
  1. Help Center
  2. CLI
  3. Developer Guide
  4. SDK
  5. Python
  6. DMS Python SDK Demo

DMS Python SDK Demo

Distributed Message Service (DMS) is a message middleware service based on distributed, high-availability clustering technology. It provides reliable, scalable, fully managed queues for storing messages. DMS enables cloud applications to decouple from each other, achieving high cost-effectiveness.

Creating a Queue

You can create a queue using the Python OpenStack SDK based on the following code. After the queue is created, messages will be sent to this queue.

queue_dict = {
                'name': "dmsTestQueue" + self.timeStamp,
                'description': "dmsTestQueue" + self.timeStamp
}
q = conn.dms.create_queue(**queue_dict)

Creating a Consumer Group

You can create a consumer group using the Python OpenStack SDK based on the following code. After the consumer group is created, it can consume messages in the queue.

groupDict = {
            "groups": [
                {
                    "name": "dmsConsumeGroup" + self.timeStamp
                }
            ]
 }
group = conn.dms.create_groups(queue, **groupDict)

Producing Messages

You can produce messages using the Python OpenStack SDK based on the following code:

msgDict = {
            "messages": [
                {
                    "body": "testMsg" + self.timeStamp,
                    "attributes":
                    {
                        "attribute1": "value1",
                        "attribute2": "value2"
                    }
                }
            ]
 }
conn.dms.send_messages(queue, **msgDict))

Consume Messages

You can consume messages using the Python OpenStack SDK based on the following code:

msgList =  conn.dms.consume_message(queue, group[0].id)