1
1
.. _aqusermanual :
2
2
3
- ***********************************
4
- Using Oracle Advanced Queuing (AQ)
5
- ***********************************
6
-
7
- `Oracle Advanced Queuing
8
- <https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=ADQUE> `__ is a highly
9
- configurable and scalable messaging feature of Oracle Database. It has
10
- interfaces in various languages, letting you integrate multiple tools in your
11
- architecture.
3
+ ************************************************************
4
+ Using Oracle Transactional Event Queues and Advanced Queuing
5
+ ************************************************************
6
+
7
+ `Oracle Transactional Event Queues and Advanced Queuing
8
+ <https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=ADQUE> `__ are highly
9
+ configurable and scalable messaging features of Oracle Database allowing
10
+ data-driven and event-driven applications to stream events and communicate with
11
+ each other. They have interfaces in various languages, letting you integrate
12
+ multiple tools in your architecture. Both Oracle Transactional Event Queues
13
+ (TxEventQ) and Advanced Queuing (AQ) "Classic" queues support sending and
14
+ receiving of various payloads, such as RAW values, JSON, JMS, and objects.
15
+ Transactional Event Queues use a highly optimized implementation of Advanced
16
+ Queuing. They were previously called AQ Sharded Queues.
12
17
13
18
.. note ::
14
19
15
- Oracle Advanced Queuing is only supported in the python-oracledb Thick
20
+ TxEventQ and AQ Classic queues are only supported in python-oracledb Thick
16
21
mode. See :ref: `enablingthick `.
17
22
18
- Python-oracledb uses the updated interface for Oracle Advanced Queuing that
19
- was first introduced in cx_Oracle 7.2.
23
+ Python-oracledb API calls are the same for Transactional Event Queues and
24
+ Classic Queues, however there are differences in support for some payload
25
+ types.
26
+
27
+ **Classic Queue Support **
28
+
29
+ - RAW, named Oracle objects, and JMS payloads are supported.
20
30
21
- Starting from Oracle Database 21c, Advanced Queuing also supports the JSON
22
- payload type. To use the JSON payload type, the Oracle Client libraries must
23
- be version 21 or later.
31
+ - The JSON payload requires Oracle Client libraries 21c (or later) and Oracle
32
+ Database 21c (or later).
24
33
25
- There are Advanced Queuing examples in the `GitHub examples
34
+ There are examples of AQ Classic Queues in the `GitHub examples
26
35
<https://github.com/oracle/python-oracledb/tree/main/samples> `__ directory.
27
36
37
+ **Transactional Event Queue Support **
38
+
39
+ - RAW and named Oracle object payloads are supported for single and array
40
+ message enqueuing and dequeuing when using Oracle Client 19c (or later) and
41
+ connected to Oracle Database 19c (or later).
42
+
43
+ - JMS payloads are supported for single and array message enqueuing and
44
+ dequeuing when using Oracle Client 19c (or later) and Oracle Database 23ai.
45
+
46
+ - JSON payloads are supported for single message enqueuing and dequeuing when
47
+ using Oracle Client libraries 21c (or later) and Oracle Database 21c (or
48
+ later). Array enqueuing and dequeuing is not supported for JSON payloads.
49
+
50
+ Transactional Event Queues do not support :attr: `EnqOptions.transformation `,
51
+ :attr: `DeqOptions.transformation `, or :ref: `Recipient Lists <reciplists >`.
28
52
29
53
Creating a Queue
30
54
================
31
55
32
- Before being used, queues need to be created in the database.
56
+ Before being used in applications , queues need to be created in the database.
33
57
34
58
**Using RAW Payloads **
35
59
36
- Queues can be created using the RAW payload type, for example in
37
- SQL*Plus :
60
+ To use SQL*Plus to create a Classic Queue for the RAW payload which is suitable
61
+ for sending string or bytes messages :
38
62
39
63
.. code-block :: sql
40
64
@@ -45,13 +69,20 @@ SQL*Plus:
45
69
end;
46
70
/
47
71
48
- This example creates a RAW queue suitable for sending string or bytes
49
- messages.
72
+ To create a Transactional Event Queue for RAW payloads:
73
+
74
+ .. code-block :: sql
75
+
76
+ begin
77
+ dbms_aqadm.create_sharded_queue('RAW_SHQ', queue_payload_type=>'RAW');
78
+ dbms_aqadm.start_queue('RAW_SHQ');
79
+ end;
80
+ /
50
81
51
82
**Using JSON Payloads **
52
83
53
- Also, queues can be created using the JSON payload type . For example,
54
- in SQL*Plus:
84
+ Queues can also be created for JSON payloads . For example, to create a Classic
85
+ Queue in SQL*Plus:
55
86
56
87
.. code-block :: sql
57
88
@@ -62,14 +93,11 @@ in SQL*Plus:
62
93
end;
63
94
/
64
95
65
- This example creates a JSON queue suitable for sending JSON data
66
- messages.
67
-
68
96
Enqueuing Messages
69
97
==================
70
98
71
99
To send messages in Python, you connect and get a :ref: `queue <queue >`. The
72
- queue can be used for enqueuing, dequeuing, or both as needed .
100
+ queue can then be used for enqueuing, dequeuing, or for both .
73
101
74
102
**Using RAW Payloads **
75
103
@@ -94,9 +122,12 @@ messages:
94
122
queue.enqone(connection.msgproperties(payload = data))
95
123
connection.commit()
96
124
97
- Since the queue sending the messages is a RAW queue, the strings in this
98
- example will be internally encoded to bytes using ``message.encode() ``
99
- before being enqueued.
125
+ Since the queue is a RAW queue, strings are internally encoded to bytes using
126
+ ``message.encode() `` before being enqueued.
127
+
128
+ The use of :meth: `~Connection.commit() ` means that messages are sent only when
129
+ any database transaction related to them is committed. This behavior can be
130
+ altered, see :ref: `aqoptions `.
100
131
101
132
**Using JSON Payloads **
102
133
@@ -105,8 +136,8 @@ payload type by using:
105
136
106
137
.. code-block :: python
107
138
139
+ # The argument "JSON" indicates the queue is of JSON payload type
108
140
queue = connection.queue(" DEMO_JSON_QUEUE" , " JSON" )
109
- # The second argument (JSON) indicates that the queue is of JSON payload type.
110
141
111
142
Now the message can be enqueued using :meth: `~Queue.enqone() `.
112
143
@@ -133,7 +164,7 @@ Dequeuing Messages
133
164
Dequeuing is performed similarly. To dequeue a message call the method
134
165
:meth: `~Queue.deqone() ` as shown in the examples below.
135
166
136
- **Using RAW Payload Type **
167
+ **Using RAW Payloads **
137
168
138
169
.. code-block :: python
139
170
@@ -142,10 +173,10 @@ Dequeuing is performed similarly. To dequeue a message call the method
142
173
connection.commit()
143
174
print (message.payload.decode())
144
175
145
- Note that if the message is expected to be a string, the bytes must
146
- be decoded using ``message.payload.decode() ``, as shown.
176
+ Note that if the message is expected to be a string, the bytes must be decoded
177
+ by the application using ``message.payload.decode() ``, as shown.
147
178
148
- **Using JSON Payload Type **
179
+ **Using JSON Payloads **
149
180
150
181
.. code-block :: python
151
182
@@ -179,7 +210,7 @@ And a queue that accepts this type:
179
210
end;
180
211
/
181
212
182
- You can queue messages:
213
+ You can enqueue messages:
183
214
184
215
.. code-block :: python
185
216
@@ -194,7 +225,7 @@ You can queue messages:
194
225
queue.enqone(connection.msgproperties(payload = book))
195
226
connection.commit()
196
227
197
- Dequeuing is done like this:
228
+ Dequeuing can be done like this:
198
229
199
230
.. code-block :: python
200
231
@@ -205,18 +236,20 @@ Dequeuing is done like this:
205
236
connection.commit()
206
237
print (message.payload.TITLE ) # will print Quick Brown Fox
207
238
239
+ .. _reciplists :
208
240
209
241
Using Recipient Lists
210
242
=====================
211
243
212
- A list of recipient names can be associated with a message at the time
213
- a message is enqueued. This allows a limited set of recipients to
214
- dequeue each message. The recipient list associated with the message
215
- overrides the queue subscriber list, if there is one. The recipient
216
- names need not be in the subscriber list but can be, if desired.
244
+ Classic Queues support Recipient Lists. A list of recipient names can be
245
+ associated with a message at the time a message is enqueued. This allows a
246
+ limited set of recipients to dequeue each message. The recipient list
247
+ associated with the message overrides the queue subscriber list, if there is
248
+ one. The recipient names need not be in the subscriber list but can be, if
249
+ desired. Transactional Event Queues do not support Recipient Lists.
217
250
218
- To dequeue a message, the `` consumername `` attribute can be set to
219
- one of the recipient names. The original message recipient list is
251
+ To dequeue a message, the :attr: ` ~DeqOptions. consumername ` attribute can be
252
+ set to one of the recipient names. The original message recipient list is
220
253
not available on dequeued messages. All recipients have to dequeue
221
254
a message before it gets removed from the queue.
222
255
@@ -237,6 +270,8 @@ messages intended for that recipient using the ``consumername`` attribute::
237
270
queue.deqoptions.consumername = "sub3"
238
271
m = queue.deqone()
239
272
273
+ .. _aqoptions :
274
+
240
275
Changing Queue and Message Options
241
276
==================================
242
277
@@ -245,8 +280,8 @@ Refer to the :ref:`python-oracledb AQ API <aq>` and
245
280
<https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=ADQUE> `__ for details
246
281
on all of the enqueue and dequeue options available.
247
282
248
- Enqueue options can be set. For example, to make it so that an explicit
249
- call to :meth: `~Connection.commit() ` on the connection is not needed to commit
283
+ Enqueue options can be set. For example, to make it so that an explicit call
284
+ to :meth: `~Connection.commit() ` on the connection is not needed to send
250
285
messages:
251
286
252
287
.. code-block :: python
@@ -269,7 +304,7 @@ expiration of 60 seconds on a message:
269
304
270
305
queue.enqone(connection.msgproperties(payload = " Message" , expiration = 60 ))
271
306
272
- This means that if no dequeue operation occurs within 60 seconds that the
307
+ This means that if no dequeue operation occurs within 60 seconds then the
273
308
message will be dropped from the queue.
274
309
275
310
@@ -279,8 +314,8 @@ Bulk Enqueue and Dequeue
279
314
The :meth: `~Queue.enqmany() ` and :meth: `~Queue.deqmany() ` methods can be used
280
315
for efficient bulk message handling.
281
316
282
- :meth: `~Queue.enqmany() ` is similar to :meth: `~Queue.enqone() ` but accepts an
283
- array of messages:
317
+ The :meth: `~Queue.enqmany() ` method is similar to :meth: `~Queue.enqone() ` but
318
+ accepts an array of messages:
284
319
285
320
.. code-block :: python
286
321
@@ -296,11 +331,11 @@ array of messages:
296
331
.. warning ::
297
332
298
333
Calling :meth: `~Queue.enqmany() ` in parallel on different connections
299
- acquired from the same pool may fail due to Oracle bug 29928074. Ensure
300
- that this function is not run in parallel, use standalone connections or
301
- connections from different pools, or make multiple calls to
302
- :meth: `~Queue.enqone() ` instead. The function :meth: ` ~Queue.deqmany() ` call
303
- is not affected.
334
+ acquired from the same pool may fail due to Oracle bug 29928074. To avoid
335
+ this, ensure that :meth: ` ~Queue.enqmany() ` is not run in parallel, use
336
+ standalone connections or connections from different pools, or make
337
+ multiple calls to :meth: `~Queue.enqone() ` instead. The function
338
+ :meth: ` ~Queue.deqmany() ` call is not affected.
304
339
305
340
To dequeue multiple messages at one time, use :meth: `~Queue.deqmany() `. This
306
341
takes an argument specifying the maximum number of messages to dequeue at one
0 commit comments