Show TOC

Publishing EventsLocate this document in the navigation structure

Use

An application can communicate with clients by publishing an event. The event is given a name and is accompanied by a message, which can include parameters.

Clients that subscribe to an event are notified when the event is published, and can retrieve the message parameters passed with the event. For more information about subscribing to events, see Subscribing to Events with Web Dynpro .

Procedure
  1. Create a message.

                      import com.sap.netweaver.rtmf.messagingimpl.exception.RTMFException;
                      import com.sap.netweaver.rtmf.messagingimpl.messages.RTMFMessage;
                      import com.sap.netweaver.rtmf.messagingimpl.messages.RTMFMessageFactory;
                      import com.sap.netweaver.rtmf.messagingimpl.messages.RTMFMessageType;
                      RTMFMessage message = RTMFMessageFactory.getMessage();
                   
  2. Add parameters to the message, if required.

                      message.putParam("param","value");
                   

    For more information, see RTMF Messages .

  3. Publish an event by calling the message's publishEvent() method. The event name is passed as a parameter.

                      try {
                              message.publishEvent("myMessage");
                      } catch (RTMFException e) {
                              e.printStackTrace();
                      }
                   

Any client that subscribed to the event is notified, and receives the message and its parameters.

Publishing to a Specific User

When you publish an event, anyone who subscribes to the event is alerted and receives the accompanying message, which can create a security problem.

Instead of publishing an event to all subscribers, you can publish an event to a specific user by specifying the name of the event and the user's unique ID. The user must be subscribed to the event.

The following publishes the myMessage event to the Administrator user only:

               message.publishEventToUser("myMessage","Administrator");