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.
1 2 3 4 5 |
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.
1 2 3 4 5 6 7 8 |
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
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:
1 |
msgList = conn.dms.consume_message(queue, group[0].id)
|
Last Article: Anti-DDoS Python SDK Demo
Next Article: MRS Python SDK Demo
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.