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.

AQ and Memory Usage<br />

OCIErrorGet ((dvoid *) errhp, (ub4) 1, (text *) NULL, &errcode,<br />

errbuf, (ub4) sizeof(errbuf), (ub4) OCI_HTYPE_ERROR);<br />

printf("Error - %s\n", errbuf);<br />

break;<br />

case OCI_INVALID_HANDLE:<br />

printf("Error - OCI_INVALID_HANDLE\n");<br />

break;<br />

default:<br />

printf("Error - %d\n", status);<br />

break;<br />

}<br />

exit(-1);<br />

} /* end checkerr */<br />

Dequeuing Messages (Free Memory After Every Call) Using OCI<br />

This program, deqnoreuse.c, dequeues each line of text from a queue 'msgqueue'<br />

that has been created in scott's schema by executing create_types.sql. Messages<br />

are enqueued using enqnoreuse or enqreuse. If there are no messages, it waits<br />

for 60 seconds before timing out. In this program the dequeue subroutine does not<br />

reuse client side objects' memory. It allocates the required memory before dequeue<br />

and frees it after the dequeue is complete.<br />

#ifndef OCI_ORACLE<br />

#include <br />

#endif<br />

#include <br />

static void checkerr(OCIError *errhp, sword status);<br />

static void deqmesg(text *buf, ub4 *buflen);<br />

LNOCIEnv *envhp;<br />

LNOCIError *errhp;<br />

LNOCISvcCtx *svchp;<br />

struct message<br />

{<br />

OCINumber id;<br />

OCIString *data;<br />

};<br />

typedef struct message message;<br />

struct null_message<br />

{<br />

A-80 <strong>Oracle</strong>9i Application Developer’s Guide - <strong>Advanced</strong> <strong>Queuing</strong>

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

Saved successfully!

Ooh no, something went wrong!