From 980f3d491ca23e2d541092cd5189d3be6c4e3069 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Tue, 19 Jun 2018 11:00:53 -0600 Subject: [PATCH] Added support for indicating if the subscription is still registered with the database when a notification is received. --- doc/src/subscription.rst | 21 ++++++++++++++++----- samples/CQN.py | 2 +- samples/DatabaseChangeNotification.py | 2 +- src/cxoModule.h | 1 + src/cxoSubscr.c | 2 ++ 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/doc/src/subscription.rst b/doc/src/subscription.rst index 6ec3cb5..19cedc3 100644 --- a/doc/src/subscription.rst +++ b/doc/src/subscription.rst @@ -107,6 +107,16 @@ Message Objects to the callback procedure specified when a subscription is created. +.. attribute:: Message.consumerName + + This read-only attribute returns the name of the consumer which generated + the notification. It will be populated if the subscription was created with + the namespace :data:`cx_Oracle.SUBSCR_NAMESPACE_AQ` and the queue is a + multiple consumer queue. + + .. versionadded:: 6.4 + + .. attribute:: Message.dbname This read-only attribute returns the name of the database that generated @@ -130,12 +140,13 @@ Message Objects .. versionadded:: 6.4 -.. attribute:: Message.consumerName +.. attribute:: Message.registered - This read-only attribute returns the name of the consumer which generated - the notification. It will be populated if the subscription was created with - the namespace :data:`cx_Oracle.SUBSCR_NAMESPACE_AQ` and the queue is a - multiple consumer queue. + This read-only attribute returns whether the subscription which generated + this notification is still registered with the database. The subscription + is automatically deregistered with the database when the subscription + timeout value is reached or when the first notification is sent (when the + quality of service flag :data:`cx_Oracle.SUBSCR_QOS_DEREG_NFY` is used). .. versionadded:: 6.4 diff --git a/samples/CQN.py b/samples/CQN.py index ec33e5b..195a002 100644 --- a/samples/CQN.py +++ b/samples/CQN.py @@ -29,7 +29,7 @@ registered = True def callback(message): global registered print("Message type:", message.type) - if message.type == cx_Oracle.EVENT_DEREG: + if not message.registered: print("Deregistration has taken place...") registered = False return diff --git a/samples/DatabaseChangeNotification.py b/samples/DatabaseChangeNotification.py index 9d5dd74..fde9da2 100644 --- a/samples/DatabaseChangeNotification.py +++ b/samples/DatabaseChangeNotification.py @@ -29,7 +29,7 @@ registered = True def callback(message): global registered print("Message type:", message.type) - if message.type == cx_Oracle.EVENT_DEREG: + if not message.registered: print("Deregistration has taken place...") registered = False return diff --git a/src/cxoModule.h b/src/cxoModule.h index 08e30de..f924250 100644 --- a/src/cxoModule.h +++ b/src/cxoModule.h @@ -281,6 +281,7 @@ struct cxoMessage { PyObject *queries; PyObject *queueName; PyObject *consumerName; + int registered; }; struct cxoMessageQuery { diff --git a/src/cxoSubscr.c b/src/cxoSubscr.c index 1913829..3d97830 100644 --- a/src/cxoSubscr.c +++ b/src/cxoSubscr.c @@ -54,6 +54,7 @@ static PyMemberDef cxoMessageTypeMembers[] = { { "queries", T_OBJECT, offsetof(cxoMessage, queries), READONLY }, { "queueName", T_OBJECT, offsetof(cxoMessage, queueName), READONLY }, { "consumerName", T_OBJECT, offsetof(cxoMessage, consumerName), READONLY }, + { "registered", T_BOOL, offsetof(cxoMessage, registered), READONLY }, { NULL } }; @@ -406,6 +407,7 @@ static int cxoMessage_initialize(cxoMessage *messageObj, messageObj->subscription = subscription; encoding = subscription->connection->encodingInfo.encoding; messageObj->type = message->eventType; + messageObj->registered = message->registered; messageObj->dbname = cxoPyString_fromEncodedString(message->dbName, message->dbNameLength, encoding); if (!messageObj->dbname)