Show TOC

Procedure documentationSending Messages to Services Locate this document in the navigation structure

Procedure

This section describes how to send messages to a service.

Sync Service
  1. Create a message.

    Syntax Syntax

    1. import com.sap.netweaver.rtmf.messagingimpl.exception.RTMFException;
    2. import com.sap.netweaver.rtmf.messagingimpl.messages.RTMFMessage;
    3. import com.sap.netweaver.rtmf.messagingimpl.messages.RTMFMessageFactory;
    4. import com.sap.netweaver.rtmf.messagingimpl.messages.RTMFMessageType;
    5. import com.sap.netweaver.rtmf.messagingimpl.services.RTMFSyncService;
    6. RTMFMessage message = RTMFMessageFactory.getMessage(RTMFMessageType.RTMFMessageType);
    End of the code.
  2. Add parameters to the message, if necessary.

    Syntax Syntax

    1. message.putParam("param1","value1");
    End of the code.
  3. Get an instance of the sync service to which you want to send a message.

    Syntax Syntax

    1. RTMFSyncService service = (RTMFSyncService)
      
      
    2. RTMFServices.getRTMFServicesInstance().getService("MySyncService");
    End of the code.
  4. Send the message.

    Syntax Syntax

    1. List responseList = service.onMessageArrived(message);
    End of the code.

    The method returns a List of messages (RTMFMessage).

Topic and Queue Service
  1. Create a message.

    Syntax Syntax

    1. RTMFMessage message = RTMFMessageFactory.getMessage(RTMFMessageType.RTMFMessageType);
    End of the code.
  2. Add parameters to the message, if necessary.

    Syntax Syntax

    1. message.putParam("param2","value2");
    End of the code.
  3. Send the message to the service.

    The following sends a message to a topic service:

    Syntax Syntax

    1. message.publishToTopic("MyRTMFService");
    End of the code.

    The following sends a message to a queue service:

    Syntax Syntax

    1. message.sendToQueue("MyRTMFService");
    End of the code.

After sending the message, the application continues with its logic. The topic or queue service can react to the message by publishing an event, to which the application can subscribe.

Generic API

The RTMFMessage class provides a method for sending a message to a service when you do not know the type of service.

The following sends a message to an RTMF service, no matter the service type:

Syntax Syntax

  1. message.sendToService("MyRTMFService");
End of the code.

For a sync service, the method waits for a return value. For topic and queue services, the application continues with its logic.