Skip to content

Commit 4fa6509

Browse files
Added support for getting the message id of the AQ message which generated
a notification.
1 parent fedd95f commit 4fa6509

File tree

7 files changed

+45
-0
lines changed

7 files changed

+45
-0
lines changed

doc/src/api_manual/subscription.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ Message Objects
126126
This read-only attribute returns the name of the database that generated
127127
the notification.
128128

129+
.. attribute:: Message.msgid
130+
131+
This read-only attribute returns the message id of the AQ message which
132+
generated the notification. It will only be populated if the subscription
133+
was created with the namespace :data:`oracledb.SUBSCR_NAMESPACE_AQ`.
129134

130135
.. attribute:: Message.queries
131136

doc/src/release_notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Thin Mode Changes
2020
Thick Mode Changes
2121
++++++++++++++++++
2222

23+
#) Added support for getting the message id of the AQ message which generated
24+
a notification.
2325
#) Fixed the ability to use external authentication with connection pools.
2426

2527

samples/aq_notification.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def process_messages(message):
4949
return
5050
print("Queue name:", message.queue_name)
5151
print("Consumer name:", message.consumer_name)
52+
print("Message id:", message.msgid)
5253

5354
connection = oracledb.connect(user=sample_env.get_main_user(),
5455
password=sample_env.get_main_password(),

src/oracledb/impl/thick/odpi.pxd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,8 @@ cdef extern from "impl/thick/odpi/embed/dpi.c":
480480
uint32_t queueNameLength
481481
const char *consumerName
482482
uint32_t consumerNameLength
483+
const void *aqMsgId
484+
uint32_t aqMsgIdLength
483485

484486
ctypedef struct dpiSubscrMessageQuery:
485487
uint64_t id

src/oracledb/impl/thick/subscr.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ cdef class ThickSubscrImpl(BaseSubscrImpl):
9999
if message.consumerName != NULL:
100100
py_message._consumer_name = \
101101
message.consumerName[:message.consumerNameLength].decode()
102+
if message.aqMsgId != NULL:
103+
msgid = <const char*> message.aqMsgId
104+
py_message._msgid = msgid[:message.aqMsgIdLength]
102105
if message.eventType == DPI_EVENT_OBJCHANGE:
103106
temp = py_message._tables
104107
for i in range(message.numTables):

src/oracledb/subscr.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ def __init__(self, subscription: Subscription) -> None:
168168
self._tables = []
169169
self._txid = None
170170
self._type = 0
171+
self._msgid = None
171172

172173

173174
@property
@@ -193,6 +194,13 @@ def dbname(self) -> str:
193194
"""
194195
return self._db_name
195196

197+
@property
198+
def msgid(self) -> bytes:
199+
"""
200+
Returns the message id of the AQ message that generated the notification.
201+
"""
202+
return self._msgid
203+
196204
@property
197205
def queries(self) -> list:
198206
"""

tests/test_2700_aq.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,5 +423,29 @@ def test_2719_recipients_list(self):
423423
props1 = queue.deqone()
424424
self.assertTrue(props1 is None)
425425

426+
def test_2720_aq_notification(self):
427+
"2720 - verify msgid of aq message which spawned notification "
428+
self.__clear_books_queue()
429+
condition = threading.Condition()
430+
connection = test_env.get_connection(events=True)
431+
def notification_callback(message):
432+
self.cursor.execute("select msgid from book_queue_tab")
433+
actual_msgid, = self.cursor.fetchone()
434+
self.assertEqual(actual_msgid, message.msgid)
435+
with condition:
436+
condition.notify()
437+
sub = connection.subscribe(namespace=oracledb.SUBSCR_NAMESPACE_AQ,
438+
name=self.book_queue_name,
439+
callback=notification_callback, timeout=300)
440+
books_type = connection.gettype(self.book_type_name)
441+
queue = connection.queue(self.book_queue_name, books_type)
442+
book = books_type.newobject()
443+
book.TITLE, book.AUTHORS, book.PRICE = self.book_data[0]
444+
props = connection.msgproperties(payload=book)
445+
queue.enqone(props)
446+
connection.commit()
447+
with condition:
448+
condition.wait(5)
449+
426450
if __name__ == "__main__":
427451
test_env.run_test_cases()

0 commit comments

Comments
 (0)