dotConnect for Oracle Documentation
Devart.Data.Oracle Namespace / OracleQueue Class / Listen Method / Listen(OracleQueueAgentCollection,Int32,OracleQueueDeliveryMode,OracleQueueDeliveryMode) Method
List of agents to listen for.
Time out for the listen call in seconds. By default, the call will block forever.
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.)
Returns the message type along with the queue and consumer for which there is a message (only for Oracle 10.2 and greater).
Example

In This Topic
    Listen(OracleQueueAgentCollection,Int32,OracleQueueDeliveryMode,OracleQueueDeliveryMode) Method
    In This Topic
    Listens on one or more queues on behalf of a list of agents.
    Syntax

    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).

    Return Value

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

    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also