Skip to Content

Thesis on enabling publish/subscribe model in SAP PI 7.1(JMS)

h1. Objective

The objective of this document is to develop proof of concept (POC) to demonstrate that SAP PI 7.1 can publish/subscribe JMS Topics though the standard JMS PI adapter doesn’t support that. Please note that I had used Hermes JMS just to prove that SAP PI can act as the publisher and subscriber of the messages but if we want to use this concept in in the real time we need to develop java client and server proxy programs  using the code snippets provided in the blog.  We are using the JMS provider of the SAP PI WAS system to accomplish the task.

 Set Up Communication between HERMES JMS and SAP PI WAS J2EE JMS Provider

About Hermes JMS

HermesJMS is an extensible console  ( that helps you interact with JMS providers making it easy to browse or search queues and topics, copy messages around and delete them. It fully integrates with JNDI letting you discover administered objects stored, create JMS sessions from the connection factories and use any destinations found. Many providers include a plugin that uses the native API to do non-JMS things like getting queue depths (and other statistics) or finding queue and topic names

Installing Hermes JMS

It is very easy to install Hermes JMS if you are installing it on the systems that have access to SAP PI. Java Web Start is the pre-requisite for installing Hermes JMS. The document assumes that java web start is already available on the machine where you plan to install HERMES JMS for simplicity. We can install and launch the HERMES JMS online using through the launch button in the website  ttp://  (

 If the installation is successful then a new screen like below will be opened:


Step 1: Download the below jars from SAP PI 7.1 into your local directory by searching the files in /usr/sap/ sap.comtcblpj_jmxapi.jar


*Step 2:  Upload the above Jar files in the Hermes JMS under class path group SAP_CP as shown below:</p><p>Click the configuration button using the options menu</p><p>!|alt=|src=!</p><p> </p><p>It should open up a window as shown below after clicking the configuration button. Click the Provider tab after that as shown below to create class path group.</p><p>!|alt=|src=!</p><p> Create class path group SAP_CP by choosing Add Group option as shown below.</p><p> </p><p>!|alt=|src=!</p><p>After pressing Add Group, the below screen should be popped up,</p><p>!|alt=|src=!</p><p>Upload the jar files that you downloaded from SAP PI 7.1 from your local directory by choosing the Add Jar(s) menu option as shown below. Press Apply at the bottom of the screen.</p><p>!|alt=|src=!</p><p>Step 2:  Create SAP JNDI Context in HERMES JMS. Create new context by clicking menu option New Context on the context node as shown below.</p><p>!|alt=|src=!</p><p>Create the SAP JNDI Context SAPCtx.</p><p>!|alt=|src=!</p><p>You need to pass the following parameters in the JNDI Initial Context for communicating with SAP PI 7.1 WAS J2EE. </p><p>loader: SAP_CP</p><p>securityCredentials :< your password></p><p>securityPrincipal: <SAP PI User Name> (Please ensure that user has SAP_J2EE_ADMIN role).</p><p>providerURL* :< ip address>:P4 port (SAP PI IP Address: J2EE P4 port-Use SMICM transaction)

*initialContextFactory: *

Browse the JNDI Context to list SAP PI 7.1 JMS Topics/Queues and SAP PI JMS 7.1 connection factories.

If the connection is successful then you should see the below message at the bottom of your screen. It takes 15 minutes to display all the JNDI resources and hence please wait with patience.

 If the HERMES JMS console finished searching then you should see the screen as below

Enable SAP PI as subscriber

Create Subscriber Topic in SAP PI

*Step 1: Login into SAP NWA using http://<PI Host Name>:<J2EE Port>/nwa with the user that has J2EE admin access.</p><p> </p><p>Step 2:**  Navigate to configure the JMS server in PI as shown below:</p><p>!|alt=|src=!</p><p> </p><p>Step 3:  *Create JMS Topic POCDemoSubscriber

Create JMS session in HERMES JMS

Step 1: Create JMS session PublishMessagetoSAPPI for publishing to a PI Topic


Assign PI topic to Hermes JMS Session

Step 1: Assign PI Topic POCDemoTopic to Hernes JMS Session !|alt=|src=!

Publish JMS Message to SAP PI

Step 1: Create sample JMS.xml on your desktop and publish the message to the SAP PI system as shown below:


 View JMS Message in SAP PI

*Step 1: Login into SAP NWA using http://<PI Host Name>:<J2EE Port>/nwa with the user that has J2EE admin access.</p><p>Step 2:**  Navigate to Java System Reports in PI as shown below:</p><p>!|alt=|src=!</p><p>Step 3:**  Navigate to java monitoring browser in PI as shown below:</p><p>!|alt=|src=!</p><p>Step 4:** * Navigate to java services as show below:


Step 5:* * Navigate to services->jms->default->TopicMessages as shown below

*Step 6:  *You can see the message is published to POCDemoTopic as show below

Code Snippets for subscribing/reading  JMS Message in SAP PI

You can’t read the message directly from SAP PI 7.1 JMS Adapter because native JMS adapter doesn’t support JMS Topics. We need to create a java client proxy to read the JMS messages from SAP PI 7.1 WAS J2EE JMS provider 1.x. The following code snippets can be useful to build the java client proxy.* </p><p>import* java.util.Properties;

import javax.naming.;</p><p>import* javax.jms.;</p><p>/*


  • This class creates a topic connection, and then


  • receives messages from the Topic.

/</p><p>public* class AsynchTopic implements javax.jms.MessageListener {

private static final String USER = “Administrator”;

private static final String PASSWORD = “admin_pass”;

private static final String SAP_NAMING_PROVIDER_URL = “localhost:50004”;

private static final String SAP_INITIAL_CONTEXT_FACTORY_IMPL =


      TopicConnectionFactory topicConnectionFactory = null;

      TopicConnection topicConnection = null;

      Topic topic = null;

      TopicSession topicSession = null;

      TopicSubscriber topicSubscriber = null;

      TextMessage textMessage1 = null;

      Boolean flag = “true”;



  • Get InitialContext with default values.


private InitialContext getInitialContext() {

try {

                  // set the properties for the InitalContext

                  Properties properties = new Properties();




                  properties.put(Context.PROVIDER_URL, SAP_NAMING_PROVIDER_URL);

                  properties.put(Context.SECURITY_PRINCIPAL, USER);

                  properties.put(Context.SECURITY_CREDENTIALS, PASSWORD);

                  // initialize and return the InitalContext with the specified 


return new InitialContext(properties);

            } catch (NamingException ne) {

                  System.out.println(“NamingException: ” + ne);


return null;




  • Initializes JMS.


private void initJMS() {

try {

                  InitialContext context = getInitialContext();

                  // look up the TopicConnectionFactory

                  topicConnectionFactory =

                        (TopicConnectionFactory) context.lookup(

                              ” jmsfactory/default/TopicConnectionFactory”);

                  // create topic connection

                  topicConnection = topicConnectionFactory.createTopicConnection();

                  // start the connection


            } catch (NamingException ne) {

                  System.out.println(“NamingException: ” + ne);

            } catch (JMSException jmse) {

                  System.out.println(“JMSException: ” + jmse);





  • Closes all resorces used in this test. This should be called


  • when you want to finish using JMS.


private void closeJMS() {

try {

                  //closes the jms topic session


                  //closes the jms topic connection


            } catch (JMSException jmse) {

                  System.out.println(“JMSException: ” + jmse);





  • Create a topic and receive messages


  • and then close the connection.


public void aMethod() {

try {

                  // initializes all important data that will be used.


                  // create topic session

                  topicSession =




                  // topic session’s topic

                  topic = topicSession.createTopic(“POCDemoTopic”);

                  //create subscriber

                  topicSubscriber = topicSession.createSubscriber(topic);


            //topic subscriber is waiting for messages.

while (flag) {

try {


                        } catch (Exception e) {




                  // clears all resources used by JMS


            } catch (JMSException e) {






  • Implemented from the MessageListener interface.


  • Allows for asynchronous message receipt. Here you can


  • unpack the message.


  • @param message the newly received message


public void onMessage(Message message) {

            // do something with the message received.

try {


                        “Message reveived: ” + ((TextMessage) message).getText());

                  flag = false;

            } catch (JMSException jmse) {





 Enabling SAP PI as publisher

 Create JMS session in HERMES JMS


 Assign PI Topic to HERMES JMS Session

Please note that I have used the same topic POCDemoTopic for simplicity. It is not a mandatory requirement for publishing messages.

 Subscribe HERMESJMS Topic to PI JMS Message

 View the SAP PI JMS Messages in HERMESJMS


You must be Logged on to comment or reply to a post.
  • Hi Sravya

    nice blog. I've been busy setting this up for a while and this nicely sums up the steps to take.

    FYI: to enable SecureJMS (over P4SEC) one needs to add the iaik_jce.jar, iaik_jsse.jar, iaik_smime.jar and iaik_ssl.jar to the SAP_CP Provider classpath and change the ProviderURL to p4s://host:p4sec_port. And of course in SMICM the P4SEC port must be enabled (which requires SSL configuration first).

    • It is always a pleasure to know that some one on the other side of the globe is exactly thinking on the same lines:) though it has been a while since I blogged:)
    • It is always a pleasure to know that some one on the other side of the globe is exactly thinking on the same lines:) though it has been a while since I blogged:)
      • It is always a pleasure to know that some one on the other side of the globe is exactly thinking on the same lines:) though it has been a while since I blogged:)
  • That is a good blog Shravya!!

    JMS is available on Netweaver Server. So do we really need PI for this? I did not see any PI related work here.. Just for clarification.

    Vijay K

    • Yes but It is an intelligent question. You definetly need PI because you need to read/send the JMS message and process the message in SAP PI. Hermes JMS can't be used for production runs.

      If you are just integrating two messaging queue based applications then you don't need but otherwise you need to.