|
|
YOUR FEEDBACK
SOA World Conference
Virtualization Conference $200 Savings Expire May 16, 2008... – Register Today! Did you read today's front page stories & breaking news?
SYS-CON.TV |
TOP THREE LINKS YOU MUST CLICK ON Feature
Advanced JMS Design Patterns for WebLogic Server Environments
By: Hub Vandervoort; Jake Yara
Digg This!
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
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
2. XAResource Is Never Enlisted
3. Proprietary Session Interface
4. XA Transaction Branches Aren't Serialized
Enter WebLogic Server Adapter (WLSAdapter)
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:
XA Transaction Integration
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
Automatic Client Reconnect
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:
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
Connection-Drop Failure
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
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 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
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
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:
BEA WEBLOGIC LATEST STORIES
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK BREAKING NEWS FROM THE WIRES
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||