Message Queue 4.0 includes the following new features:
These are described in the following subsections.
One of the more minor but potentially disruptive changes introduced with version 4.0 is the deprecation of the command-line option to specify a password. Henceforth, you must store all passwords in a file as described in Deprecated Password Option.
Changes to the C-API were introduced with Release 3.7: they include a new function, a new message type, and a new connection property.
New function: MQGetDestinationName()
MQGetDestinationName (const MQDestinationHandle destinationHandle, MQString * destinationName); |
Use this function to get the name of a destination. The returned destinationName is a copy that the caller is responsible for freeing by calling the MQFreeString() function.
Parameters
A handle to the destination whose name you want to know.
The output parameter for the name.
This function is useful when using the reply-to pattern. You can use the MQGetMessageReplyTo function to obtain a handle to the destination where the message should be sent. You can then use the MQGetDestinationName to get the name of that destination. Having obtained the destination name, you can do message processing based on the name.
New enumerated value: MQ_MESSAGE
The new MQMessageType, MQ_MESSAGE, allows C clients to exchange JMS messages of type Message with other Message Queue clients (both C and Java):
typedef enum _MQMessageType {MQ_TEXT_MESSAGE = 0, MQ_BYTES_MESSAGE = 1, MQ_MESSAGE = 3, MQ_UNSUPPORTED_MESSAGE = 2} MQMessageType; |
The MQ_MESSAGE type identifies messages that have a header and properties but no message body. You use the MQCreateMessage() function to create a message of this type.
A new connection property, MQ_UPDATE_RELEASE_PROPERTY, that specifies the update release version for the installed version of Message Queue. Use the MQGetMetaData() function to obtain version information.
The query subcommand was added to the imqdbmgr command. Use this subcommand to display information about the persistent store, including the store version, the database user, and whether the database tables have been created.
The following is an example of the information displayed by the command
dbmgr query |
[04/Oct/2005:15:30:20 PDT] Using plugged-in persistent store: version=400 brokerid=Mozart1756 database connection url=jdbc:oracle:thin:@Xhome:1521:mqdb database user=scott Running in standalone mode. Database tables have already been created. |
Version 3.7 UR1 of Message Queue introduced two changes to the persistent store format to improve performance. One change is to the file store, the other is to the JDBC store.
Format of Transaction Data Persisted in File Store
The format of transaction state information stored in the Message Queue file-based persistent store was changed to reduce disk I/O and to improve the performance of JMS transactions.
Oracle JDBC Store
In previous versions of Message Queue, the store schema for Oracle used the LONG RAW data type to store message data. In Oracle 8, Oracle introduced the BLOB data types and deprecated the LONG RAW type. Message Queue 3.7 UR1 switched to the BLOB data type to improve performance and supportability.
Because these changes impact store compatibility, the store version for both the file store and the JDBC store was changed from 350 to 370 in version 3.7 UR1 of Message Queue.
Version 4.0 of Message Queue introduced changes to the JDBC store for optimization and to support future enhancements. For this reason the JDBC store version was increased to 400. Note that in Version 4.0, the file—based persistent store version remains 370 because no changes were made to it.
Message Queue 4.0 supports automatic conversion of the persistent store to the newest versions of the file-based and JDBC persistent stores. The first time imqbrokerd starts, if the utility detects an older store it will migrate the store to the new format, leaving the old store behind.
File—based store versions 200 and 350 will be migrated to the 370 version format.
JDBC store versions 350 and 370 will be migrated to the 400 version format. (If you need to upgrade a 200 store, you will need to step through an intermediate 3.5 or 3. 6 release.)
If you should need to roll back this upgrade, you can uninstall Message Queue 4.0 and then reinstall the version you were previously running. Since the older copy of the store is left intact, the broker can run with the older copy of the store.
The Command utility (imqcmd) has added a subcommand and several options that allow administrators to quiesce the broker, to shutdown the broker after a specified interval, or to destroy a connection.
Quiescing the broker moves it into a quiet state, which allows messages to be drained before the broker is shut down or restarted. No new connections can be created to a broker that is being quiesced. To quiesce the broker, enter a command like the following.
imqcmd quiesce bkr -b Wolfgang:1756
To shut down the broker after a specified interval, enter a command like the following. The time interval specifies the number of seconds to wait before the broker is shut down.
imqcmd shutdown bkr -b Hastings:1066 -time 90
To destroy a connection, enter a command like the following.
imqcmd destroy cxn -n 2691475382197166336
Use the command imqcmd list cxn or imqcmd query cxn to obtain the connection ID.
For complete information about the syntax of the imqcmd command, see Chapter 14, “Command Line Reference,” in Sun Java System Message Queue 3 2005Q4 Administration Guide.
Apache Derby Version 10.1.1 is now supported as a JDBC-compliant persistent store provider.
Starting with release 4.0, the default value for the client connection factory property imqSSLIsHostTrusted is false. If your application depends on the prior default value of true, you need to reconfigure and to set the property explicitly to true.
A new API has been added for configuring and monitoring Message Queue brokers in conformance with the Java Management Extensions (JMX) specification. Using this API, you can configure and monitor broker functions programmatically from within a Message Queue client application. In earlier versions of Message Queue, these functions were accessible only from the command line or the Administration Console.
The API consists of a set of JMX Managed Beans (MBeans) for managing the following Message Queue–related resources:
Message brokers
Connection services
Connections
Destinations
Message producers
Message consumers
Transactions
Broker clusters
Logging
The Java Virtual Machine (JVM)
These MBeans provide attributes and operations for synchronously polling and manipulating the state of the underlying resources, as well as notifications that allow a client application to listen for and respond asynchronously to state changes as they occur. Using the JMX API, client applications can perform configuration and monitoring tasks like the following:
Set a broker's port number
Set a broker's maximum message size
Pause a connection service
Set the maximum number of threads for a connection service
Get the current number of connections on a service
Destroy a connection
Create a destination
Destroy a destination
Enable or disable auto-creation of destinations
Purge all messages from a destination
Get the cumulative number of messages received by a destination since the broker was started
Get the current state (running or paused) of a queue
Get the current number of message producers for a topic
Purge all messages from a durable subscriber
Get the current JVM heap size
For an introduction to the JMX API and for complete reference information, see the Sun Java System Message Queue 4.0 Developer's Guide for JMX Clients.
Several new broker properties have been added to support the JMX API (see Table 1–2). None of these properties can be set from the command line with the Message Queue Command utility (imqcmd). Instead, they can either be set with the -D option of the Broker utility (imqbrokerd) or edited by hand in the broker's instance configuration file (config.properties). In addition, some of these properties (imq.jmx.rmiregistry.start, imq.jmx.rmiregistry.use, imq.jmx.rmiregistry.port) can be set with the new Broker utility options described in Table 1–3. The table lists each option, specifies its type, and describes its use.
Table 1–2 New Broker Properties for JMX Support
The imq.jmx.connector.list property defines a set of named JMX connectors to be created at broker startup; imq.jmx.connector.activelist specifies which of these are to be activated. Each named connector then has its own set of properties:
imq.jmx.connector.connectorName.urlpath |
imq.jmx.connector.connectorName.useSSL |
imq.jmx.connector.connectorName.brokerHostTrusted |
By default, two JMX connectors are created, named jmxrmi and ssljmxrmi; the first is configured not to use SSL encryption (imq.jmx.connector.jmxrmi.useSSL = false, the second to use it (imq.jmx.connector.ssljmxrmi.useSSL = true). By default, only the jmxrmi connector is activated at broker startup; see SSL Support for JMX Clients for information on how to activate the ssljmxrmi connector for secure communications.
For convenience, new options (Table 1–3) are also added to the command-line Broker utility (imqbrokerd) to control the usage, startup, and port for the RMI registry. The use and effects of these options are the same as those of the equivalent broker properties, as described in Table 1–2. The table lists each option, specifies its equivalent broker property, and describes its use.
Table 1–3 New Broker Utility Options for JMX Support
Option |
Equivalent Broker Property |
Description |
---|---|---|
-startRmiRegistry |
imq.jmx.rmiregistry.start |
Start RMI registry at broker startup? |
-useRmiRegistry |
imq.jmx.rmiregistry.use |
Use external RMI registry? |
-rmiRegistryPort |
imq.jmx.rmiregistry.port |
Port number of RMI registry |
A new subcommand (Table 1–4) is added to the command-line Command utility (imqcmd) for listing the JMX service URLs of JMX connectors created and started at broker startup. This information is needed by JMX clients that do not use the Message Queue convenience class AdminConnectionFactory to obtain their JMX connectors, and can also be used for managing or monitoring Message Queue via a generic JMX browser such as the Java Monitoring and Management Console (jconsole).
Table 1–4 New Command Utility Subcommand
Subcommand |
Description |
---|---|
list jmx |
List JMX service URLs of JMX connectors |
As mentioned above, a Message Queue message broker is configured by default for insecure communication using the preconfigured JMX connector jmxrmi. Applications wishing to use the Secure Socket Layer (SSL) for secure communication must activate the alternate, secure JMX connector, ssljmxrmi. This requires the following steps:
Obtain and install a signed certificate in the same way as for the ssljms, ssladmin, or cluster connection service, as described in the Message Queue Administration Guide.
Install the root certification authority certificate in the trust store if necessary.
Add the ssljmxrmi connector to the list of JMX connectors to be activated at broker startup:
imq.jmx.connector.activelist=jmxrmi,ssljmxrmi
Start the broker with the Message Queue Broker utility (imqbrokerd), either passing it the key-store password in a password file or typing it from the command line when prompted.
By default, the ssljmxrmi connector (or any other SSL-based connector) is configured to validate all broker SSL certificates presented to it. To avoid this validation (for instance, when using self-signed certificates during software testing), set the broker property imq.jmx.connector.ssljmxrmi.brokerHostTrusted to true.
On the client side, the administrator connection factory (AdminConnectionFactory) must be configured with a URL specifying ssljmxrmi as the preferred connector:
AdminConnectionFactory acf = new AdminConnectionFactory(); acf.setProperty(AdminConnectionConfiguration.imqAddress, "mq://myhost:7676/ssljmxrmi");
If needed, use the system properties javax.net.ssl.trustStore and javax.net.ssl.trustStorePassword to point the JMX client to the trust store.
This section describes Message Queue 4.0 support for client runtime logging of connection and session-related events.
JDK 1.4 (and above) includes the java.util.logging library. This library implements a standard logger interface that can be used for application-specific logging.
The Message Queue client runtime uses the Java Logging API to implement its logging functions. You can use all the J2SE 1.4 logging facilities to configure logging activities. For example, an application can use the following Java logging facilities to configure how the Message Queue client runtime outputs its logging information:
Logging Handlers
Logging Filters
Logging Formatters
Logging Level
For more information about the Java Logging API, please see the Java Logging Overview at http://java.sun.com/j2se/1.4.2/docs/guide/util/logging/overview.html
The Message Queue provider defines a set of logging name spaces associated with logging levels and logging activities that allow Message Queue clients to log connection and session events when a logging configuration is appropriately set.
The root logging name space for the Message Queue client runtime is defined as javax.jms. All loggers in the Message Queue client runtime use this name as the parent name space.
The logging levels used for the Message Queue client runtime are the same as those defined in the java.util.logging.Level class. This class defines seven standard log levels and two additional settings that you can use to turn logging on and off.
Turns off logging.
Highest priority, highest value. Application-defined.
Application-defined.
Application-defined.
Application-defined
Application-defined.
Application-defined.
Lowest priority, lowest value. Application-defined.
Enables logging of all messages.
In general, exceptions and errors that occur in the Message Queue client runtime are logged by the logger with the javax.jms name space.
Exceptions thrown from the JVM and caught by the client runtime, such as IOException, are logged by the logger with the logging name space javax.jms at level WARNING.
JMS exceptions thrown from the client runtime, such as IllegalStateException, are logged by the logger with the logging name space javax.jms at level FINER.
Errors thrown from the JVM and caught by the client runtime, such as OutOfMemoryError, are logged by the logger with the logging name space javax.jms at level SEVERE.
The following tables list the events that can be logged and the log level that must be set to log events for JMS connections and for sessions.
The following table describes log levels and events for connections.
Table 1–5 Log Levels and Events for javax.jms.connection Name Space
Log Level |
Events |
---|---|
FINE |
Connection created |
FINE |
Connection started |
FINE |
Connection closed |
FINE |
Connection broken |
FINE |
Connection reconnected |
FINER |
Miscellaneous connection activities such as setClientID |
FINEST |
Messages, acknowledgments, Message Queue action and control messages (like committing a transaction) |
For sessions, the following information is recorded in the log record.
Each log record for a message delivered to a consumer includes ConnectionID, SessionID, and ConsumerID.
Each log record for a message sent by a producer includes ConnectionID, SessionID, ProducerID, and destination name.
The table below describes log levels and events for sessions.
Table 1–6 Log Levels and Events for javax.jms.session Name Space
Log Level |
Event |
---|---|
FINE |
Session created |
FINE |
Session closed |
FINE |
Producer created |
FINE |
Consumer created |
FINE |
Destination created |
FINER |
Miscellaneous session activities such as committing a session. |
FINEST |
Messages produced and consumed. (Message properties and bodies are not logged in the log records.) |
By default, the output log level is inherited from the JRE in which the application is running. Check the JRE_DIRECTORY/lib/logging.properties file to determine what that level is.
You can configure logging programmatically or by using configuration files, and you can control the scope within which logging takes place. The following sections describe these possibilities.
The following example shows how you set logging name spaces and levels in the JRE_DIRECTORY/lib/logging.properties file, which is used to set the log level for the Java runtime environment. All applications using this JRE will have the same logging configuration. The sample configuration below sets the logging level to INFO for the javax.jms.connection name space and specifies that output be written to java.util.logging.ConsoleHandler.
#logging.properties file. # "handlers" specifies a comma separated list of log Handler # classes. These handlers will be installed during VM startup. # Note that these classes must be on the system classpath. # By default we only configure a ConsoleHandler, which will only # show messages at the INFO and above levels. handlers= java.util.logging.ConsoleHandler # Default global logging level. # This specifies which kinds of events are logged across # all loggers. For any given facility this global level # can be overriden by a facility-specific level. # Note that the ConsoleHandler also has a separate level # setting to limit messages printed to the console. .level= INFO # Limit the messages that are printed on the console to INFO and above. java.util.logging.ConsoleHandler.level = INFO java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter # The logger with javax.jms.connection name space will write # Level.INFO messages to its output handler(s). In this configuration # the ouput handler is set to java.util.logging.ConsoleHandler. javax.jms.connection.level = INFO
You can also define a logging configuration file from the java command line that you use to run an application. The application will use the configuration defined in the specified logging file. In the following example, configFile uses the same format as defined in the JRE_DIRECTORY/lib/logging.properties file.
java -Djava.util.logging.config.file=configFile MQApplication
The following code uses the java.util.logging API to log connection events by changing the javax.jms.connection name space log level to FINE. You can include such code in your application to set logging configuration programmatically.
import java.util.logging.*; //construct a file handler and output to the mq.log file //in the system's temp directory. Handler fh = new FileHandler("%t/mq.log"); fh.setLevel (Level.FINE); //Get Logger for "javax.jms.connection" domain. Logger logger = Logger.getLogger("javax.jms.connection"); logger.addHandler (fh); //javax.jms.connection logger would log activities //with level FINE and above. logger.setLevel (Level.FINE);
Connection event notifications allow a Message Queue client to listen for closure and reconnection events and to take appropriate action based on the notification type and the connection state. For example, when a failover occurs and the client is reconnected to another broker, an application might want to clean up its transaction state and proceed with a new transaction.
If the Message Queue provider detects a serious problem with a connection, it calls the connection object's registered exception listener. It does this by calling the listener's onException method, and passing it a JMSException argument describing the problem. In the same way, the Message Queue provider offers an event notification API that allows the client runtime to inform the application about connection state changes. The notification API is defined by the following elements:
The com.sun.messaging.jms.notification package, which defines the event listener and the notification event objects .
The com.sun.messaging.jms.Connection interface, which defines extensions to the javax.jms.Connection interface.
The following sections describe the events that can trigger notification and explain how you can create an event listener.
The following table lists and describes the events that can be returned by the event listener.
Note that the JMS exception listener is not called when a connection event occurs. The exception listener is only called if the client runtime has exhausted its reconnection attempts. The client runtime always calls the event listener before the exception listener.
Table 1–7 Notification Events
Event Type |
Meaning |
---|---|
ConnectionClosingEvent |
The Message Queue client runtime generates this event when it receives a notification from the broker that a connection is about to be closed due to a shutdown requested by the administrator. |
ConnectionClosedEvent |
The Message Queue client runtime generates this event when a connection is closed due to a broker error or when it is closed due to a shutdown or restart requested by the administrator. When an event listener receives a ConnectionClosedEvent, the application can use the getEventCode() method of the received event to get an event code that specifies the cause for closure. |
ConnectionReconnectedEvent |
The Message Queue client runtime has reconnected to a broker. This could be the same broker to which the client was previously connected or a different broker. An application can use the getBrokerAddress method of the received event to get the address of the broker to which it has been reconnected. |
ConnectionReconnectFailedEvent |
The Message Queue client runtime has failed to reconnect to a broker. Each time a reconnect attempt fails, the runtime generates a new event and delivers it to the event listener. The JMS exception listener is not called when a connection event occurs. It is only called if the client runtime has exhausted its reconnection attempts. The client runtime always calls the event listener before the exception listener. |
The following code example illustrates how you set a connection event listener. Whenever a connection event occurs, the event listener's onEvent method will be invoked by the client runtime
//create an MQ connection factory. com.sun.messaging.ConnectionFactory factory = new com.sun.messaging.ConnectionFactory(); //create an MQ connection. com.sun.messaging.jms.Connection connection = (com.sun.messaging.jms.Connection )factory.createConnection(); //construct an MQ event listener. The listener implements //com.sun.messaging.jms.notification.EventListener interface. com.sun.messaging.jms.notification.EventListener eListener = new ApplicationEventListener(); //set event listener to the MQ connection. connection.setEventListener ( eListener );
In this example, an application chooses to have its event listener log the connection event to the application's logging system:
public class ApplicationEventListener implements com.sun.messaging.jms.notification.EventListener { public void onEvent ( com.sun.messaging.jms.notification.Event connEvent ) { log (connEvent); } private void log ( com.sun.messaging.jms.notification.Event connEvent ) { String eventCode = connEvent.getEventCode(); String eventMessage = connEvent.getEventMessage(); //write event information to the output stream. } }