dotConnect for Oracle Documentation
Devart.Data.Oracle Namespace / OracleQueue Class / Listen Method / Listen(OracleQueueAgentCollection,OracleConnection) Method
List of agents to listen for.
A OracleConnection that represents the connection to an instance of Oracle server.
Example

In This Topic
Listen(OracleQueueAgentCollection,OracleConnection) Method
In This Topic
Listens on one or more queues on behalf of a list of agents.
Syntax
'Declaration
 
Public Overloads Shared Function Listen( _
   ByVal agents As OracleQueueAgentCollection, _
   ByVal connection As OracleConnection _
) As OracleQueueAgent
 

Parameters

agents
List of agents to listen for.
connection
A OracleConnection that represents the connection to an instance of Oracle server.

Return Value

Agent with a message available for consumption.
Example
The following example demonstrates the usage of Listen(OracleQueueAgentCollection,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()
See Also