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
"Space Monkey by Vivent Smart Home is a product that is a distributed cloud-based edge storage network. Vivent Smart Home, our parent company, is a smart home provider that places a lot of hard drives across homes in North America," explained JT Olds, Director of Engineering, and Brandon Crowfeather, Product Manager, at Vivint Smart Home, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
SYS-CON Events announced today that Conference Guru has been named “Media Sponsor” of the 22nd International Cloud Expo, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. A valuable conference experience generates new contacts, sales leads, potential strategic partners and potential investors; helps gather competitive intelligence and even provides inspiration for new products and services. Conference Guru works with conference organizers to pass great deals to gre...
The Internet of Things will challenge the status quo of how IT and development organizations operate. Or will it? Certainly the fog layer of IoT requires special insights about data ontology, security and transactional integrity. But the developmental challenges are the same: People, Process and Platform. In his session at @ThingsExpo, Craig Sproule, CEO of Metavine, demonstrated how to move beyond today's coding paradigm and shared the must-have mindsets for removing complexity from the develop...
In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, led attendees through the exciting evolution of the cloud. He looked at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering m...
"Evatronix provides design services to companies that need to integrate the IoT technology in their products but they don't necessarily have the expertise, knowledge and design team to do so," explained Adam Morawiec, VP of Business Development at Evatronix, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. In his session at @BigDataExpo, Jack Norris, Senior Vice President, Data and Applications at MapR Technologies, reviewed best practices to ...
Widespread fragmentation is stalling the growth of the IIoT and making it difficult for partners to work together. The number of software platforms, apps, hardware and connectivity standards is creating paralysis among businesses that are afraid of being locked into a solution. EdgeX Foundry is unifying the community around a common IoT edge framework and an ecosystem of interoperable components.
Large industrial manufacturing organizations are adopting the agile principles of cloud software companies. The industrial manufacturing development process has not scaled over time. Now that design CAD teams are geographically distributed, centralizing their work is key. With large multi-gigabyte projects, outdated tools have stifled industrial team agility, time-to-market milestones, and impacted P&L stakeholders.
"Akvelon is a software development company and we also provide consultancy services to folks who are looking to scale or accelerate their engineering roadmaps," explained Jeremiah Mothersell, Marketing Manager at Akvelon, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
"IBM is really all in on blockchain. We take a look at sort of the history of blockchain ledger technologies. It started out with bitcoin, Ethereum, and IBM evaluated these particular blockchain technologies and found they were anonymous and permissionless and that many companies were looking for permissioned blockchain," stated René Bostic, Technical VP of the IBM Cloud Unit in North America, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventi...
In his session at 21st Cloud Expo, Carl J. Levine, Senior Technical Evangelist for NS1, will objectively discuss how DNS is used to solve Digital Transformation challenges in large SaaS applications, CDNs, AdTech platforms, and other demanding use cases. Carl J. Levine is the Senior Technical Evangelist for NS1. A veteran of the Internet Infrastructure space, he has over a decade of experience with startups, networking protocols and Internet infrastructure, combined with the unique ability to it...
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
"Cloud Academy is an enterprise training platform for the cloud, specifically public clouds. We offer guided learning experiences on AWS, Azure, Google Cloud and all the surrounding methodologies and technologies that you need to know and your teams need to know in order to leverage the full benefits of the cloud," explained Alex Brower, VP of Marketing at Cloud Academy, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clar...
Gemini is Yahoo’s native and search advertising platform. To ensure the quality of a complex distributed system that spans multiple products and components and across various desktop websites and mobile app and web experiences – both Yahoo owned and operated and third-party syndication (supply), with complex interaction with more than a billion users and numerous advertisers globally (demand) – it becomes imperative to automate a set of end-to-end tests 24x7 to detect bugs and regression. In th...
"MobiDev is a software development company and we do complex, custom software development for everybody from entrepreneurs to large enterprises," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, discussed how from store operations and ...
"There's plenty of bandwidth out there but it's never in the right place. So what Cedexis does is uses data to work out the best pathways to get data from the origin to the person who wants to get it," explained Simon Jones, Evangelist and Head of Marketing at Cedexis, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
SYS-CON Events announced today that CrowdReviews.com has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5–7, 2018, at the Javits Center in New York City, NY. CrowdReviews.com is a transparent online platform for determining which products and services are the best based on the opinion of the crowd. The crowd consists of Internet users that have experienced products and services first-hand and have an interest in letting other potential buye...
SYS-CON Events announced today that Telecom Reseller has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. Telecom Reseller reports on Unified Communications, UCaaS, BPaaS for enterprise and SMBs. They report extensively on both customer premises based solutions such as IP-PBX as well as cloud based and hosted platforms.
It is of utmost importance for the future success of WebRTC to ensure that interoperability is operational between web browsers and any WebRTC-compliant client. To be guaranteed as operational and effective, interoperability must be tested extensively by establishing WebRTC data and media connections between different web browsers running on different devices and operating systems. In his session at WebRTC Summit at @ThingsExpo, Dr. Alex Gouaillard, CEO and Founder of CoSMo Software, presented ...