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...@ya...> - 2012-12-05 08:07:37
|
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...> wrote: > OCI_SubscriptionAddDequeue -- Vincent Rogier |