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-05 20:04:03
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 that would be perfect (IMHO). I think it's a very clean solution. For eg. simple monitoring it will need only few lines of code. also I silently assume thatOCI_DequeueSetConsumer is still optional (or available with consumer=NULL) to allow to catch all handler's events. thanks, petr On 12/5/12 8:16 PM, vincent rogier wrote: > Hi, > > The design exposed in my previous email would give : > > > void msg_handler(OCI_Dequeue *deq, OCI_Msg *msg) > { > /* process msg payload */ > } > > int main(void) > { > OCI_Connection *con; > OCI_Dequeue *deq1; > OCI_Dequeue *deq2; > > OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT | OCI_ENV_EVENTS | OCI_ENV_THREADED); > > con = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT); > inf = OCI_TypeInfoGet(con, "MY_MESSAGE", OCI_TIF_TYPE); > deq1 = OCI_DequeueCreate(inf, "MY_QUEUE"); > deq2 = OCI_DequeueCreate(inf, "MY_QUEUE"); > > OCI_DequeueEnableAsync(PORT, TIMEOUT); > > OCI_DequeueSetConsumer(deq1, "CONSUMER1"); > OCI_DequeueSetConsumer(deq2, "CONSUMER2"); > > OCI_DequeueGetStartAsync(deq1, msg_handler); > OCI_DequeueGetStartAsync(deq2, msg_handler); > > sleep(MAX_INT); > > OCI_DequeueGetStopAsync(deq1); //optional - performed by OCI_DequeueFree > OCI_DequeueGetStopAsync(deq2); //optional - performed by OCI_DequeueFree > OCI_DequeueFree(deq1); > OCI_DequeueFree(deq2); > > OCI_DequeueDisableAsync(); //optional - performed by OCI_Cleanup > OCI_ConnectionFree(con); > OCI_Cleanup(); > > return EXIT_SUCCESS; > } > > > > On Wed, Dec 5, 2012 at 6:39 PM, vincent rogier <vin...@gm... <mailto:vin...@gm...>> wrote: > > Hi, > > In fact, I prefer to not use an OCI_Event as all other fields (database, datetime, etc....) won't be available..... That would be messy ! > > Thus, what i proposed does not make sense. > > As the goal is to implement async dequeuing i prefer proposing another design. What do you think about the following : > * OCI_DequeueEnableAsync(port, timeout) > * OCI_DequeueDisableAsync(void) > * OCI_DequeueGetStartAsync(oci_dequeue *, async callback) > * OCI_DequeueGetStopAsync(oci_dequeue *) > > Where async callback prototype woulb be like: > void callback(oci_dequeue*, oci_msg*) > > Thus no public subscription (it would be internal). Just call to enable/disable program wide aq notification. Then you provide a callback that gets msg object. I find it smooth. > It may need to support more than one central notification... > > Vincent > > > hi Vincent, > > yes, it makes perfect sense to me. > > I'm looking forward to it! > p. > > On 12/5/12 9:07 AM, vincent rogier wrote: > > Hi, > > > > About coding, this is a secondary easy task that required only just few lines of code. > > I'm more focused on how to integrate to OCILIB. > > Is the following mock-up all right for you ? > > > > #include "ocilib.h" > > > #ifdef _WINDOWS > > #define sleep(x) Sleep(x*1000) > > #endif > > > #define PORT 5468 > > #define TIMEOUT 0 > > > void event_handler(OCI_Event *event); > > void error_handler(OCI_Error *err); > > > int main(void) > > { > > OCI_Connection *con; > > OCI_Subscription *sub; > > OCI_Dequeue *deq1; > > OCI_Dequeue *deq2; > > > OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT | OCI_ENV_EVENTS | OCI_ENV_THREADED); > > > con = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT); > > sub = OCI_SubscriptionRegister(con, "SUB-MSG", OCI_CNT_MESSAGE, event_handler, PORT, TIMEOUT); > > inf = OCI_TypeInfoGet(con, "MY_MESSAGE", OCI_TIF_TYPE); > > deq1 = OCI_DequeueCreate(inf, "MY_QUEUE"); > > deq2 = OCI_DequeueCreate(inf, "MY_QUEUE"); > > > OCI_DequeueSetConsumer(deq1, "CONSUMER1"); > > OCI_DequeueSetConsumer(deq2, "CONSUMER2"); > > > OCI_SubscriptionAddDequeue(sub, deq1); > > OCI_SubscriptionAddDequeue(sub, deq2); > > > sleep(MAX_INT); > > > OCI_DequeueFree(deq1); > > OCI_DequeueFree(deq2); > > OCI_SubscriptionUnregister(sub); > > OCI_ConnectionFree(con); > > > OCI_Cleanup(); > > > return EXIT_SUCCESS; > > } > > > void error_handler(OCI_Error *err) > > { > > printf("*** error : %s\n", OCI_ErrorGetString(err)); > > } > > > void event_handler(OCI_Event *event) > > { > > OCI_Dequeue *deq = OCI_EventGetDequeue(event); > > OCI_Msg *msg = OCI_DequeueGet(deq); > > > /* process payload */ > > } > > > > > On Tue, Dec 4, 2012 at 8:57 PM, Petr Vaněk <pe...@ya... <mailto:pe...@ya...> <mailto:pe...@ya...> <mailto:pe...@ya...>> wrote: > > > OCI_SubscriptionAddDequeue > > > > > > -- > > Vincent Rogier > > > > > > -- > 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/ iQEcBAEBAgAGBQJQv6iiAAoJEC8yRjM4uE2tpd8H/RwdU3qGzA/Vx1J9xI8gzhGq S6qypr0K/ErrRCMCVNZhPGYYp4it1Os8pFek7FidETkOjPdO9HcCq1IVPdFWuX9N ZjqG6+tKWOMSUfHunXxwqdN+I28z0K5jgCzpKGpf2gtAdKnWeg/TZn02sB1sfAle a2fDbpFWzjtZ0N3wtA1zNJrsOAlHLwK8ciIGYbQXsPYMFDBrqgzR2n5iWUgpuH4R 8PJR4m48e6I/40+TZhrunFWg9QFXCZPW+CbxZdLz+XzrIRZEcXJ100yar63AeLfu vaX1XGluwj9+Og88EHxT50gnM1LNRXclU4K1Im66Q/u3NN2zm+6uxx33NcEAVpg= =pry4 -----END PGP SIGNATURE----- |