Solace Topic Publisher Subscriber Spring Example

Solace Topic Publisher Subscriber Spring Example

In last tutorial you saw how to publish and Subscribe message on Queue using Solace by Spring framework. In this tutorial you will see how to publish and subscribe on Topic using Spring framework and JMS API.

Tools needed:

  • Eclipse (Any latest version)
  • JDK 1.8
  • Solace 7.1.2.230 (This assumes you have already Solace hardware setup and running)
  • Maven 3.2.1 (You could you any latest version)

I hope you already have Solace hardware setup and administrator provide you below information OR in other-words whenever either you or your administrator do Solace on-boarding you get below information (Note for demo purpose I put JavaHonk Solace information)

  • VPNName: Javahonk_VPN
  • MessagingURL : JavaHonk.com:55555
  • JMS-Persistent Connection Factory(Window size 1) :JavaHonk_VPN_CF (Very important: Use for queue)
  • JMS-NonPersistent Connection Factory(Window size 255); JavaHonk_VPN_NP_CF
  • JMS-Direct Connection Factory(direct-no Ack back); JavaHonk_VPN_DIRECT_CF (Very important: Use for Topic)

Once Solace on-boarding done then you will create Queue or Topic and Users where you will be publish or Subscriber for message. This is also Solace administrator responsibility to give you URL which can be use to create Users, Queue or Topic.

JNDI Name: Usually JNDI name will be same as QUEUE or Topic name but its up to you or whoever is create queue to choose the name.

To create Queue or Topic you will have something like below interface (Note: This is sample and your interface or URL will be completely different and it all depends on company to company):

Solace Topic Publisher Subscriber Spring Example

Solace Topic Publisher Subscriber Spring Example

Now you have enough information to go ahead to create Solace application. This demo will show you how to send message on Topic and Consume it using JMS API and Spring framework.

  • Create maven project name: SolaceTopicJMSPubSubSpring below is final structure:

Solace Topic Publisher Subscriber Spring Example

  • Solace jars:

Solace Topic Publisher Subscriber Spring Example

  • All other dependencies: pom.xml:

  • For logging: log4j2.xml:

  • Solace properties file: Here you could mentioned all Solace connection properties: javahonk-solace.properties (Note: Please replace this properties with your actual Solace properties):

  • spring-context.xml: Spring framework context file to load all configuration:

  • javahonk-solace-context.xml: To keep it clean I have created separate context file to keep all Solace related beans:

  • Please note above I have commented out below beans:

Solace Topic Publisher Subscriber Spring Example

  • SolaceConnectionFactory.java: Main class to load initial context and create connection to Solace system:

  • SolaceMessagePublisher.java: Separate publisher to publish message on Topic:

  • SolaceMessageSubscriber.java: Class to subscriber message on the Topic:

  • SolaceMessagePublisherSubscriber.java: Both publisher and Subscriber put together in this class and I have created this because sometimes we do both publish and consume on the topic:

  • JavahonkSolacePublisherTest.java: Main class for test.

  • To start and run the application right click JavahonkSolacePublisherTest.java class and Run As java application: If everything is setup correctly you will below output on the console:

Solace Topic Publisher Subscriber Spring Example

Download project: SolaceTopicJMSPubSubSpring

For more information please visit Solace official documentation here

Leave a Reply

Your email address will not be published. Required fields are marked *