0 overview
Spring provides a JMS integration framework that simplifies the use of JMS APIs, like the Spring integrated JDBC API.
JMS can be easily divided into two functional areas, the production of messages and the consumption of messages. The Jmstemplate class is used to generate messages and synchronously accept messages. Like other Java EE message-driven styles, for asynchronous messages, spring also provides a number of message listener containers for creating message-driven Pojo (MDPs). Spring also provides a way to declaratively create a message listener.
Org.springframework.jms.core provides the core functionality of using JMS, which contains the Jmstemplate class, similar to Jdbdtemplate in JDBC, which simplifies JMS development by creating and disposing of resources. Spring's template class is widely used as a design principle in the spring framework, and the template class provides a helper method for simple operations, and a proxy for complex operations that provides important processing through the inheritance callback interface. Jmstemplate also follows this design principle, which provides a variety of convenient ways to send messages, synchronize consumer messages, and provide users with JMS sessions and message producers.
The Org.springframework.jms.support provides jmsexception translation functionality. It transforms the jmsexception level of the checked into a mirror hierarchy of uncheckedd anomalies. If the exception thrown is not a subclass of Javax.jms.JmsException, the exception will be encapsulated as unchecked exception uncategorizedjmsexception.
Org.springframework.jms.support.converter provides an abstract messageconverter that translates between Java objects and JMS messages.
Org.springframework.jms.support.destination provides a variety of strategies for managing JMS destination, such as providing service positioning capabilities for destionation stored in Jndi.
Org.springframework.jms.annotation provides support for annotation-driven listeners by using the @jmslistener.
Org.springframework.jms.config supports the parsing of JMS namespaces, while also enabling the configuration of listener containers and the generation of listeners.
Finally, Org.springframework.jms.connection provides an implementation of ConnectionFactory for Standonle applications. It is also the spring Platformtransactionmanager implementation Jmstranscationmanager for JMS transaction management. This allows JMS to be seamlessly integrated into the spring transaction management mechanism as a transactional resource.
1. Exception Handling class module
The transformation of the exception is done in Jmsutils:
/*** Convert The specified checked {@linkjavax.jms.JMSException JMSException} to a * Spring runtime {@linkorg.springframework.jms.JmsException jmsexception} equivalent. * @paramex The original checked jmsexception to convert *@returnThe Spring Runtime jmsexception wrapping the given exception*/ Public Staticjmsexception convertjmsaccessexception (JMSException ex) {Assert.notnull (ex,"JMSException must not being null"); if(exinstanceofjavax.jms.IllegalStateException) {return Neworg.springframework.jms.IllegalStateException ((javax.jms.IllegalStateException) ex); } if(exinstanceofjavax.jms.InvalidClientIDException) {return Newinvalidclientidexception ((javax.jms.InvalidClientIDException) ex); } if(exinstanceofjavax.jms.InvalidDestinationException) {return Newinvaliddestinationexception ((javax.jms.InvalidDestinationException) ex); } if(exinstanceofjavax.jms.InvalidSelectorException) {return Newinvalidselectorexception ((javax.jms.InvalidSelectorException) ex); } if(exinstanceofjavax.jms.JMSSecurityException) {return Newjmssecurityexception ((javax.jms.JMSSecurityException) ex); } if(exinstanceofjavax.jms.MessageEOFException) {return Newmessageeofexception ((javax.jms.MessageEOFException) ex); } if(exinstanceofjavax.jms.MessageFormatException) {return Newmessageformatexception ((javax.jms.MessageFormatException) ex); } if(exinstanceofjavax.jms.MessageNotReadableException) {return Newmessagenotreadableexception ((javax.jms.MessageNotReadableException) ex); } if(exinstanceofjavax.jms.MessageNotWriteableException) {return Newmessagenotwriteableexception ((javax.jms.MessageNotWriteableException) ex); } if(exinstanceofjavax.jms.ResourceAllocationException) {return Newresourceallocationexception ((javax.jms.ResourceAllocationException) ex); } if(exinstanceofjavax.jms.TransactionInProgressException) {return Newtransactioninprogressexception ((javax.jms.TransactionInProgressException) ex); } if(exinstanceofjavax.jms.TransactionRolledBackException) {return Newtransactionrolledbackexception ((javax.jms.TransactionRolledBackException) ex); } //fallback return NewUncategorizedjmsexception (ex); }
2. config module
Supports parsing of JMS namespaces, as well as configuring listening containers and generating listeners. The structure is as follows:
Among them, the listening container is used in the Jmsnamespacehandler, as follows:
Public class extends namespacehandlersupport { @Override publicvoid init () { Registerbeandefinitionparser (new jmslistenercontainerparser ()); Registerbeandefinitionparser (new jcalistenercontainerparser ());} }
3. Connection Module
Provides an implementation of the ConnectionFactory for Standonle applications. It is also the spring Platformtransactionmanager implementation Jmstranscationmanager for JMS transaction management. This allows JMS to be seamlessly integrated into the spring transaction management mechanism as a transactional resource. The structure is as follows:
Jmstemplate requires a connectionfactory reference, connectionfactory as part of the JSM specification, as a key element in the JMS interaction, used as a factory-created and JMS The provider connects to the client app's connection and encapsulates several types of configuration parameters, which are typically indicated by the JSM provider, such as SSL configuration options.
Singleconnectionfactory returns the same connection Connectin when creating the connection and ignores the close () call. It applies to both the test environment and the standalone environment, because the same connection can be called by multiple jmstemplate, which can span multiple transactions. Singleconnectionfactory has a standard connectionfactory reference that may come from Jndi.
The cachingconnectionfactory expands the Singleconnectionfactory function, adding the session cache, MessageProducer and Messageconsumer. The initialized size of the cache is set to 1, using the
4. Core Module
Provides the core functionality of using JMS.
When using jmstemplate, you only need to inherit the callback interface, you can define a high-level protocol by inheriting the call interface, and the Messagecreator callback interface creates a message at the specified session. It can only be called by Jmstemplate. To meet the more complex applications of the JMS API, Sessioncallback provides the user with a JMS Session,producercallback exposing the session and MessageProducer two.
The JMS API provides two types of send methods, one setting delivery mode, priority, survival time (time-to-live) as the QoS parameter, and the other using default values that do not provide QoS parameters.
5. Listener Module
The Message Listener container (Messagelistenercontainer) is used to accept messages from the JMS message queue and then push the registers into the message listeners (MessageListener) inside it. Spring provides two standard JMS message monitoring containers, with the following features:
Simplemessagelistenercontainer: At startup, create a fixed number of JMS sessions and a consumer, using the standard JMS Messageconsumer.setmessagelistener () method to register the listener, Let the JMS provider return the listener.
Defaultmessagelistenercontainer: Supports dynamic adaptation at runtime and can participate in externally managed transactions. Each received message is registered as an XA transaction using Jtatransactionmanager, so the XA transaction semantics can be leveraged for processing.
6. Remoting Module
Org.aopalliance.intercept.MethodInterceptor is used to receive JMS-based remote services.
Jmsinvokerclientinterceptor: Serializes a remote trigger object and deserializes a remote trigger result object, using a Java serialization method, such as RMI.
JMSINVOKERPROXYFACTORYBEAN:JMS the factory bean that triggers the agent, exposing the agent service referenced by the bean, using a specific service interface.
JMSINVOKERSERVICEEXPORTER:JMS a message listener that exposes a specific service bean as a terminal for a JSM message, which is obtained through a JMS trigger proxy.
Summary
Spring provides a JMS integration framework that simplifies the use of JMS APIs, like the Spring integrated JDBC API.
Spring source analysis of the SPRING-JMS module detailed