以 PDF 格式下载本书 (1536 KB)
Chapter 10 Java Message Service Load Balancing and FailoverThis chapter describes how to configure load balancing and failover of the Java Message Service (JMS) for use with the Application Server. It contains the following topics: Overview of Java Message ServiceThe Java Message Service (JMS) API is a messaging standard that allows Java EE applications and components to create, send, receive, and read messages. It enables distributed communication that is loosely coupled, reliable, and asynchronous. The Sun Java System Message Queue (MQ), which implements JMS, is tightly integrated with Application Server, enabling you to create components such as message-driven beans (MDBs). MQ is integrated with Application Server using a connector module, also known as a resource adapter, defined by the Java EE Connector Architecture Specification 1.5. Java EE components deployed to the Application Server exchange JMS messages using the JMS provider integrated via the connector module. Creating a JMS resource in Application Server creates a connector resource in the background. So, each JMS operation invokes the connector runtime and uses the MQ resource adapter in the background. You can manage the Java Message Service through the Admin Console or the asadmin command-line utility. Further InformationFor more information on configuring JMS resources, see Chapter 4, Configuring Java Message Service Resources, in Sun Java System Application Server 9.1 Administration Guide. For more information on JMS, see Chapter 18, Using the Java Message Service, in Sun Java System Application Server 9.1 Developer’s Guide. For more information on connectors (resource adapters), see Chapter 12, Developing Connectors, in Sun Java System Application Server 9.1 Developer’s Guide. For more information about the Sun Java System Message Queue, see the Message Queue documentation. For general information about the JMS API, see the JMS web page Configuring the Java Message ServiceThe Java Message Service configuration is available to all inbound and outbound connections to the Sun Java System Application Server cluster or instance. You can configure the Java Message Service with:
You can override the Java Message Service configuration using JMS connection factory settings. For details, see JMS Connection Factories in Sun Java System Application Server 9.1 Administration Guide. Note – You must restart the Application Server instance after changing the configuration of the Java Message Service. For more information about JMS administration, see Chapter 4, Configuring Java Message Service Resources, in Sun Java System Application Server 9.1 Administration Guide Java Message Service IntegrationMQ can be integrated with Application Server in three ways: LOCAL, REMOTE, and EMBEDDED. These modes are represented in the Admin Console by the Java Message Service Type attribute. LOCAL Java Message ServiceWhen the Type attribute is LOCAL (the default for cluster instances), the Application Server will start and stop the MQ broker specified as the Default JMS host. The MQ process is started out-of-process, in a separate VM, from the Application Server process. Application Server supplies an additional port to the broker . This port will be used by the broker to start the RMI registry. This port number will be equal to the configured JMS port for that instance plus 100. For example, if the JMS port number is 37676, then this additional port number will be 37776. To create a one-to-one relationship between Application Server instances and Message Queue brokers, set the type to LOCAL and give each Application Server instance a different default JMS host. You can do this regardless of whether clusters are defined in the Application Server or MQ. With LOCAL type, use the Start Arguments attribute to specify MQ broker startup parameters. REMOTE Java Message ServiceWhen the Type attribute is REMOTE, the MQ broker must be started separately. For information about starting the broker, see the Sun Java System Message Queue Administration Guide. In this case, Application Server will use an externally configured broker or broker cluster. Also, you must start and stop MQ brokers separately from Application Server, and use MQ tools to configure and tune the broker or broker cluster. REMOTE type is most suitable for Application Server clusters. With REMOTE type, you must specify MQ broker startup parameters using MQ tools. The Start Arguments attribute is ignored. EMBEDDED Java Message ServiceWhen the JMS Type attribute is EMBEDDED, it means that the application server and the JMS broker are co-located in the same VM and the JMS service is started in-process and managed by the Application Server. In this mode, the JMS operations by pass the networking stack leading to performance optimization. JMS Hosts ListA JMS host represents an MQ broker. The Java Message Service contains a JMS Hosts list (also called AddressList) that contains all the JMS hosts that Application Server uses. The JMS Hosts list is populated with the hosts and ports of the specified MQ brokers and is updated whenever a JMS host configuration changes. When you create JMS resources or deploy MDBs, they inherit the JMS Hosts list. Note – In the Sun Java System Message Queue software, the AddressList property is called imqAddressList. Default JMS HostOne of the hosts in the JMS Hosts list is designated the default JMS host, named Default_JMS_host. The Application Server instance starts the default JMS host when the Java Message Service type is configured as LOCAL. If you have created a multi-broker cluster in the Sun Java System Message Queue software, delete the default JMS host, then add the Message Queue cluster’s brokers as JMS hosts. In this case, the default JMS host becomes the first one in the JMS Hosts list. When the Application Server uses a Message Queue cluster, it executes Message Queue specific commands on the default JMS host. For example, when a physical destination is created for a Message Queue cluster of three brokers, the command to create the physical destination is executed on the default JMS host, but the physical destination is used by all three brokers in the cluster. Creating JMS HostsYou can create additional JMS hosts in the following ways:
Connection Pooling and FailoverApplication Server supports JMS connection pooling and failover. The Sun Java System Application Server pools JMS connections automatically. When the Address List Behavior attribute is random (the default), Application Server selects its primary broker randomly from the JMS host list. When failover occurs, MQ transparently transfers the load to another broker and maintains JMS semantics. The default value for the Address List Behavior attribute is priority, if the JMS type is of type LOCAL. To specify whether the Application Server tries to reconnect to the primary broker when the connection is lost, select the Reconnect checkbox. If enabled and the primary broker goes down, Application Server tries to reconnect to another broker in the JMS Hosts list. When Reconnect is enabled, also specify the following attributes:
You can override these settings using JMS connection factory settings. For details, see JMS Connection Factories in Sun Java System Application Server 9.1 Administration Guide. Load-Balanced Message InflowYou can configure ActivationSpec properties of the jmsra resource adapter in the sun-ejb-jar.xml file for a message-driven bean using activation-config-property elements. Whenever a message-driven bean (EndPointFactory) is deployed, the connector runtime engine finds these properties and configures them accordingly in the resource adapter. See activation-config-property in Sun Java System Application Server 9.1 Application Deployment Guide. The Application Server transparently enables messages to be delivered randomly to message-driven beans having the same ClientID . The ClientID is required for durable subscribers. For non-durable subscribers in which the ClientID is not configured, all instances of a specific message-driven bean that subscribe to same topic are considered equal. When a message-driven bean is deployed to multiple instances of the Application Server, only one of the message-driven beans receives the message. If multiple distinct message-driven beans subscribe to same topic, one instance of each message-driven bean receives a copy of the message. To support multiple consumers using the same queue, set the maxNumActiveConsumers property of the physical destination to a large value. If this property is set, the Sun Java System Message Queue software allows up to that number of message-driven beans to consume messages from same queue. The message is delivered randomly to the message-driven beans. If maxNumActiveConsumers is set to -1, there is no limit to the number of consumers. To ensure that local delivery is preferred, set addresslist-behavior to priority. This setting specifies that the first broker in the AddressList is selected first. This first broker is the local colocated Message Queue instance. If this broker is unavailable, connection attempts are made to brokers in the order in which they are listed in the AddressList. This setting is the default for Application Server instances that belong to a cluster. Note – Clustering features are not available in the developer profile. For information about profiles, see Usage Profiles in Sun Java System Application Server 9.1 Administration Guide. JMS Service High AvailabilityThere are two levels of availability for JMS components:
You can enable data availability in the Sun Java System Message Queue cluster that comprises the Java Message Service (JMS). Messages are persisted to the common persistence store and are available from all the other broker instances in the cluster or from the high-availability database (HADB) if it is installed and the enterprise profile is selected. For information about profiles, see Usage Profiles in Sun Java System Application Server 9.1 Administration Guide. You must enable availability for the Application Server instances before you can enable data availability for the corresponding brokers. Note – Individual applications and modules cannot control or override JMS availability. To enable data availability, select the Availability Service component under the relevant configuration in the Admin Console. Check the Availability Service box. To enable availability for the JMS service, select the JMS Availability tab, then check the Availability Service box. All instances in an Application Server cluster should have the same instance availability and JMS availability settings to ensure consistent behavior. For details, see the Sun Java System Application Server 9.1 High Availability Administration Guide. Note – Clustering features are not available in the developer profile. For information about profiles, see Usage Profiles in Sun Java System Application Server 9.1 Administration Guide. Using MQ Clusters with Application ServerMQ Enterprise Edition supports multiple interconnected broker instances known as a broker cluster. With broker clusters, client connections are distributed across all the brokers in the cluster. Clustering provides horizontal scalability and improves availability. This section describes how to configure Application Server to use highly available Sun Java System Message Queue clusters. It explains how to start and configure Message Queue clusters. For more information about the topology of Application Server and MQ deployment, see Planning Message Queue Broker Deployment in Sun Java System Application Server 9.1 Deployment Planning Guide. Highly Available MQ ClustersSun Java System Message Queue 4.1 provides a highly available messaging service through a new "Highly Available" cluster type. In an MQ cluster of this type, all the broker instances would share a peer– to–peer relationship and all its broker instances would share a common persistent data store thus offering 'Data Availability.' Instances would automatically be able to detect if an instance fails and perform a takeover of the failed broker's persistent messages, dynamically through a takeover election. Application components that are deployed in the Application Server could thus leverage these availability features. With this cluster type, there would not be any loss of transacted persistent messages to a queue or a durable topic subscription. Non-persistent messages or persistent messages to non-durable subscribers are likely to be lost when the broker that the client runtime is connected to is unavailable. Configuring a Highly Available Broker Cluster in the Local Mode
Configuring a Highly Available Broker Cluster in the Remote Mode
Auto-clustering for non-HA ClustersTill now, the administrator had to set up 'non-Highly Available' MQ clusters (MQ clusters with a master broker) separately as explained in the procedure following this section. In this release, in addition to the manual process (of type REMOTE) of setting up an MQ cluster, Application Server provides 'auto-clustering,' which means that a co-located non-HA cluster (of type LOCAL) will be created automatically when a user creates an Application Server cluster. This will be the default mode of creating MQ clusters. For example, when the administrator creates an Application Server cluster with three Application Server instances, each Application Server instance will be configured to work with a co-located broker, and as a result the three MQ broker instances will be made to form an MQ cluster transparently. The first Application Server instance's MQ broker will be set to be the master broker. Auto-clustering, however, has a disadvantage too. If the administrator adds an instance to the cluster, the MQ broker instance created automatically will not be able to take part in the cluster. This behavior also applies if an instance is removed from the cluster.
|
asadmin delete-jms-host --target cluster1 default_JMS_host
asadmin create-jms-host --target cluster1
--mqhost myhost1 --mqport 6769
--mquser admin --mqpassword admin broker1
asadmin create-jms-host --target cluster1
--mqhost myhost2 --mqport 6770
--mquser admin --mqpassword admin broker2
asadmin create-jms-host --target cluster1
--mqhost myhost3 --mqport 6771
--mquser admin --mqpassword admin broker3
|
To create the hosts with Admin Console:
Navigate to the JMS Hosts node (Configurations > config-name > Java Message Service > JMS Hosts)
Delete the default broker (default_JMS_host).
Select the checkbox next to it, and then click Delete.
Click New to create each JMS host and enter its property values.
Fill in the values for host name, DNS name or IP address, port number, administrative user name and password.
Start the master MQ broker and the other MQ brokers.
In addition to the three external brokers started on JMS host machines, start one master broker on any machine. This master broker need not be part of a broker cluster. For example:
/usr/bin/imqbrokerd -tty -name brokerm -port 6772 -cluster myhost1:6769,myhost2:6770,myhost2:6772,myhost3:6771 -D"imq.cluster.masterbroker=myhost2:6772" |
Start the Application Server instances in the cluster.
Create JMS resources on the cluster:
Create JMS physical destinations.
For example, using asadmin:
asadmin create-jmsdest --desttype queue --target cluster1 MyQueue asadmin create-jmsdest --desttype queue --target cluster1 MyQueue1 |
To use Admin Console:
Create JMS connection factories.
For example, using asadmin:
asadmin create-jms-resource --target cluster1 --restype javax.jms.QueueConnectionFactory jms/MyQcf asadmin create-jms-resource --target cluster1 --restype javax.jms.QueueConnectionFactory jms/MyQcf1 |
To use Admin Console:
Navigate to the JMS Connection Factories page (Resources > JMS Resources > Connection Factories).
To create each connection factory, click New.
The Create JMS Connection Factory page opens.
For each connection factory, enter JNDI Name (for example jms/MyQcf) and Type, javax.jms.QueueConnectionFactory
Select the cluster from the list of available targets at the bottom of the page and click Add.
Click OK to create the connection factory.
Create JMS destination resources.
For example, using asadmin:
asadmin create-jms-resource --target cluster1
--restype javax.jms.Queue
--property imqDestinationName=MyQueue jms/MyQueue
asadmin create-jms-resource --target cluster1
--restype javax.jms.Queue
--property imqDestinationName=MyQueue1 jms/MyQueue1
|
To use Admin Console:
Navigate to the JMS Destination Resources page (Resources > JMS Resources > Connection Factories).
To create each destination resource, click New.
The Create JMS Destination Resource page opens.
For each destination resource, enter JNDI Name (for example jms/MyQueue) and Type javax.jms.Queue.
Select the cluster from the list of available targets at the bottom of the page and click Add.
Click OK to create the destination resource.
Deploy the applications with the – retrieve option for application clients. For example:
asadmin deploy --target cluster1 --retrieve /opt/work/MQapp/mdb-simple3.ear |
Access the application and test it to ensure it is behaving as expected.
If you want to return the Application Server to its default JMS configuration, delete the JMS hosts you created and recreate the default. For example:
asadmin delete-jms-host --target cluster1 broker1 asadmin delete-jms-host --target cluster1 broker2 asadmin delete-jms-host --target cluster1 broker3 asadmin create-jms-host --target cluster1 --mqhost myhost1 --mqport 7676 --mquser admin --mqpassword admin default_JMS_host |
You can also perform the equivalent operation with Admin Console.
If you encounter problems, consider the following:
View the Application Server log file located at as-install-dir/nodeagents/node-agent-name/instance-name/logs/server.log. If you see in the log file that an MQ broker does not respond to a message, stop the broker and then restart it.
View the broker log available at as-install-dir/nodeagents/node-agent-name/instance-name/imq/imq-instance-name/log/log.txt.
For the Remote JMS type, always be sure to start MQ brokers first, and then the Application Server instances.
When all MQ brokers are down, it takes 30 minutes for Application Server to go down or up, with the default values in Java Message Service. Tune Java Message Service values to get acceptable values for this timeout. For example:
asadmin set --user admin --password administrator cluster1.jms-service.reconnect-interval-in-seconds=5