OracleConnection oracleConnection = new OracleConnection(
"User Id=system;Password=manager;Server=ora11;");
oracleConnection.Open();
OracleQueueTable oracleQueueTable = new OracleQueueTable(
"QUEUE_TABLE_MESSAGE", oracleConnection);
// Set the table to serve multiple consumers.
oracleQueueTable.Options.MultipleConsumers = true;
oracleQueueTable.Options.PayloadTypeName = "RAW";
oracleQueueTable.CreateQueueTable();
OracleQueueAdmin oracleQueueAdmin = new OracleQueueAdmin(
"MESSAGE_QUEUE", "QUEUE_TABLE_MESSAGE", oracleConnection);
oracleQueueAdmin.CreateQueue();
oracleQueueAdmin.StartQueue();
oracleQueueAdmin.AddSubscriber(new OracleQueueAgent("Bob"));
OracleQueue oracleEnqueueQueue = new OracleQueue("MESSAGE_QUEUE", oracleConnection);
OracleQueueMessage message = new OracleQueueMessage();
message.StringPayload = "Message for Bob.";
message.MessageProperties.RecipientList.Add(new OracleQueueAgent("Bob"));
oracleEnqueueQueue.Enqueue(message);
OracleQueue oracleDequeueQueue = new OracleQueue();
oracleDequeueQueue.Connection = oracleConnection;
OracleQueueAgentCollection coll = new OracleQueueAgentCollection();
coll.Add(new OracleQueueAgent("Bob", "MESSAGE_QUEUE"));
// listening only for 60 seconds instead of blocking thread forever
OracleQueueAgent agent = oracleDequeueQueue.Listen(coll, 60);
Console.WriteLine("The following consumer received a message: {0}", agent.Name);
oracleDequeueQueue.QueueName = agent.Address;
oracleDequeueQueue.DequeueOptions.ConsumerName = agent.Name;
Console.WriteLine("The message: {0}", oracleDequeueQueue.Dequeue().StringPayload);
oracleQueueAdmin.StopQueue();
oracleQueueAdmin.DropQueue();
oracleQueueTable.DropQueueTable();
oracleConnection.Close();