Listen(OracleQueueAgentCollection,Int32,OracleQueueDeliveryMode,OracleQueueDeliveryMode,OracleConnection) Method
Listens on one or more queues on behalf of a list of agents.
Parameters
- agents
- List of agents to listen for.
- waitTimeout
- Time out for the listen call in seconds. By default, the call will block forever.
- listenDeliveryMode
- The caller specifies whether it is interested in persistent, buffered messages or both types of messages, specifying a delivery mode. (Only for Oracle 10.2 and greater.)
- messageDeliveryMode
- Returns the message type along with the queue and consumer for which there is a message (only for Oracle 10.2 and greater).
- connection
- A OracleConnection that represents the connection to an instance of Oracle server.
Return Value
Agent with a message available for consumption.
The following example demonstrates the usage of
Listen(OracleQueueAgentCollection,Int32,OracleQueueDeliveryMode,OracleQueueDeliveryMode,OracleConnection) method.
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();
Dim oracleConnection As New OracleConnection("User Id=system;Password=manager;Server=ora11;")
oracleConnection.Open()
Dim oracleQueueTable As New OracleQueueTable("QUEUE_TABLE_MESSAGE", oracleConnection)
' Set the table to serve multiple consumers.
oracleQueueTable.Options.MultipleConsumers = True
oracleQueueTable.Options.PayloadTypeName = "RAW"
oracleQueueTable.CreateQueueTable()
Dim oracleQueueAdmin As New OracleQueueAdmin("MESSAGE_QUEUE", "QUEUE_TABLE_MESSAGE", oracleConnection)
oracleQueueAdmin.CreateQueue()
oracleQueueAdmin.StartQueue()
oracleQueueAdmin.AddSubscriber(New OracleQueueAgent("Bob"))
Dim oracleEnqueueQueue As New OracleQueue("MESSAGE_QUEUE", oracleConnection)
Dim message As New OracleQueueMessage()
message.StringPayload = "Message for Bob."
message.MessageProperties.RecipientList.Add(New OracleQueueAgent("Bob"))
oracleEnqueueQueue.Enqueue(message)
Dim oracleDequeueQueue As New OracleQueue()
oracleDequeueQueue.Connection = oracleConnection
Dim coll As New OracleQueueAgentCollection()
coll.Add(New OracleQueueAgent("Bob", "MESSAGE_QUEUE"))
' listening only for 60 seconds instead of blocking thread forever
Dim agent As OracleQueueAgent = 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()