Feeds

Programming message services in Java

Asynchronous interactions seem to be the way of the future

Internet Security Threat Report 2014

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. ®

Security for virtualized datacentres

More from The Register

next story
Microsoft WINDOWS 10: Seven ATE Nine. Or Eight did really
Windows NEIN skipped, tech preview due out on Wednesday
Business is back, baby! Hasta la VISTA, Win 8... Oh, yeah, Windows 9
Forget touchscreen millennials, Microsoft goes for mouse crowd
Apple: SO sorry for the iOS 8.0.1 UPDATE BUNGLE HORROR
Apple kills 'upgrade'. Hey, Microsoft. You sure you want to be like these guys?
ARM gives Internet of Things a piece of its mind – the Cortex-M7
32-bit core packs some DSP for VIP IoT CPU LOL
Microsoft on the Threshold of a new name for Windows next week
Rebranded OS reportedly set to be flung open by Redmond
Lotus Notes inventor Ozzie invents app to talk to people on your phone
Imagine that. Startup floats with voice collab app for Win iPhone
'Google is NOT the gatekeeper to the web, as some claim'
Plus: 'Pretty sure iOS 8.0.2 will just turn the iPhone into a fax machine'
prev story

Whitepapers

Forging a new future with identity relationship management
Learn about ForgeRock's next generation IRM platform and how it is designed to empower CEOS's and enterprises to engage with consumers.
Storage capacity and performance optimization at Mizuno USA
Mizuno USA turn to Tegile storage technology to solve both their SAN and backup issues.
The next step in data security
With recent increased privacy concerns and computers becoming more powerful, the chance of hackers being able to crack smaller-sized RSA keys increases.
Security for virtualized datacentres
Legacy security solutions are inefficient due to the architectural differences between physical and virtual environments.
A strategic approach to identity relationship management
ForgeRock commissioned Forrester to evaluate companies’ IAM practices and requirements when it comes to customer-facing scenarios versus employee-facing ones.