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-05 19:16:55
|
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...>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
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> 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...> <pe...@ya...>> wrote:
> >
> > OCI_SubscriptionAddDequeue
> >
> >
> >
> >
> > --
> > 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/
>
> iQEcBAEBAgAGBQJQvwGAAAoJEC8yRjM4uE2t7MwH/iYJyM13uHjr7pEYewQJ+cLV
> 5iYQTyB6RrD5TCVDXyid9KB55AVHHtef4yr24HDkMTxAit0D+ayP3T51EqV7ojuf
> ncqMR895TJMleK01+NSy9W0jzevj81/K8Tia3QO6QdXJd7EPNHiBY0m2EYJaTPbI
> AY1H47IKTWadMs2VCEuvV5zMzTf/RP7765FpKB/91/+Tm14A6A4SUY1QRc9mLRJ2
> +vCy6UU8MXhEngKmFUKB+ZBte7YB8GdxrNeStM2vIHTYuRqYEgvzZLmU3oIwubw6
> kOSOy1evKLuXNqe9DxbIwfMdE2T1DMvEtryLGUrHLG3UR35r5LwkhIW7Fp00VD8=
> =vGEd
> -----END PGP SIGNATURE-----
>
>
--
Vincent Rogier
|