Show TOC

Creating ServicesLocate this document in the navigation structure

Use

This section describes how to create an RTMF service.

Procedure
  1. Create a class that extends one of the following classes:

    • Sync Service: RTMFSyncService

    • Topic Service: RTMFTopicService

    • Queue Service: RTMFQueueService

                      import com.sap.netweaver.rtmf.messagingimpl.messages.RTMFMessage;
                      import com.sap.netweaver.rtmf.messagingimpl.services.RTMFQueueService;
                      import com.sap.netweaver.rtmf.messagingimpl.services.RTMFSyncService;
                      import com.sap.netweaver.rtmf.messagingimpl.services.RTMFTopicService;
                      public class MyRTMFService extends RTMFSyncService {
    
    
                              // ...
    
    
                      }
                   
  2. Create a constant whose value is a unique name for the service.

                      private static final String myName = "MyRTMFService";
                   
  3. Implement a constructor with no parameters that calls the constructor of the superclass.

                      public MyRTMFService() {
                              super(myName);
                      }
                   
  4. Implement the following methods:

    • onMessageArrived () : This method is executed when a service receives a message.

    • onUserMessageArrived() : This method is executed when a service receives a message from a client. The user's logon ID is passed to the method (or null if the user is not authenticated).

      Note

      This method is for future use. However, the method is defined as abstract, so you must provide an empty implementation.

    The following example checks the task parameter of the message and executes the register() method if the task parameter is register . Afterward, the method publishes an event called myMessage .

                      protected List onMessageArrived(RTMFMessage message) {
                              if (message.getParamValue("task").equals("register")) {
                                      register(message);
                              }
    
    
                              try {
                                      message.publishEvent("myMessage");
                              } catch (Exception e) {
                                      e.printStackTrace();
                              }
    
    
                              return null;
                      }
                   
    Note

    For topic and queue services, the method is protected because applications do not call this method directly. The return value is irrelevant.

    For sync services, the method is public because applications call the method directly and wait for the return value.

  5. Implement the method onClusterMessageArrived() , if necessary. This method is used by services to update the service instances on the other node.

    The method gets executed when one of the service instances on one of the cluster nodes calls the method publishToCluster().

                      protected void onClusterMessageArrived(RTMFMessage message) {}
                   

    For more information, see Synchronizing Services .

Other Tasks

You can implement any logic within your service. The following are RTMF-related tasks that you may want to perform in the service:

  • Retrieve Parameters: You can examine the parameters of the received message, and perform different tasks based on the values.

    For more information, see RTMF Messages .

  • Publish Events: You can react to the message by publishing events to subscribing applications.

    For more information, see Publishing Events .

  • Publish to Cluster: An instance of a service may need to update the instances on the other cluster nodes.

    For more information see Synchronizing Services .

If you override the service's destroy() method - called when the service is shut down - then you must call the destroy method of the superclass, that is, super.destroy() .

Starting the Service

To start the RTMF service, create and store an instance of the service, for example, in a JEE or portal service.

For example, you can define a portal service with an interface IStartRTMFPortalService and an implementation class StartRTMFPortalService . In the init() method of StartRTMFPortalService , create the RTMF service. The following is a section of StartRTMFPortalService :

               public class StartRTMFPortalService implements IStartRTMFPortalService{


                       private IServiceContext mm_serviceContext;
                       private MyRTMFService myRTMFService;


                       public void init(IServiceContext serviceContext) {
                               mm_serviceContext = serviceContext;
                               myRTMFService = new MyRTMFService();
                       }


                       // ... 


               }