Re: [Orclib-users] subscriptions/callback for Oracle AQ
Open source C and C++ library for accessing Oracle Databases
Brought to you by:
vince_del_paris
From: Petr V. <pe...@ya...> - 2012-12-04 13:00:38
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Vincent, the basic usecase is to have resource friendly way how to get AQ messages from the server. The main purbose is to inform client that data are ready to be dequeued. Lets take an example: there is a PL/SQL app doing various business logic resulting in unpredictable timing of posting messages to queues (some kind of notifications to an external app). Currently the external app have to perform polling against the DB/queue to get these messages. In the case you have more queues you need to poll in more loops etc. When there will be a subscription to AQ available we will be able to just wait for an event = to work fully asynchronously (external app is already doing some stuff etc.). So basically - yes, it's something like "monitoring" but it could allow stuff like this (pseudocode): installAQSubscription(...); ... do something ... ... and when DB writes a message to the queue, notify arrives... my_aq_handler(...) { if (queue_name == 'user.foo') handleMessagesFromFoo(); ... } real dequeueing will be done by already existing AQ ocilib implementation. thanks, petr On 12/4/12 1:45 PM, vincent rogier wrote: > Hi Petr, > > I already have in my plans to add support to CQN.. > > OCILIB currently support CDN introduced in 10g. > CQN is an extension of CDN and has been introduced in 11g. > > when I added support for CDN, I saw that subscription could be done against AQ. > when I looked at it, i thought that implementing notifications just for being notified of enqueuing was not a priority. > I may have misunderstood its pertinence. > > If I have well understood, you want to add event notification on AQ for being informed that a user has received a message into queue ? Kind of monitoring ? > Or is there more information you want to get ? More information that the one you've exposed in your code are available > > Regards, > > vincent > > > > > On Mon, Dec 3, 2012 at 7:53 PM, Petr Vaněk <pe...@ya... <mailto:pe...@ya...>> wrote: > > hi Vincent and gang, > > I'd like to introduce you an idea about an addon to DCN or CQN > notifications/callback ocilib framework - notifications and callback > API for Advanced Queueing (AQ). > > You can see it in this temporary git repository: > > https://github.com/pvanek/ocilib > > this is based on the latest ocilib 3.10.0 with these changes: > > > - an initial support for AQ callback: > https://github.com/pvanek/ocilib/commit/0b44a5247829ef52c61694cfc2187396f88ef62f > > Note: this is not a final code, I'd like to know your opinion first. > There is no doc etc. > > * backward compatibility stays as is - there are no changes in > existing public API > * new function OCI_SubscriptionRegisterAQ, similar to > OCI_SubscriptionRegister but it uses AQ's OCI_SUBSCR_NAMESPACE_AQ > subscription context (instead of OCI_SUBSCR_NAMESPACE_DBCHANGE) > * new functions OCI_EventGetAQQueueName and > OCI_EventGetAQConsumerName to get AQ related attributes from OCI_Event > OCI_Event structure has been expanded to hold AQ attributes. > > Here I'm not sure if it's a good idea to expanc existing OCI_Event or > create new AQ-only similar struct and related functions. I'm open to > suggestions here. > > a small example: > > #include "ocilib.h" > > #ifdef _WINDOWS > #define sleep(x) Sleep(x*1000) > #else > #include <unistd.h> > #endif > > #define wait_for_events() sleep(15) > > void event_handler(OCI_Event *event); > void error_handler(OCI_Error *err); > > int main(void) > { > OCI_Connection *con; > OCI_Subscription *sub; > OCI_Statement *st; > > printf("=> Initializing OCILIB in event mode...\n\n"); > > if (!OCI_Initialize(error_handler, NULL, OCI_ENV_EVENTS)) > return EXIT_FAILURE; > > con = OCI_ConnectionCreate("stimpy", "omquser", "omquser", > OCI_SESSION_DEFAULT); > > sub = OCI_SubscriptionRegisterAQ(con, "omquser.testaq", > event_handler, 5468, 0); > > wait_for_events(); > > OCI_ConnectionFree(con); > OCI_SubscriptionUnregister(sub); > OCI_Cleanup(); > return EXIT_SUCCESS; > } > > void error_handler(OCI_Error *err) > { > int err_type = OCI_ErrorGetType(err); > const char *err_msg = OCI_ErrorGetString(err); > > printf("** %s - %s\n", err_type == OCI_ERR_WARNING ? "Warning" : > "Error", err_msg); > } > > void event_handler(OCI_Event *event) > { > unsigned int type = OCI_EventGetType(event); > unsigned int op = OCI_EventGetOperation(event); > OCI_Subscription *sub = OCI_EventGetSubscription(event); > > printf("** Notification : %s\n\n", OCI_SubscriptionGetName(sub)); > printf("... Queue Name : %s\n", > OCI_EventGetAQQueueName(event)); > printf(". Consumer Name : %s\n", > OCI_EventGetAQConsumerName(event)); > > printf("\n"); > } > > > > > > - pkg-config feature added (ocilib.pc): > https://github.com/pvanek/ocilib/commit/6ba08629bb3be6229b19bae577af241fade2202c > This feature is ready to be merged. It allows easy use of ocilib in > cmake, autotools, and similar build tools > > cmake example: > find_package(PkgConfig) > pkg_check_modules(OCILIB REQUIRED ocilib>=3.10) > message(STATUS "includes: ${OCILIB_INCLUDE_DIRS}") > message(STATUS " libs: ${OCILIB_LIBRARIES}") > message(STATUS "lib dirs: ${OCILIB_LIBRARY_DIRS}") > > > > looking forward your comments, > petr > > ------------------------------------------------------------------------------ > Keep yourself connected to Go Parallel: > BUILD Helping you discover the best ways to construct your parallel projects. > http://goparallel.sourceforge.net > _______________________________________________ > Orclib-users mailing list > Orc...@li... <mailto:Orc...@li...> > https://lists.sourceforge.net/lists/listinfo/orclib-users > > > > > -- > Vincent Rogier -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (Darwin) Comment: GPGTools - http://gpgtools.org Comment: Using GnuPG with undefined - http://www.enigmail.net/ iQEcBAEBAgAGBQJQvfPlAAoJEC8yRjM4uE2tdYgH/RMXV8tA/muGigVVN38Fhxhu ltj/CvPmYfUDAK+MAbRStmpumz4uAvYPeawCJEWhHHUCBsthgeRwdXUUs0H+OMg7 aVcvU/KkCIoYBD1navDEYY1+uVldIciUxf36FfHnk7fwQtNXlZi3VRr6UPRkCjGn XK/KiR0udfe2hrB+pVSh0ImXFD08kj2JyQSV6P+ZF69Kd/2wFCJdAOAgWDpWADMX SuYrRKpidpmjqBcLNT0PbyMDcoXihzho/MpAMfr24nhLCBPJAT5nJP2TA6OfMVqC nAKmmExDDFk2bGVcFrF+R18Bac2l6L636nR2OMy4F8A+ZE6InPK8HRbRHKccEVM= =n04O -----END PGP SIGNATURE----- |