Over a million developers have joined DZone.

JMS Mbean Configuration in Spring Integration

· Java Zone

Learn more about the advantages of moving from a monolithic to microservices architecture.  Brought to you in partnership with IBM.

Spring IntegrationJMS message-driven-channel-adapter has good MBean support through  DefaultMessageListenerContainer where we can control the flow of messages to the subscribers. In this blog I will demonstrate some of these capabilities. For people in hurry, here is the code @ Github,

  • Download activemq and unzip it
  • run activemq.bat under <activemq-home>/bin folder
  • Go to browser and type http://localhost:8161/admin/queues.jsp, create a new queue “MyQueue”
  • Get the latest code from Github
  • Build the war file using “mvn clean package”
  • Deploy the war file in Spring tomcat container
  • “Send to” message to MyQueue in admin console of activemq in the browser
  • You notice the message gets consumed
  • Open jconsole.exe under jdk bin directory
  • Login in to Remote process “localhost:6969″, uid: admin, password: “springsource”
  • Go to MBean tab and expand spring.application/JMSContainer/testQueueContainer/Operation, click on stop operation
  • Again “Send to” message to MyQueue in admin console of activemq in the browser, if you notice, the message is not consumed
  • Go to MBean tab and expand spring.application/JMSContainer/testQueueContainer/Operation, click on start operation
  • Again “Send to” message to MyQueue in admin console of activemq in the browser, if you notice, the message got consumed

Details: Spring Integration JMS Mbean configuration

In a typical enterprise IT production environment, you need to control the message processing by the queue subscribers. A typical scenario would be, if there is a an issue with the subscriber and we want to pause the subscriber to troubleshoot it, we need a mechanism for this as below.

Expose Lifecycle interface of DefaultMessageListenerContainer

<bean id="queue.exporter" class="org.springframework.jmx.export.MBeanExporter">
<property name="beans">
<map>
<entry key="spring.application:type=JMSContainer,name=testQueueContainer" value-ref="queueContainer" />
</map>
</property>
<property name="assembler">
<bean class="org.springframework.jmx.export.assembler.InterfaceBasedMBeanInfoAssembler">
<property name="managedInterfaces">
<value>org.springframework.context.Lifecycle</value>
</property>
</bean>
</property>
</bean>

InterfaceBasedMBeanInfoAssembler class expose an interface of a particular class as a Mbean, in the above example it exposes Lifecycle

Managing JMS subscriber in JConsole

Managing JMS subscriber using JConsole

Managing JMS subscriber using JConsole

When you click on start operation, and click on start button, it will start the subscriber to listen to the message and when you click on stop, it will pause the subscriber.

Conclusion

MBean is a powerful way to expose some of the capabilities of Spring Integration’s various Channel Adapter, so that you can control them from various tools which are MBean aware, like JConsole, Hyperic . We can also expose, Log4J Mbean so that we can change the log level in the production system. More on this in my subsequent blog.



From Idea to Application gives you the architecture to quickly build, manage and run a range of applications (web, mobile, big data, new smart devices, etc.) on an open-standard, cloud-based platform. See why developers are using IBM Bluemix. Brought to you in partnership with IBM.

Topics:

Published at DZone with permission of Krishna Prasad, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}