Feeds

Programming message services in Java

Asynchronous interactions seem to be the way of the future

The Power of One Brief: Top reasons to choose HP BladeSystem

Deployment and execution

To deploy to JBoss, the ear file can be copied to the ${JBoss.home}/server/default/deploy directory and the JBoss server started. As JBoss starts up, it will discover the new jar file and deploy it automatically (which makes deploying to JBoss very easy). As the JBoss server is being started up, you should see messages telling you that it is deploying the new ear file and linking the MDB to the queue.

After the JBoss server has fully started up, you can start the client application. I ran the NewsClient form within the Eclipse IDE, specifying the j2ee.jar file of my Enterprise Java installation for the JMS classes and including a command line string to send to the MDB. In my case, this string was the message “Hello”.

The end result is that the string “Hello” is printed out in the JBoss console window, as illustrated below:

20:03:45,656 INFO  [Server] JBoss (MX MicroKernel) [4.2.1.GA (build: 
SVNTag=JBoss_4_2_1_GA date=200707131605)] Started in 52s:235ms 
20:04:43,468 INFO  [STDOUT] In the onMessage method(Hello)

There you have it; you’ve now stepped through and run a simple JMS based asynchronous application.

EJB3 versus old MDBs

It is interesting to compare this with what I would have had to define prior to EJB3. With older message driven beans I would have had to implement the javax.ejb.MessageDrivenBean interface as well as the MessageListener interface. It would also have been necessary to define any application server specific files used to define the destination type and destination of the queue.

For example, as well as the default ejb-jar.xml JAR file; with JBoss I would also have had to define a JBoss.xml file. The first file, the JAR file, would have been used to specify that this was a MDB and that it should be bound to a queue. The JBoss specific file would then have been used to bind the MDB to the appropriate queue (the queue/testQueue). The two files, as would be defined for EJB 2.0 are presented below.

The ejb-jar.xml file:

<ejb-jar>
    <enterprise-beans>
        <!-- Some descriptors omitted -->
        <message-driven>
            <ejb-name>DebugMonitor</ejb-name>
            <ejb-class>util.DebugMonitorBean</ejb-class>
            <message-selector>JMSType = ‘DEBUG’</message-selector>
            <transaction-type>Container</transaction-type>
            <acknowledge-mode>Auto-acknowledge</acknowledge-mode>
            <message-driven-destination>
               <destination-type>javax.jms.Queue</destination-type>
            </message-driven-destination>
         </message-driven>
    </enterprise-beans>
    <!-- Some descriptors omitted -->
</ejb-jar>

The JBoss.xml file

<?xml version="1.0"?>
<JBoss>
   <enterprise-beans>
       <!-- Some descriptors omitted -->
       <message-driven>
           <ejb-name>TestMonitor</ejb-name>
           <configuration-name>
              Standard Message Driven Bean
           </configuration-name>
           <destination-jndi-name>queue/queueTest</destination-jndi-name>
           <container-pool-conf>
              <MaximumSize>1</MaximumSize>
              <MinimumSize>1</MinimumSize>
           </container-pool-conf>
       </message-driven>
    </enterprise-beans>
</JBoss>

Conclusion

In this column, we’ve looked at how asynchronous applications can be defined using the JMS API. The example, although very simple, is essentially the same as used by any asynchronous JMS based applications. As you can see the actual implementation is very straight forward and particularly with EJB3, simple to implement. ®

Securing Web Applications Made Simple and Scalable

More from The Register

next story
HIDDEN packet sniffer spy tech in MILLIONS of iPhones, iPads – expert
Don't panic though – Apple's backdoor is not wide open to all, guru tells us
Apple fanbois SCREAM as update BRICKS their Macbook Airs
Ragegasm spills over as firmware upgrade kills machines
NO MORE ALL CAPS and other pleasures of Visual Studio 14
Unpicking a packed preview that breaks down ASP.NET
Captain Kirk sets phaser to SLAUGHTER after trying new Facebook app
William Shatner less-than-impressed by Zuck's celebrity-only app
Do YOU work at Microsoft? Um. Are you SURE about that?
Nokia and marketing types first to get the bullet, says report
Microsoft takes on Chromebook with low-cost Windows laptops
Redmond's chief salesman: We're taking 'hard' decisions
Cheer up, Nokia fans. It can start making mobes again in 18 months
The real winner of the Nokia sale is *drumroll* ... Nokia
prev story

Whitepapers

Designing a Defense for Mobile Applications
Learn about the various considerations for defending mobile applications - from the application architecture itself to the myriad testing technologies.
How modern custom applications can spur business growth
Learn how to create, deploy and manage custom applications without consuming or expanding the need for scarce, expensive IT resources.
Reducing security risks from open source software
Follow a few strategies and your organization can gain the full benefits of open source and the cloud without compromising the security of your applications.
Boost IT visibility and business value
How building a great service catalog relieves pressure points and demonstrates the value of IT service management.
Consolidation: the foundation for IT and business transformation
In this whitepaper learn how effective consolidation of IT and business resources can enable multiple, meaningful business benefits.