Over a million developers have joined DZone.
Platinum Partner

JMS Mbean Configuration in Spring Integration

· Java Zone

The Java Zone is brought to you in partnership with JetBrains.  Learn more about Kotlin, a new programming language designed by JetBrains to solve problems that software developers face every day.

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.



The Java Zone is brought to you in partnership with JetBrains.  Discover how powerful static code analysis and ergonomic design make development not only productive but also an enjoyable experience.

Topics:

Published at DZone with permission of Krishna Prasad , DZone MVB .

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}