Configure publish and subscribe messaging for a single Liberty server
We can configure publish/subscribe messaging from a topic space on a single Liberty server.
- Configure the messaging features in the server.xml file.
To perform a JNDI lookup, then we 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>
- 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>
- 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"/>
- 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>
- Declare an activation specification for the message-driven beans 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 that the application name is applicable only if the bean is packaged within an EAR file.
- Optional: We can configure the wasJmsSecurity-1.0 feature to enable the wasJmsServer-1.0 feature work in a secure mode.
See Enable secure JMS messaging for Liberty. The publish/subscribe messaging is configured for a topic queue.