Show TOC

Procedure documentationPublishing Events Locate this document in the navigation structure

 

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.

    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. RTMFMessage message = RTMFMessageFactory.getMessage();
    End of the code.
  2. Add parameters to the message, if required.

    Syntax Syntax

    1. message.putParam("param","value");
    End of the code.

    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.

    Syntax Syntax

    1. try {
    2. 	message.publishEvent("myMessage");
    3. } catch (RTMFException e) {
    4. 	e.printStackTrace();
    5. }
    End of the code.

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:

Syntax Syntax

  1. message.publishEventToUser("myMessage","Administrator");
End of the code.