Oracle Objects for OLE C++ Class Library Release 9.2 Part Number A95896-01 |
|
This topic includes examples for enqueuing RAW (string of characters) and user-defined type messages.
Note: For more information about sample code, see Sample Code and Applications.
Enqueuing RAW (String of Characters) Messages:
#include <oracl.h>
OSession osess ;
int EnqueueRaw();
int main(int argc, char **argv)
{
int retVal = 0;
OStartup(OSTARTUP_MULTITHREADED);
try
{
osess.Open();
if ( ! osess.IsOpen() )
{
cout << "Session not opened: Error: " << osess.GetErrorText() << endl;
osess.Close();
OShutdown();
return -1;
}
// Enqueue a payload of raw type
retVal = EnqueueRaw();
osess.Close();
OShutdown();
}
catch(OException oerr)
{
cout << "Exception while dequeuing message : " << oerr.GetErrorText() << endl;
retVal = -1;
}
return retVal;
}
// This function enqueues a message of default
// type (string of characters) to the queue.
// Sets the message attributes and queue attributes before enqueuing
int EnqueueRaw()
{
ODatabase odb;
const char *msgid = 0;
OAQ oaq;
OAQMsg oaqmsg;
odb.Open(osess, "ExampleDB", "SCOTT", "TIGER");
// Open the 'raw_msg_queue'
oaq.Open(odb,"raw_msg_queue");
// Get an instance of the default message(of RAW type)
oaqmsg.Open(oaq);
// Enqueue the message
// Set the actual message value
OValue oval = "My first message through OO4O ClassLibrary";
oaqmsg.SetValue(oval);
msgid = oaq.Enqueue();
const char *msgval = oval;
if ( msgid )
cout<<"Message : '"<<msgval<<"' Enqueued Successfully"<<endl;
// Set Message attributes - priority,Correlation identifier etc
oaqmsg.SetPriority(-6);
oaqmsg.SetCorrelation("FOR AQ");
// Set the actual message value
oval = "Another message";
oaqmsg.SetValue(oval);
// Enqueue the message
msgid = oaq.Enqueue();
msgval = oval;
if ( msgid )
cout<<"Message : '"<<msgval<<"' Enqueued Successfully"<<endl;
// Close all of the objects
oaqmsg.Close();
oaq.Close();
odb.Close();
return 0;
}
Enqueuing User-Defined Type Messages:
// This function enqueues a message of user-defined type MESSAGE_TYPE
// from the msg_queue.
// Sets the message attributes and queue attributes before enqueuing
int EnqueueObject()
{
OAQMsg oaqmsg;
OAQ oaq;
ODatabase odb;
const char *msgid = 0;
OValue oval;
char text[255];
odb.Open(osess, "ExampleDB", "SCOTT", "TIGER");
// Open the 'msg_queue'
oaq.Open(odb,"msg_queue");
// Get an instance of the udt MESSAGE_TYPE
// (check out schema for details)
oaqmsg.Open(oaq, OTYPE_OBJ,"MESSAGE_TYPE");
// Enqueue a message
// Set the actual message value
OObject msgval(odb,"MESSAGE_TYPE");
msgval.SetAttrValue("SUBJECT", "BUY");
msgval.SetAttrValue("text", "ORCL >= 87");
oval = msgval;
oaqmsg.SetValue(oval);
msgid = oaq.Enqueue();
msgval.GetAttrValue("text",text,255);
if ( msgid )
cout<<"Message : '"<<text<< "' Enqueued Successfully"<<endl;
// Set Message attributes - priority,Correlation identifier etc
oaqmsg.SetPriority(-6);
oaqmsg.SetCorrelation("FOR SCOTT");
// Set the actual message value
msgval.SetAttrValue("subject", "SELL");
msgval.SetAttrValue("text", "MSFT < 120");
oval = msgval;
oaqmsg.SetValue(oval);
// Enqueue a message
msgid = oaq.Enqueue();
msgval.GetAttrValue("text",text,255);
cout<<"Message : '"<<text<<"' Enqueued Successfully"<<endl;
// Close all of the objects
oaqmsg.Close();
oaq.Close();
odb.Close();
return 0;
}
|
Copyright © 1998, 2002 Oracle Corporation. All Rights Reserved. |
|