Weblogic Authors: Yeshim Deniz, Elizabeth White, Michael Meiner, Michael Bushong, Avi Rosenthal

Related Topics: Weblogic

Weblogic: Article

Advanced JMS Design Patterns for WebLogic Server Environments Part 2

Advanced JMS Design Patterns for WebLogic Server Environments Part 2

Part 1 of this article (WLDJ, Vol. 1, issue 8) explored third-party Java Message Service (JMS) integration into WebLogic Server (WLS) and addressed related issues. In Part 2, we'll implement transactional JMS design patterns using SonicMQ and the WebLogic Server Adapter (WLSAdapter) as the JMS solution. Included in this discussion are the message-driven bean (MDB), message-producing bean (MPB), and message- consumer bean (MCB).

Pattern 1: Message-Driven Bean with a Queue Listener
This design pattern is used with the WLSAdapter to create and configure an MDB that will be used with a SonicMQ Queue to implement an XA transaction. The destinations and connection factories will be stored in a file-based JNDI store.

Connection Factory
The first step is to create the JNDI entry for the connection factory. This can be done with a JNDI loader application that operates outside of WebLogic, or in a startup class that creates the entries within the WLS internal JNDI store (see end of article). We'll assume a file-based JNDI store for this example. Use the WLSAdapter to create the XAConnectionFactory.

XAQueueConnectionFactory xafactory =
new com.sonicsw.sonicmq.j2ee.wls.
XAQueueConnection Factory ("localhost:2506", "QueueMessageDriven",

This creates a connection factory named "xafactory" that's bound to a JNDI entry. The variable m_context is a reference the file-based JNDI context created from the com.sun.jndi. fscontext.RefFSContextFactory package.

m_context.rebind("myJMSxaqcf", xafactory);

At this point, a connection factory named "myJMSxaqcf" is ready for use in the JNDI store. A reference to the queue in the JNDI store is now created:

javax.jms.Queue queue = new progress.message.jclient.Queue ("sonicQueue");

This queue would also be bound to a JNDI entry:

m_context.rebind("sonicQueue", queue);

Deployment Descriptors
An EJB deployed in WLS requires two descriptor files: a standard "ejb-jar.xml" and a WebLogic-specific file, "weblogic-ejb.xml". In ejb-jar.xml, the MDB is prepared for an XA transaction by setting the trans-attribute tag to "Required"(see Listing 1; the listings for this article may be found online at www.sys-con.com/weblogic/sourcec.cfm).

The queue and connection factory are designated in the WebLogic-specific descriptor. The tag destination-jndi-name identifies the destination, in this case the queue "sonicQueue". The connection factory "myJMSxaqcf" is identified in connection-factory-jndi-name tag (see Listing 2).

Message-Driven Bean
The MDB doesn't require anything special to actually receive the message in an XA transaction. It just needs to be deployed transactionally in WebLogic, and it must implement the MessageDrivenBean and MessageListener interfaces.
The onMessage() method of this example will receive a message sent to the queue "sonicQueue":

public void onMessage(Message msg) { try { System.out.println("Received from sonicQueue"); } catch(JMSException ex) { ex.printStackTrace(); } }

Pattern 2: Message-Driven Bean with a Topic Listener
and Reconnect

This design pattern is used with the WLSAdapter to create
and configure an MDB that will be used with a SonicMQ Topic
to implement an XA transaction.
It will support reconnect capabilities.

Connection Factory
Use the WLSAdapter to create the XAConnectionFactory.

xafactory = new

To identify the fail-over brokers, connection URLs for
the factory are set:


A reconnect version of the connection factory is then created from the original connection factory:

long pingInterval = 1000L; long facSleep = 10000L; int maxIterations = 10; com.sonicsw.ssps.reconnect.
rec_xafactory =
new com.sonicsw.ssps.reconnect.
(xafactory, pingInterval, facSleep,

Parameters are set to define reconnect behavior. The value of "pingInterval" indicates how often (in milliseconds) to check for a lost connection. The value of "facSleep" indicates how long to wait before reconnecting. Finally, "maxIterations" indicates how many attempts should be made to reconnect. The reconnect version of the connection factory is then bound in the JNDI store:

m_context.rebind("myJMSrecxatcf", rec_xafactory);

Deployment Descriptors
The values of the destination-jndi-name tag and the connection-factory-jndi-name tag reflect the topic and the connection factory, in this case "sonicTopic" and "myJMSxatcf", respectively (see Listing 3).

Pattern 3: Stateless Session Message-Consumer Bean
This design pattern is used with the WLSAdapter to create and configure a stateless session bean that acts as a message consumer, an MCB. The example uses the receive() method of a receiver object to synchronously receive messages from a queue. The design would be similar for a topic-based MCB, where the receive() method of a subscriber object would be used.

This example assumes the home interface of the bean exposes three methods that correspond directly to the three types of receive() methods available on a receiver object:

public interface SonicMCBHome extends javax.ejb.EJBObject { public void receive()
throws RemoteException,JMSException ;
public void receive(long timeout)
throws RemoteException, JMSException;
public void receiveNoWait()
throws RemoteException, JMSException; }

Message-Consumer Bean
In the case of a queue-based MCB, the ejbCreate() method will look up a queue from which to create a session object (see Listing 4). From that session, a queue receiver object is created and the connection is started:

queue = (Queue) ctx.lookup(queueName);
receiver = session.createReceiver(queue);

The three receive() methods are implemented in the bean; each method corresponds to a matching receive() method signature on the queue receiver object (see Listing 5).

When one of these methods is called, the receiver will poll for a message from the queue. The receiver will wait indefinitely for a message if the first receive() method is called. If the second receive() method is called, the bean will wait an amount of time equal to the timeout parameter in milliseconds. If no wait time is desired, the receiveNoWait() implementation is used. If the second receive() method times out, a null value is returned. An MCB with a topic subscriber would be similar (see Listing 6). The receive() method is called from a topic subscriber instead of the queue receiver (see Listing 7).

Pattern 4: Message-Producing Bean
This design pattern is used with the WLSAdapter to create and configure a stateless session bean to act as a message producer. The MPB exposes one method, send(), in its home interface. The message is sent out on both a queue and a topic using an XA transaction to ensure that the send occurs on both destinations. The MPB also supports reconnect.

Connection Factories
First, XAConnectionFactories are created and bound. One is created for the queue and one for the topic, along with their reconnect counterparts (see Listing 8). JNDI entries are created for the two destinations, "sonicQueue" and "sonicTopic" (see Listing 9).

Deployment Descriptors In the ejb-jar.xml file, the trans-attribute tag is set to "Required" for XA transactions (see Listing 10). In the WebLogic-specific descriptor, however, the only necessary information is the ejb-name and the JNDI name for this stateless session bean. The connection factories and destinations aren't referenced here:


Message-Producing Bean
In the ejbCreate() method of the MPB, an initial context is created:

Hashtable env = new Hashtable();
InitialContext ctx = new InitialContext(env);

Then, a queue sender is created from the "myJMSxaqcf" connection factory, and a reference to the XAResource for the queue is retained (see Listing 11). The analogous steps are taken for a topic destination (see Listing 12). At this point, a topic publisher and a queue sender are ready for use in the send() method. When the MPB's send() method is invoked, a reference to the transaction object is obtained from WebLogic's Transaction helper:

javax.transaction.Transaction txn =

Next, the queue message is sent by enlisting the XA queue resource, creating and sending the message, and, finally, delisting the resource:

TextMessage qtext = qsession.createTextMessage
(qName + ":" + message);
txn.delistResource(qxar, XAResource.TMSUCCESS);

The steps are repeated for the topic:

TextMessage ttext = qsession.createTextMessage
(tName + ":" + message);
txn.delist Resource(txar, XAResource.TMSUCCESS);

A Note About Session Pooling
One clever aspect of the MPB built on a stateless session bean is the lightweight session pooling that can then be implemented through WLS. For a session bean, the initial and maximum number of instances of the bean that reside on the WLS can be configured in the WebLogic-specific descriptor file for that bean (see Listing 13).

Although these parameters' values can't be changed while WLS is running, this interface allows for some control over resources and a simple pooling mechanism to optimize message production.

Pulling the Design Patterns Together
Figure 1 illustrates a circumstance where an MDB implementation consumes messages from a topic, processes them into a local database via an entity bean, and then produces a response message for transmission over a queue via an MPB. In a highly scaled environment, the transaction might also use pooled, auto-reconnect MPBs to achieve higher throughput and manage scalability. Most importantly, the entire interaction is transactional. If a failure occurs along any execution point, the entire process can be rolled back, with the developer coding minimal recovery logic.

This illustration is just one of many possible combinations of core JMS design patterns integrated with applications' EJBs. Dozens more are facilitated and documented in the adapter package. From this brief discussion of the design patterns and implementation techniques, it should be clear that along with a robust adapter suite such as that provided with SonicMQ, the tools exist to create reliable, high-performance enterprise solutions for most complex scenarios.

While BEA WebLogic Server has JMS support to address simple requirements, the need for sophisticated and higher-performance capabilities of pure-play JMS providers will remain in certain circles for quite some time. Fortunately, the leading JMS providers have worked around "WLS-isms" to enable transactional integration of their products.

In the meantime, BEA has stated that WLS 7.0 will solve the issues of standards compliance. This may indeed obviate the need for XA integration adapters. However, the issues of automatic reconnection, JNDI loading, and failure injection will remain, as will the need for advanced adapter solutions that address these issues. Moreover, having the design wherewithal, best practices, and proven design patterns to implement reliable, globally scalable messaging systems in enterprise application server networks, adapters or not, will be an enduring capability well beyond the retirement of WLS 7.0. The qualities of SonicMQ and its associated adapter for WLS stand out as unique among the field of solutions in this area.

The authors wish to acknowledge the following individuals who contributed to this article: Gary Ark, Bill Cullen, Kathy Guo, May Hsu, K.V. Sastry, and Ademola Taiwo.

One quirk of WLS is that its JNDI repository isn't persistent across server sessions. Consequently, an outboard JNDI must be used or a JNDI loader class must be hard-wired for each application (the latter being the most common default). This seriously limits deployment flexibility and complicates network administration and maintenance.

The Sonic WLSAdapter cleverly answers these issues by providing a pattern for a generic, XML-driven JNDI loader class and an accompanying utility that generates the XML file directly from the JMS broker management API.

More Stories By Hub Vandervoort

Hub Vandervoort is vice president of Professional Services for Sonic Software. He has over twenty years experience as a consultant and senior technology executive in the networking, communications software, and Internet industries. Vandervoort previously co-founded three start-up ventures, including early message-oriented middleware (MOM) leader Horizon Strategies, Inc., which he merged with Momentum Software Corporation. He also co-founded, and served as board member of the Message-Oriented-Middleware Association (MOMA).

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

@ThingsExpo Stories
Dion Hinchcliffe is an internationally recognized digital expert, bestselling book author, frequent keynote speaker, analyst, futurist, and transformation expert based in Washington, DC. He is currently Chief Strategy Officer at the industry-leading digital strategy and online community solutions firm, 7Summits.
Digital Transformation and Disruption, Amazon Style - What You Can Learn. Chris Kocher is a co-founder of Grey Heron, a management and strategic marketing consulting firm. He has 25+ years in both strategic and hands-on operating experience helping executives and investors build revenues and shareholder value. He has consulted with over 130 companies on innovating with new business models, product strategies and monetization. Chris has held management positions at HP and Symantec in addition to ...
Cloud-enabled transformation has evolved from cost saving measure to business innovation strategy -- one that combines the cloud with cognitive capabilities to drive market disruption. Learn how you can achieve the insight and agility you need to gain a competitive advantage. Industry-acclaimed CTO and cloud expert, Shankar Kalyana presents. Only the most exceptional IBMers are appointed with the rare distinction of IBM Fellow, the highest technical honor in the company. Shankar has also receive...
Enterprises have taken advantage of IoT to achieve important revenue and cost advantages. What is less apparent is how incumbent enterprises operating at scale have, following success with IoT, built analytic, operations management and software development capabilities - ranging from autonomous vehicles to manageable robotics installations. They have embraced these capabilities as if they were Silicon Valley startups.
The standardization of container runtimes and images has sparked the creation of an almost overwhelming number of new open source projects that build on and otherwise work with these specifications. Of course, there's Kubernetes, which orchestrates and manages collections of containers. It was one of the first and best-known examples of projects that make containers truly useful for production use. However, more recently, the container ecosystem has truly exploded. A service mesh like Istio addr...
Predicting the future has never been more challenging - not because of the lack of data but because of the flood of ungoverned and risk laden information. Microsoft states that 2.5 exabytes of data are created every day. Expectations and reliance on data are being pushed to the limits, as demands around hybrid options continue to grow.
Business professionals no longer wonder if they'll migrate to the cloud; it's now a matter of when. The cloud environment has proved to be a major force in transitioning to an agile business model that enables quick decisions and fast implementation that solidify customer relationships. And when the cloud is combined with the power of cognitive computing, it drives innovation and transformation that achieves astounding competitive advantage.
Poor data quality and analytics drive down business value. In fact, Gartner estimated that the average financial impact of poor data quality on organizations is $9.7 million per year. But bad data is much more than a cost center. By eroding trust in information, analytics and the business decisions based on these, it is a serious impediment to digital transformation.
Digital Transformation: Preparing Cloud & IoT Security for the Age of Artificial Intelligence. As automation and artificial intelligence (AI) power solution development and delivery, many businesses need to build backend cloud capabilities. Well-poised organizations, marketing smart devices with AI and BlockChain capabilities prepare to refine compliance and regulatory capabilities in 2018. Volumes of health, financial, technical and privacy data, along with tightening compliance requirements by...
Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life settlement products to hedge funds and investment banks. After, he co-founded a revenue cycle management company where he learned about Bitcoin and eventually Ethereal. Andrew's role at ConsenSys Enterprise is a mul...
DXWordEXPO New York 2018, colocated with CloudEXPO New York 2018 will be held November 11-13, 2018, in New York City and will bring together Cloud Computing, FinTech and Blockchain, Digital Transformation, Big Data, Internet of Things, DevOps, AI, Machine Learning and WebRTC to one location.
DXWorldEXPO LLC announced today that "Miami Blockchain Event by FinTechEXPO" has announced that its Call for Papers is now open. The two-day event will present 20 top Blockchain experts. All speaking inquiries which covers the following information can be submitted by email to [email protected] Financial enterprises in New York City, London, Singapore, and other world financial capitals are embracing a new generation of smart, automated FinTech that eliminates many cumbersome, slow, and expe...
DXWorldEXPO | CloudEXPO are the world's most influential, independent events where Cloud Computing was coined and where technology buyers and vendors meet to experience and discuss the big picture of Digital Transformation and all of the strategies, tactics, and tools they need to realize their goals. Sponsors of DXWorldEXPO | CloudEXPO benefit from unmatched branding, profile building and lead generation opportunities.
The best way to leverage your Cloud Expo presence as a sponsor and exhibitor is to plan your news announcements around our events. The press covering Cloud Expo and @ThingsExpo will have access to these releases and will amplify your news announcements. More than two dozen Cloud companies either set deals at our shows or have announced their mergers and acquisitions at Cloud Expo. Product announcements during our show provide your company with the most reach through our targeted audiences.
DevOpsSummit New York 2018, colocated with CloudEXPO | DXWorldEXPO New York 2018 will be held November 11-13, 2018, in New York City. Digital Transformation (DX) is a major focus with the introduction of DXWorldEXPO within the program. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of bus...
With 10 simultaneous tracks, keynotes, general sessions and targeted breakout classes, @CloudEXPO and DXWorldEXPO are two of the most important technology events of the year. Since its launch over eight years ago, @CloudEXPO and DXWorldEXPO have presented a rock star faculty as well as showcased hundreds of sponsors and exhibitors! In this blog post, we provide 7 tips on how, as part of our world-class faculty, you can deliver one of the most popular sessions at our events. But before reading...
Cloud Expo | DXWorld Expo have announced the conference tracks for Cloud Expo 2018. Cloud Expo will be held June 5-7, 2018, at the Javits Center in New York City, and November 6-8, 2018, at the Santa Clara Convention Center, Santa Clara, CA. Digital Transformation (DX) is a major focus with the introduction of DX Expo within the program. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive ov...
As IoT continues to increase momentum, so does the associated risk. Secure Device Lifecycle Management (DLM) is ranked as one of the most important technology areas of IoT. Driving this trend is the realization that secure support for IoT devices provides companies the ability to deliver high-quality, reliable, secure offerings faster, create new revenue streams, and reduce support costs, all while building a competitive advantage in their markets. In this session, we will use customer use cases...
DXWorldEXPO LLC announced today that ICOHOLDER named "Media Sponsor" of Miami Blockchain Event by FinTechEXPO. ICOHOLDER give you detailed information and help the community to invest in the trusty projects. Miami Blockchain Event by FinTechEXPO has opened its Call for Papers. The two-day event will present 20 top Blockchain experts. All speaking inquiries which covers the following information can be submitted by email to [email protected] Miami Blockchain Event by FinTechEXPO also offers s...
With tough new regulations coming to Europe on data privacy in May 2018, Calligo will explain why in reality the effect is global and transforms how you consider critical data. EU GDPR fundamentally rewrites the rules for cloud, Big Data and IoT. In his session at 21st Cloud Expo, Adam Ryan, Vice President and General Manager EMEA at Calligo, examined the regulations and provided insight on how it affects technology, challenges the established rules and will usher in new levels of diligence arou...