Skip to content

Commit 51d2f76

Browse files
DMS Examples & Docu (#156)
DMS Examples & Docu closes #155 Reviewed-by: Tino Schr <None> Reviewed-by: None <None>
1 parent a258cc0 commit 51d2f76

28 files changed

+963
-1
lines changed

doc/source/sdk/guides/cce.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ or name.
5454
Delete CCE Cluster
5555
^^^^^^^^^^^^^^^^^^
5656

57-
This interface is used to get a CCE cluster by ID
57+
This interface is used to delete a CCE cluster by ID
5858
or an instance of class
5959
:class:`~otcextensions.sdk.cce.v3.cluster.Cluster`.
6060

doc/source/sdk/guides/dms.rst

Lines changed: 312 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,312 @@
1+
Distributed Message Service (DMS)
2+
=================================
3+
4+
.. contents:: Table of Contents
5+
:local:
6+
7+
DMS is a fully-managed, high-performance message queuing service that
8+
supports normal queues, first-in-first-out (FIFO) queues,
9+
Kafka queues, and Kafka premium instances.
10+
It is compatible with HTTP and TCP, and provides a flexible
11+
and reliable asynchronous communication mechanism
12+
for distributed applications.
13+
Normal and FIFO queues feature low-latency and high reliability.
14+
They support dead letter messages for handling exceptions.
15+
In normal queues, partitions ensure higher concurrency.
16+
Kafka queues support high-throughput and high-reliability modes.
17+
A Kafka queue is equivalent to a topic. The storage space and
18+
network bandwidth resources are allocated by the system,
19+
without requiring you to make choices.
20+
Kafka premium instances use physically isolated computing,
21+
storage, and bandwidth resources.
22+
You can customize partitions and replicas for Kafka topics in the instances,
23+
and configure the network bandwidth as required.
24+
The instances can be used right out of the box,
25+
taking off the deployment and O&M pressure for you
26+
so that you can focus on developing your services.
27+
28+
DMS Queues
29+
----------
30+
31+
A message queue is a container that receives and stores message files.
32+
By default, 5 queues can be created under a project.
33+
Different messages in one queue can be retrieved
34+
by multiple consumers at the same time.
35+
36+
List Queues
37+
^^^^^^^^^^^
38+
39+
This interface is used to query all DMS Queues and to filter
40+
the output with query parameters.
41+
42+
.. literalinclude:: ../examples/dms/list_queues.py
43+
:lines: 16-22
44+
45+
Create Queue
46+
^^^^^^^^^^^^
47+
48+
This interface is used to create a Queue with
49+
parameters.
50+
51+
.. literalinclude:: ../examples/dms/create_queue.py
52+
:lines: 16-27
53+
54+
Get Queue
55+
^^^^^^^^^
56+
57+
This interface is used to get a Queue by ID
58+
or an instance of class
59+
:class:`~otcextensions.sdk.dms.v1.queue.Queue`.
60+
61+
.. literalinclude:: ../examples/dms/get_queue.py
62+
:lines: 16-23
63+
64+
Find Queue
65+
^^^^^^^^^^
66+
67+
This interface is used to find a Queue by ID
68+
or name.
69+
70+
.. literalinclude:: ../examples/dms/find_queue.py
71+
:lines: 16-23
72+
73+
Delete Queue
74+
^^^^^^^^^^^^
75+
76+
This interface is used to delete a Queue by ID
77+
or an instance of class
78+
:class:`~otcextensions.sdk.dms.v1.queue.Queue`.
79+
80+
.. literalinclude:: ../examples/dms/delete_queue.py
81+
:lines: 16-23
82+
83+
DMS Queue Groups
84+
----------------
85+
86+
A consumer group is used to group consumers.
87+
A maximum of three consumer groups can be created in each queue.
88+
Messages in one queue can be retrieved once by each consumer group.
89+
Messages acknowledged by one consumer group are no longer available
90+
to that consumer group but still available to other consumer groups.
91+
Consumers in the same consumer group can retrieve
92+
different messages from one queue at the same time.
93+
94+
List Queue Groups
95+
^^^^^^^^^^^^^^^^^
96+
97+
This interface is used to query all groups of a Queue
98+
and to filter the output with query parameters.
99+
100+
.. literalinclude:: ../examples/dms/list_queue_groups.py
101+
:lines: 16-23
102+
103+
Create Queue Group
104+
^^^^^^^^^^^^^^^^^^
105+
106+
This interface is used to create a Queue Group with
107+
parameters.
108+
109+
.. literalinclude:: ../examples/dms/create_queue_group.py
110+
:lines: 16-26
111+
112+
Find Queue Group
113+
^^^^^^^^^^^^^^^^
114+
115+
This interface is used to find a Queue Group by ID
116+
or name.
117+
118+
.. literalinclude:: ../examples/dms/find_queue_group.py
119+
:lines: 16-25
120+
121+
Delete Queue Group
122+
^^^^^^^^^^^^^^^^^^
123+
124+
This interface is used to delete a Queue Group by ID
125+
or an instance of class
126+
:class:`~otcextensions.sdk.dms.v1.group.Group`.
127+
128+
.. literalinclude:: ../examples/cce/delete_cluster_node.py
129+
:lines: 16-25
130+
131+
DMS messages
132+
------------
133+
134+
Messages are JavaScript object notation (JSON) objects
135+
used for transmitting information.
136+
They can be sent one by one or in batches.
137+
Sending messages in batches can be achieved only
138+
through calling DMS application programming interfaces (APIs).
139+
140+
Send message
141+
^^^^^^^^^^^^
142+
143+
This interface is used to send a message with
144+
parameters.
145+
146+
.. literalinclude:: ../examples/dms/send_messages.py
147+
:lines: 16-42
148+
149+
Consume message
150+
^^^^^^^^^^^^^^^
151+
152+
This interface is used to consume a queue's message by Queue- and Group-ID
153+
or an instance of class
154+
:class:`~otcextensions.sdk.dms.v1.queue.Queue`
155+
and
156+
:class:`~otcextensions.sdk.dms.v1.group.Group`.
157+
158+
.. literalinclude:: ../examples/dms/consume_message.py
159+
:lines: 16-26
160+
161+
Confirm message
162+
^^^^^^^^^^^^^^^
163+
164+
This interface is used to confirm consumed messages by a list of
165+
class
166+
:class:`~otcextensions.sdk.dms.v1.message.Messages`.
167+
168+
.. literalinclude:: ../examples/dms/confirm_message.py
169+
:lines: 16-38
170+
171+
DMS Instances
172+
-------------
173+
174+
Kafka premium instances use physically isolated computing,
175+
storage, and bandwidth resources.
176+
You can customize partitions and replicas
177+
for Kafka topics in the instances,
178+
and configure the network bandwidth as required.
179+
The instances can be used right out of the box,
180+
taking off the deployment and O&M pressure for you
181+
so that you can focus on developing your services.
182+
183+
List Instances
184+
^^^^^^^^^^^^^^
185+
186+
This interface is used to query all instances
187+
with query parameters
188+
189+
.. literalinclude:: ../examples/dms/list_instances.py
190+
:lines: 16-22
191+
192+
Find Instance
193+
^^^^^^^^^^^^^
194+
195+
This interface is used to find an Instance by ID
196+
or name
197+
198+
.. literalinclude:: ../examples/dms/find_instance.py
199+
:lines: 16-23
200+
201+
Get Instance
202+
^^^^^^^^^^^^
203+
204+
This interface is used to get Instance by ID
205+
or an instance of class
206+
:class:`~otcextensions.sdk.dms.v1.instance.Instance`.
207+
208+
.. literalinclude:: ../examples/cce/get_job.py
209+
:lines: 16-24
210+
211+
Create Instance
212+
^^^^^^^^^^^^^^^
213+
214+
This interface is used to create an Instance with
215+
parameters.
216+
217+
.. literalinclude:: ../examples/dms/create_instance.py
218+
:lines: 16-34
219+
220+
Delete Instance
221+
^^^^^^^^^^^^^^^
222+
223+
This interface is used to delete an Instance by ID
224+
or an instance of class
225+
:class:`~otcextensions.sdk.dms.v1.instance.Instance`.
226+
227+
.. literalinclude:: ../examples/dms/delete_instance.py
228+
:lines: 16-25
229+
230+
Update Instance
231+
^^^^^^^^^^^^^^^
232+
233+
This interface is used to update an Instance by ID
234+
or an instance of class
235+
:class:`~otcextensions.sdk.dms.v1.instance.Instance`.
236+
237+
.. literalinclude:: ../examples/dms/create_instance.py
238+
:lines: 16-28
239+
240+
Restart Instance
241+
^^^^^^^^^^^^^^^^
242+
243+
This interface is used to restart an Instance by ID
244+
or an instance of class
245+
:class:`~otcextensions.sdk.dms.v1.instance.Instance`.
246+
247+
.. literalinclude:: ../examples/dms/restart_instance.py
248+
:lines: 16-25
249+
250+
DMS Instance Topics
251+
-------------------
252+
253+
After creating a Kafka premium instance,
254+
you must create a topic in the instance
255+
for creating and retrieving messages.
256+
257+
List Instance Topics
258+
^^^^^^^^^^^^^^^^^^^^
259+
260+
This interface is used to query all instance topics
261+
with query parameters
262+
263+
.. literalinclude:: ../examples/dms/list_instance_topics.py
264+
:lines: 16-25
265+
266+
Create Instance Topic
267+
^^^^^^^^^^^^^^^^^^^^^
268+
269+
This interface is used to create an Instance topic with
270+
parameters.
271+
272+
.. literalinclude:: ../examples/dms/create_instance_topic.py
273+
:lines: 16-28
274+
275+
Delete Instance Topic
276+
^^^^^^^^^^^^^^^^^^^^^
277+
278+
This interface is used to delete an Instance topic by ID
279+
or an instance of class
280+
:class:`~otcextensions.sdk.dms.v1.instance.Instance`.
281+
282+
.. literalinclude:: ../examples/dms/delete_instance.py
283+
:lines: 16-25
284+
285+
Misc
286+
----
287+
288+
Extra APIs allow querying of DMS specific data.
289+
290+
List Instance Availability Zones
291+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
292+
293+
This interface is used to query all instance AZ's.
294+
295+
.. literalinclude:: ../examples/dms/list_instance_az_zones.py
296+
:lines: 16-22
297+
298+
List Products
299+
^^^^^^^^^^^^^
300+
301+
This interface is used to query all supported DMS products.
302+
303+
.. literalinclude:: ../examples/dms/list_instance_products.py
304+
:lines: 16-22
305+
306+
List Maintenance Windows
307+
^^^^^^^^^^^^^^^^^^^^^^^^
308+
309+
This interface is used to query all Maintenance Windows.
310+
311+
.. literalinclude:: ../examples/dms/list_maintenance_windows.py
312+
:lines: 16-22

doc/source/sdk/guides/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Open Telekom Cloud related User Guides
1515
cts
1616
dcs
1717
deh
18+
dms
1819
dns
1920
kms
2021
nat

examples/dms/confirm_message.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python3
2+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
3+
# not use this file except in compliance with the License. You may obtain
4+
# a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
# License for the specific language governing permissions and limitations
12+
# under the License.
13+
"""
14+
Confirm Messages
15+
"""
16+
import openstack
17+
18+
openstack.enable_logging(True)
19+
conn = openstack.connect(cloud='otc')
20+
21+
queue_name_or_id = 'queue_name_or_id'
22+
queue = conn.dms.find_queue(name_or_id=queue_name_or_id)
23+
group_name_or_id = 'group_name_or_id'
24+
group = conn.dms.find_group(queue, name_or_id=group_name_or_id)
25+
26+
27+
attrs = {
28+
'queue': queue,
29+
'group': group,
30+
'messages': [
31+
{
32+
'handler': 'handler_id',
33+
'status': 'success'
34+
}
35+
]
36+
}
37+
for raw in conn.dms.ack_message(**attrs):
38+
print(raw)

examples/dms/consume_message.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python3
2+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
3+
# not use this file except in compliance with the License. You may obtain
4+
# a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
# License for the specific language governing permissions and limitations
12+
# under the License.
13+
"""
14+
Consume Messages
15+
"""
16+
import openstack
17+
18+
openstack.enable_logging(True)
19+
conn = openstack.connect(cloud='otc')
20+
21+
attrs = {
22+
'queue': 'queue_id',
23+
'group': 'group_id'
24+
}
25+
for raw in conn.dms.consume_message(**attrs):
26+
print(raw)

0 commit comments

Comments
 (0)