Create a Completion Listener for Asynchronous Sending

TIBCO Enterprise Message Service provides APIs for a Message Producer to send messages either synchronously or asynchronously. For asynchronous sending, you need to implement a CompletionListener that serves as an asynchronous event handler for message send result notification.

  • Java

    Create an implementation of the CompletionListener interface, create a CompletionListener and pass that into the appropriate send method:

    /* create connection, session, producer, message */
    TibjmsCompletionListener completionListener = new
      TibjmsCompletionListener();
    msgProducer.send(destination, msg, completionListener);
    class TibjmsCompletionListener implements CompletionListener
    {
      public void onCompletion(Message msg)
      {
        /* Handle the send success case for the message */
      }
      public void onException(Message msg, Exception ex)
      {
        /* Handle the send failure case for the message */
      }
    }

    See the tibjmsMsgProducer.java sample client for a working example.

  • C

    In C, Implement an onCompletion() function to perform the desired actions when a message is sent:

    static void
    onCompletion(tibemsMsg msg, tibems_status status, void* closure)
    {
        if (status == TIBEMS_OK)
        {
            /* Handle the send success case for the message */
        }
        else
        {
            /* Handle the send failure case for the message */
        }
    }
    /* Create a connection, session, and producer. When sending, pass
     * the onCompletion() function as the tibemsMsgCompletionCallback
     */
    status = tibemsMsgProducer_AsyncSend(producer, msg, onCompletion, NULL);

    See the tibemsMsgProducer.c sample client for a working example.

  • C#

    Create an implementation of the ICompletionListener interface, create a CompletionListener and pass that into the appropriate send method.

    EMSCompletionListener completionListener = new EMSCompletionListener();
    producer.Send(destination, msg, completionListener);

    Create an implementation of the IMessageListener interface to perform actions when a message is sent:

    class EMSCompletionListener : ICompletionListener
    {
      public void OnCompletion(Message msg)
      {
        /* Handle the send success case for the message */
      }
      public void OnException(Message msg, Exception ex)
      {
        /* Handle the send failure case for the message */
      }
    }

    See the csMsgProducer.cs sample client for a working example.