With all of the hype surrounding Web services these days, you don't hear much about message-oriented middleware (MOM) anymore. This is a shame, because messaging solutions really do have a lot to offer in terms of reliability and scalability. But that's another lesson for another day.
Assuming you've already bought into all that MOM has to offer, then you're probably at least familiar with the Java™ Message Service (JMS) on some level. JMS is a vendor-neutral API that can be used to interact with messaging systems. As a Java™ developer, this means that you can write a piece of code to interact with IBM's WebSphere MQ and then turn around and use that same piece of code to process messages on SAP's JMS provider. This is analogous to the use of other generic APIs such as JDBC, JavaMail, and JNDI.
While the JMS API defines rich semantics for processing messages, it doesn't have a lot to say about how to carry out certain administrative tasks. Frequently, these operations are performed using proprietary extensions and/or JMX MBeans. But what if you just want a simple administrative console to perform simple operations like browsing a queue, adding messages/removing messages, and so on?
Coming up with a solution for this has been something I've been playing around with off and on for quite some time. After giving the open-source HermesJMS tool an extended look, I ultimately decided that I needed something a little more specialized for what I was trying to accomplish. In this blog, I will present a custom Web Dynpro-based management tool that can be used to perform simple administrative tasks on the default SAP JMS provider.
The Solution
The solution was developed using Web Dynpro for Java on an SAP NetWeaver AS Java 7.1 stack. The core functionality is implemented exclusively using the JMS and JNDI APIs, so no proprietary extensions are required to install this solution. The following figure shows the main selection screen area where you can search for JMS queues that you wish to manage. The results table allows you to view messages, create sample messages, and remove messages.
Searching for Queues
If you can't remember the name of the queue you want to manage, you can browse to it using the advanced search capabilities built into the tool. This search help lets you search for queues using regular expression syntax (see the figure below).
Creating Messages
You can click on the Create button to create a new message. Here, you will be prompted with an input mask that allows you to create a TextMessage. This could include a sample XML snippet, or some other text payload of your choosing. As the source code is provided, you could conceivably develop support for other message type as necessary.
Viewing Messages
You can view a JMS message by selecting it in the table and clicking on the View Message button. The figure below shows what the screen looks like. In addition to the JMS message ID and timestamp, you can also see custom header properties that were added to the message.
Removing Messages
To remove a message, simply select it in the table and click on the Remove Message button. One thing to keep in mind here is that this function will only work if there are no registered listeners (e.g. MDBs, and so on) on the queue in question; otherwise the operation will fail. This is because JMS does not provide API methods for removing messages. Therefore, the only portable way of achieving this is to create an ad hoc consumer that uses message selectors to filter on the selected message IDs.
Purging the Queue
You can think of the Purge Queue button as a mass deletion operation that is designed to remove all messages from the queue. This function is also subject to the same constraints as the Remove Message function.
Security
As you can imagine, many of these operations are powerful and must be secured against novice users who could potentially wreak havoc on the system. To guard against this, a series of UME actions were defined to protect access to the more sensitive functions. The figure below shows the creation of a sample UME role called JMSAdministrator that contains these actions. You can mix and match these actions in different roles as needed.
Where can I go to get it?
The final solution is bundled as an SCA archive and available for download here. I hope that this will be of some use to you, and thanks for reading.