Welcome!

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

Advanced JMS Design Patterns for WebLogic Server Environments

BEA WebLogic Server (WLS) is the most widely deployed J2EE application server and continues to be an attractive platform for many enterprise-class situations.

As part of its support for J2EE 1.3, WLS now embeds a Java Message Service (JMS). The implementation is straightforward; using many built-in WLS features, it proves worthy at moderate scale in predominantly WLS environments.

Despite the inclusion of a new JMS implementation, there remain instances where heterogeneity, scalability, and availability requirements go beyond native support, calling for increased sophistication provided by third-party messaging solutions. For example, when multiple brands of application servers, C clients, or non-Java legacy applications are involved, a solution with broader platform coverage is required. If specialized features like client-side persistence or large-message support are necessary, niche solutions may be most suitable. If extreme throughput scalability or high availability via clustering, routing, and failover are critical, enterprise architects must turn to pure-play messaging vendors.

While implementing a third-party JMS has many advantages in highly scaled, mission-critical settings, it carries a bit more complexity than simple out-of-box configuration - especially when Enterprise JavaBeans (EJBs) and XA Container-Managed Transactions (CMT) are involved. The issues stem from two principal concerns: first, the manner in which WLS 6.x implements the Java Transaction API (JTA) and Java Transaction Service (JTS); and second, the way JMS and J2EE application servers interrelate with respect to runtime and development-time questions. On the first issue, cooperation from the JMS vendor is necessary for a solution (unless the JMS exposes its internal transaction APIs - read: open source). On the second issue, various design patterns can augment JMS vendor-provided tools for a complete solution.

This article explores third-party JMS integration with WLS and addresses the two issues outlined above by exposing Sonic Software's approach to implementing the SonicMQ WLSAdapter. We'll review how XA transactions implemented by the SonicMQ JMS are properly mapped to the nonstandard WLS JTA and illustrate how to deal with problems surrounding client reconnect, JNDI loading, exception handling, and complex EJB interactions.

WLS XA Transactions with Third-Party JMS
Global Transaction (XA) support, or CMT, presents unique, complex issues. When WLS EJBs use a foreign JMS to send or receive messages, and both attempt to participate in a common XA transaction, it usually fails. This is because the WLS 6.x JTA and JTS are implemented in a nonstandard way.

According to the JMS specification, a JMS provider must comply with the JTA specification and its rules for creation and use of XA resources, namely the XAConnectionFactory, XAConnection, and XASession objects. Similarly, the JMS must conform to the JTA standard for providing XAResource objects directly from an XASession object (for more details see Chapter 8 of the JMS 1.0.2.b Specification at http://java.sun.com/products/jms/docs.html).

Virtually all third-party JMS products meet these criteria, and they expect the application server, which acts as a JMS client, to adhere to the same JMS specification for a successful XA-compliant operation. WLS addresses four issues dealing with XA transactions.

1. No XAConnectionFactory, XAConnection, or XASession
When a J2EE application server sets up an XA transaction, it's supposed to use the XAQueueConnectionFactory or XATopicConnectionFactory objects from an external JMS provider to create XAConnection and XASession objects. Instead, WLS creates only standard JMS connection and session objects. As a result, steps specific to XA transactions and "Chapter-8 compliance" aren't implemented.

2. XAResource Is Never Enlisted
In order for an XA transaction to take place, an XAResource must be enlisted to begin the transaction. Because WLS doesn't use the third-party JMS provider XAConnectionFactory objects, it can't properly obtain an XAResource object to enlist. Thus, in a message-driven bean (MDB), where the enlistment should take place automatically under control of the application server, the external JMS XAResources are never actually enlisted into the CMT. Likewise, a session bean can't explicitly enlist the XAResource either - an XAResource can't be created in the first place.

3. Proprietary Session Interface
WLS requires that the session object of the external JMS implement a specific proprietary interface, weblogic.jms.extensions.MDBTransaction. This interface contains a method, associateTransaction(), that will be called by WLS to join the JMS transaction manager in the CMT. Because this interface isn't standard, third-party JMS providers must include an adapter to implement the method. Internally, WLS checks to see that a session object supports the interface; if not, the container throws an exception.

4. XA Transaction Branches Aren't Serialized
According to the JTA specification, all branches of a common XA transaction must be in serial order. However, WLS manages transaction branches in a way that allows a second transaction branch, provided to the container by an outboard transaction manager, to begin before other transaction branches have completed. This occurs because WLS transactions start and end branches in different threads. The "start" thread may have completed its actions, allowing the next transaction branch to start, while the "end" actions from the first transaction branch may not yet have completed. JMS 1.0.2-compliant products expect XA branches to be in serial order according to the JTA specification and consider any overlapping transaction branches to be a violation of JTA protocol. Thus, compliant JMS implementations will throw an exception when transactions are permitted to overlap, unless the JMS vendor provides an alternative nonstandard implementation.

Enter WebLogic Server Adapter (WLSAdapter)
Despite the issues, third-party JMS providers who intend to participate in the WebLogic market have clear incentives to provide integration solutions. Most vendors do this by including adapters to reconcile differences between JMS Chapter-8 compliance and the "isms" characteristic of the current WLS release. Adapter implementations are distinguished not only by the robustness with which they address XA functionality, but also by how they carry through to enable truly elegant and scalable solutions.

Enter the WLSAdapter from Sonic Software - a solution that resolves integration issues between WLS and SonicMQ, a leading enterprise messaging platform. This implementation addresses other key integration challenges as well, including:

  • Automating client reconnect and JNDI loading
  • Facilitating development-time failure injection for testing of exception-handling logic
  • Providing a robust set of template design patterns for sophisticated JMS architectures

    XA Transaction Integration
    If an application server is to provide XA transactions alongside a third-party JMS, it must be able to:

    • Create and manage JMS connections and sessions
    • Create and manage XAConnections and XASessions
    • Enlist the XAResource.
    While WLS can create and manage JMS connections, it can't create XA transactions or enlist XAResources. To resolve this problem, WLSAdapter creates and manages all XAConnectionFactories, XAConnections, XASessions, and XAResources.

    When the WLSAdapter creates an XASession, it also creates a single XAResource object inside a JVM (singleton), which is presented to the WLS transaction manager for each XA transaction. The real XAResources, provided within the JMS transaction manager, are created by WLSAdapter and registered with the singleton, which in turn delegates all WLS transaction manager calls to the appropriate SonicMQ XAResource. The adapter manages all SonicMQ XA branches internally. In MDBs, the WLSAdapter automatically enlists the XAResource on each transaction, while session beans explicitly enlist XAResources via the WLS TxHelper, javax.transaction.Transaction txn = weblogic.transaction.TxHelper.getTransaction(), and a direct call to the enlist method txn.enlistResource(myXAResource).

    The result is equivalent to the JMS adapter providing a small transaction manager to participate as a single resource for the WLS transaction manager. And, since an XA resource can now be obtained for the WLS transaction manager, issues 1 and 2 are resolved.

    The WLSAdapter addresses issue 3 by implementing the BEA proprietary interface, MDBTransaction, in its session object and uses the associateTransaction() method to trigger automatic enlistment from MDB transactions. Because the method is now implemented in the adapter XA session object, the WLS exceptions are no longer thrown.

    Finally, the WLSAdapter addresses issue 4 by managing XA transaction branches so they remain completely serialized. It does this by catching SonicMQ exceptions whenever WLS allows a transaction branch overlap, and holding the overlapping branch until the previous one has completed. Only then does it permit the next transaction branch to be started. Exceptions are masked, branch overlap is avoided, and XA transactions conform to the JTA Specification.

    With the WLSAdapter for SonicMQ, all four of the WLS XA-compliance issues are resolved, providing a fully JTA-compliant Global Transaction solution within an enterprise-class JMS.

    Other Integration Challenges
    Runtime and Development-Time Considerations

    The introduction of an adapter presents an opportunity to incorporate various value-added features that enhance the robustness of an enterprise solution. Key considerations include automating runtime reconnection around failed brokers or links and providing facilities for testing application-level exception handling (particularly connection- and transaction-level recovery logic).

    Automatic Client Reconnect
    Reconnection and failover capabilities are important to any large-scale distributed application. Both WebLogic and SonicMQ provide clustering and reconnection capabilities. Figure 1 represents a typical WebLogic clustering configuration with two servers in a cluster.

    Topic A and Topic B can be accessed from any WLS in the cluster. However, the topics must be created in advance, and topic information is tied locally to a particular server.

    In the event Instance A goes down, traffic will be routed to the remaining server in the cluster. However, Topic A will no longer be accessible.

    Figure 2 shows a WebLogic cluster and a SonicMQ cluster working together to leverage the reconnect capabilities of WLSAdapter.

    In this example, if either of the WLS instances fails, all topics will still be available through SonicMQ. In addition, if either of the SonicMQ brokers goes down, they'll automatically fail over to the backup server or servers, and topic information won't be lost. When WLSAdapter is used in a SonicMQ cluster, topics can be dynamically created and information is shared across the JMS cluster.

    To accomplish a reconnect in the first example (which doesn't use WLSAdapter), a producer or a synchronous consumer in an EJB would have to trap the exception inside the application logic when the broker goes down and explicitly reconnect and reconstitute all the connection and session objects.

    WLS does recreate a reconnection within an MDB; however, the listener isn't recreated and the messages can be lost. The solution provided by WLSAdapter:

  • Completely hides the connection failure from the user
  • Relies on the URL list to reestablish a connection
  • Ensures the session is recreated as well as the producers and consumers

    Since the connection failure and the reconnect are completely transparent to the user and business logic, the developer is freed from writing code to manage reconnect scenarios.

    Failure Insertion Points
    WLSAdapter can insert failure points for debugging and analysis. The advantages geared to development time address one of the most daunting aspects of integration testing - introducing controlled but realistic failures to test exception-handling pathways. WLSAdapter provides two types of failure injection: connection drop failure points and method failures.

    Connection-Drop Failure
    A connection-drop failure pauses the application in a specified method. This way, an external action can be taken by the developer to have an effect at a specific point in the execution of the application.

    For example, to test application behavior when a broker goes down or a connection fails, randomly pulling cables or "killing" a broker won't provide a reliably reproducible test case. However, using the SonicMQ WLSAdapter, you can isolate the failure occurrences by forcing a connection-drop failure to occur during the execution of a particular method, for example the onMessage() method of an MDB. When the method is called, the application will be paused by the adapter. At that point you can force a broker to disconnect and simulate the problem. After releasing the failure point, execution of the application resumes to reveal how the exception logic copes with the situation.

    Method Failure
    A method failure is similar in design, but it simply forces a particular exception to be thrown from a specific method rather than requiring developer intervention (such as killing a broker or pulling a cable). When a method failure point is set, the application will pause when it reaches the method specified. There the option is offered to have that method raise an exception, or continue normally.

    There are 10 methods in which you can set a connection-drop or method failure. Five of them are for JMS methods, and five are specifically for XA transactions. An application simply needs to implement the method in question for the WLSAdapter to execute it and inject a failure point; thus, no temporary test logic needs to be embedded within the application code. Table 1 lists the JMS and XA methods where failure insertion may occur.

    Using failure point insertion in WebLogic is as simple as including the WLSAdapter package in the classpath of the WebLogic domain startup and adding the appropriate flags to the application server start-up:

    -DSonicsw.WLSAdapter.Test.DoFail=true
    -DSonicsw.WLSAdapter.Test.FailType=%1
    -DSonicsw.WLSAdapter.Test.FailPoint=%2

    The parameter %1 would be either "ConnectionDrop" or "MethodFailure", and %2 would represent one of the methods listed in Table 1.

    Enterprise-Class Design Patterns
    Value-added features can be included with adapter packages in templates that implement advanced transactional design patterns. Often enterprise-level EJB scenarios employing JMS require several beans to interact transactionally. These complex scenarios necessitate clever construction for robustness and some form of session pooling for scalability.

    For example, a common circumstance might be to have an MDB acting as a consumer to a Pub/Sub topic listening for RFPs. When an RFP message arrives, it might process the document into a local database via an entity bean, and then a session bean to produce a proposal for transmission over a point-to-point queue back to the proposal requestor. In a high throughput environment, the outbound queue transmission might pool session beans to improve scalability. In this complex arrangement, the MDB, entity bean, and session beans must all become part of a single transaction, where two of the beans are interacting with the JMS transaction manager.

    The WLSAdapter uniquely answers questions surrounding these enterprise-grade problems. It does so by including prebuilt code templates that implement design patterns suitable for supporting multibean interactions. Solutions are illustrated for consumers and producers, along with a robust, yet lightweight, pooling mechanism for stateless session beans.

    Looking Ahead
    There are five primary transactional-JMS design patterns included in the Sonic WLSAdapter (illustrated in Figure 3). These include:

    • Message-Driven Bean
    • Message-Driven Bean Router
    • Message-Producing Bean
    • Message-Consuming Bean
    • Message-Consuming Bean Router
    Conclusion
    In part 2 of this article we'll describe the implementation of a few of these design patterns inside WLS using SonicMQ and the WLSAdapter as the JMS solution. The specific implementations covered will include:
    • Message-driven bean (with a queue listener)
    • Message-driven bean (with a topic listener and reconnect)
    • Message-consumer bean
    • Message-producing bean (with cross-JMS domain XA and reconnect)
    We'll summarize with a description of a composite design pattern employing a multibean interaction along the lines of the RFI/RFP example described above.
  • 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).

    More Stories By Jake Yara

    Jake Yara is an independent software consultant working with Sonic Software to implement application server-specific solutions for the leading EJB application servers on the market. In February of 2000 he founded Yara, Inc., which provides consulting services for the development and deployment of commercial client-server and web applications. [email protected]

    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
    Nordstrom is transforming the way that they do business and the cloud is the key to enabling speed and hyper personalized customer experiences. In his session at 21st Cloud Expo, Ken Schow, VP of Engineering at Nordstrom, discussed some of the key learnings and common pitfalls of large enterprises moving to the cloud. This includes strategies around choosing a cloud provider(s), architecture, and lessons learned. In addition, he covered some of the best practices for structured team migration an...
    Recently, REAN Cloud built a digital concierge for a North Carolina hospital that had observed that most patient call button questions were repetitive. In addition, the paper-based process used to measure patient health metrics was laborious, not in real-time and sometimes error-prone. In their session at 21st Cloud Expo, Sean Finnerty, Executive Director, Practice Lead, Health Care & Life Science at REAN Cloud, and Dr. S.P.T. Krishnan, Principal Architect at REAN Cloud, discussed how they built...
    In his session at 21st Cloud Expo, Raju Shreewastava, founder of Big Data Trunk, provided a fun and simple way to introduce Machine Leaning to anyone and everyone. He solved a machine learning problem and demonstrated an easy way to be able to do machine learning without even coding. Raju Shreewastava is the founder of Big Data Trunk (www.BigDataTrunk.com), a Big Data Training and consulting firm with offices in the United States. He previously led the data warehouse/business intelligence and B...
    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...
    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...
    The 22nd International Cloud Expo | 1st DXWorld Expo has announced that its Call for Papers is open. Cloud Expo | DXWorld Expo, to be held June 5-7, 2018, at the Javits Center in New York, NY, brings together Cloud Computing, Digital Transformation, Big Data, Internet of Things, DevOps, Machine Learning and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding busin...
    Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
    No hype cycles or predictions of a gazillion things here. IoT is here. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, an Associate Partner of Analytics, IoT & Cybersecurity at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He also discussed the evaluation of communication standards and IoT messaging protocols, data...
    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 ...
    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 ...
    DevOps at Cloud Expo – being held June 5-7, 2018, at the Javits Center in New York, NY – announces that its Call for Papers is open. Born out of proven success in agile development, cloud computing, and process automation, DevOps is a macro trend you cannot afford to miss. From showcase success stories from early adopters and web-scale businesses, DevOps is expanding to organizations of all sizes, including the world's largest enterprises – and delivering real results. Among the proven benefits,...
    @DevOpsSummit at Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, is co-located with 22nd Cloud Expo | 1st DXWorld Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is no time to wait...
    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...
    SYS-CON Events announced today that T-Mobile exhibited at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. As America's Un-carrier, T-Mobile US, Inc., is redefining the way consumers and businesses buy wireless services through leading product and service innovation. The Company's advanced nationwide 4G LTE network delivers outstanding wireless experiences to 67.4 million customers who are unwilling to compromise on qua...
    SYS-CON Events announced today that Cedexis will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Cedexis is the leader in data-driven enterprise global traffic management. Whether optimizing traffic through datacenters, clouds, CDNs, or any combination, Cedexis solutions drive quality and cost-effectiveness. For more information, please visit https://www.cedexis.com.
    SYS-CON Events announced today that Google Cloud has been named “Keynote Sponsor” of SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Companies come to Google Cloud to transform their businesses. Google Cloud’s comprehensive portfolio – from infrastructure to apps to devices – helps enterprises innovate faster, scale smarter, stay secure, and do more with data than ever before.
    SYS-CON Events announced today that Vivint to exhibit at SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California. As a leading smart home technology provider, Vivint offers home security, energy management, home automation, local cloud storage, and high-speed Internet solutions to more than one million customers throughout the United States and Canada. The end result is a smart home solution that sav...
    SYS-CON Events announced today that Opsani will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Opsani is the leading provider of deployment automation systems for running and scaling traditional enterprise applications on container infrastructure.
    SYS-CON Events announced today that Nirmata will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Nirmata provides a comprehensive platform, for deploying, operating, and optimizing containerized applications across clouds, powered by Kubernetes. Nirmata empowers enterprise DevOps teams by fully automating the complex operations and management of application containers and its underlying ...
    SYS-CON Events announced today that Opsani to exhibit at SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California. Opsani is creating the next generation of automated continuous deployment tools designed specifically for containers. How is continuous deployment different from continuous integration and continuous delivery? CI/CD tools provide build and test. Continuous Deployment is the means by which...