09.12.2012 Views

Advanced Queuing - Oracle

Advanced Queuing - Oracle

Advanced Queuing - Oracle

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

LNOCIError *errhp;<br />

LNOCISvcCtx *svchp;<br />

LNOCIAQDeqOptions *deqopt;<br />

message *mesg = (message *)0;<br />

null_message *mesgind = (null_message *)0;<br />

static void deqmesg(buf, buflen)<br />

text *buf;<br />

ub4 *buflen;<br />

{<br />

AQ and Memory Usage<br />

OCIType *mesgtdo = (OCIType *)0; /* type descr of SCOTT.MESSAGE */<br />

ub4 wait = 60; /* timeout after 60 seconds */<br />

ub4 navigation = OCI_DEQ_FIRST_MSG;/* always get head of q */<br />

/* Get the type descriptor object for the type SCOTT.MESSAGE: */<br />

checkerr(errhp, OCITypeByName(envhp, errhp, svchp,<br />

(CONST text *)"SCOTT", strlen("SCOTT"),<br />

(CONST text *)"MESSAGE", strlen("MESSAGE"),<br />

(text *)0, 0, OCI_DURATION_SESSION,<br />

OCI_TYPEGET_ALL, &mesgtdo));<br />

/* Set wait time, navigation in dequeue options: */<br />

checkerr(errhp, OCIAttrSet(deqopt, OCI_DTYPE_AQDEQ_OPTIONS,<br />

(dvoid *)&wait, 0, OCI_ATTR_WAIT, errhp));<br />

checkerr(errhp, OCIAttrSet(deqopt, OCI_DTYPE_AQDEQ_OPTIONS,<br />

(dvoid *)&navigation, 0,<br />

OCI_ATTR_NAVIGATION, errhp));<br />

/*<br />

* Dequeue the message and commit. The memory for the payload will be<br />

* automatically allocated/resized by OCI:<br />

*/<br />

checkerr(errhp, OCIAQDeq(svchp, errhp, (CONST text *)"msgqueue",<br />

deqopt, 0, mesgtdo, (dvoid **)&mesg,<br />

(dvoid **)&mesgind, 0, 0));<br />

checkerr(errhp, OCITransCommit(svchp, errhp, (ub4) 0));<br />

/* Copy the message payload text into the user buffer: */<br />

if (mesgind->null_data)<br />

*buflen = 0;<br />

else<br />

memcpy((dvoid *)buf, (dvoid *)OCIStringPtr(envhp, mesg->data),<br />

(size_t)(*buflen = OCIStringSize(envhp, mesg->data)));<br />

<strong>Oracle</strong> <strong>Advanced</strong> <strong>Queuing</strong> by Example A-85

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!