Configuring publish and subscribe messaging for a single Liberty server

You can configure publish/subscribe messaging from a topic space on a single Liberty server.

Procedure

  1. Configure the messaging features in the server.xml file. If you want to perform a JNDI lookup, then you must also add the jndi-1.0 feature.
    <featureManager>
       <feature>wasJmsServer-1.0</feature>
       <feature>wasJmsClient-2.0</feature>
       <feature>jndi-1.0</feature>
    </featureManager>
  2. Configure the messaging engine to create a topic space, called SPORTS, as given in the following example.
    <messagingEngine>
        <topicSpace id="SPORTS"
          forceReliability="ReliablePersistent"
          maintainStrictOrder="true"
          maxMessageDepth="5000">
        </topicSpace>
    </messagingEngine>
    
  3. Declare a topic connection factory resource to create a connection to the messaging engine as given in the following example.
    <jmsTopicConnectionFactory jndiName="jms/libertyTCF" connectionManagerRef="ConMgr1">
        <properties.wasJms
          clientID="clientId"  
          nonPersistentMapping="ExpressNonPersistent"  
          password="password"  
          persistentMapping="ReliablePersistent"/>
    </jmsTopicConnectionFactory>
    <connectionManager id="ConMgr1" maxPoolSize="2"/>
  4. Declare a topic space resource to create a Publisher/Subscriber session to the TopicSpace, SPORTS.
    <jmsTopic jndiName="jms/libertyTopic">
        <properties.wasJms topicName="Cricket"
          deliveryMode="Application" 
          timeToLive="500000" 
          priority="1"
          readAhead="AsConnection" />
    </jmsTopic>
  5. Declare an activation specification for the message-driven beans that are deployed on Liberty. The message-driven beans use the activation specification to asynchronously consume messages that are published to the jmsTopic resource.
    <jmsActivationSpec id="JMSSample/JMSApp/SampleMDB">
        <properties.wasJms destinationRef="jms/libertyTopic" />
    </jmsActivationSpec>
    The ID value must be given in the following format: application name/module name/bean name format, where application name is the name of the application that is deployed, module name is the name of the module in which the bean is packaged, and bean name is the ejb-name of the enterprise bean. Ensure that the destinationRef attribute is pointing to a valid jmsTopic resource ID.
    Note: The application name is applicable only if the bean is packaged within an EAR file.
  6. Optional: You can configure the wasJmsSecurity-1.0 feature to enable the wasJmsServer-1.0 feature work in a secure mode. For more information, see Enabling secure JMS messaging for Liberty.
    The publish/subscribe messaging is configured for a topic queue.