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: vincent r. <vin...@gm...> - 2012-12-06 00:13:42
|
Hum... I've been testing my implementation that seemed to works nicely. But... We can have two types of queue table : single consumer and multiple consumers. First case, a message is consumed by one consumer Second case, a message can be consumed by many consumer In the first case, it simple. For the second case, the OCI subscription must specify the consumer name.... Thus it is not possible possible to have a library wide subscription when dealing with a queue with multiple consumers. Thus a subscription must be done for each dequeue object... So i removed OCI_DequeueEnableAsync() and OCI_DequeueDisableAsync() We end up with only 2 new functions ! Here is 2 examples: First a queue with multiple consumer set to false (default) : void on_message(OCI_Dequeue *deq, OCI_Msg *msg) { /* process message here */ } int main(int argc, char *argv[]) { OCI_Connection *con; OCI_Dequeue *deq; OCI_TypeInfo *inf; OCI_Initialize(err_handler, NULL, OCI_ENV_DEFAULT | OCI_ENV_THREADED |OCI_ENV_EVENTS); con = OCI_ConnectionCreate("db11g", "usr", "pwd", OCI_SESSION_DEFAULT); inf = OCI_TypeInfoGet(con, "MY_MESSAGE", OCI_TIF_TYPE); deq = OCI_DequeueCreate(inf, "usr.my_queue"); OCI_DequeueGetStartAsync(deq, 9999, 0, on_message); getchar(); OCI_DequeueGetStopAsync(deq); OCI_DequeueFree(deq); OCI_ConnectionFree(con); OCI_Cleanup(); return EXIT_SUCCESS; } And a second example where we have a queue with multiple consumers : void on_message(OCI_Dequeue *deq, OCI_Msg *msg) { /* process message here */ } int main(int argc, char *argv[]) { OCI_Connection *con; OCI_Dequeue *deq1; OCI_Dequeue *deq2; OCI_TypeInfo *inf; OCI_Initialize(err_handler, NULL, OCI_ENV_DEFAULT | OCI_ENV_THREADED |OCI_ENV_EVENTS); con = OCI_ConnectionCreate("db11g", "usr", "pwd", OCI_SESSION_DEFAULT); inf = OCI_TypeInfoGet(con, "MY_MESSAGE", OCI_TIF_TYPE); deq1 = OCI_DequeueCreate(inf, "usr.my_queue"); deq2 = OCI_DequeueCreate(inf, "usr.my_queue"); OCI_DequeueSetConsumer(deq1, "C1"); OCI_DequeueSetNavigation(deq1, OCI_ADN_FIRST_MSG); OCI_DequeueSetConsumer(deq2, "C2"); OCI_DequeueSetNavigation(deq2, OCI_ADN_FIRST_MSG); OCI_DequeueGetStartAsync(deq1, 9998, 0, on_message); OCI_DequeueGetStartAsync(deq2, 9999, 0, on_message); getchar(); OCI_DequeueGetStopAsync(deq1); OCI_DequeueGetStopAsync(deq2); OCI_DequeueFree(deq1); OCI_DequeueFree(deq2); OCI_ConnectionFree(con); OCI_Cleanup(); return EXIT_SUCCESS; } My tests seems to run smoothly... Let me know your opinion :) Vincent On Wed, Dec 5, 2012 at 9:11 PM, vincent rogier <vin...@gm...>wrote: > yep, OCI_DequeueSetConsumer is still optional. > > I'm currently working on implementing the design shown oin my previous > email. > > I'll send to you a temporary ocilib package later this evening :) > > On Wed, Dec 5, 2012 at 9:03 PM, Petr Vaněk <pe...@ya...> wrote: > >> ly assume thatOCI_DequeueSetConsumer is sti > > > > > -- > Vincent Rogier > -- Vincent Rogier |