【Spring】Spring Framework Reference Documentation中文版27

30. JMS (Java Message Service)

Java消息服务)

 

30.1 Introduction

介绍

 

Spring provides a JMS integration framework that simplifies the use of the JMS API much like Springs integration does for the JDBC API.

spring提供了JMS集成框架可以简单的使用JMSAPI就像使用spring集成JDBCAPI一样。

 

JMS can be roughly divided into two areas of functionality, namely the production and consumption of messages. The JmsTemplate class is used for message production and synchronous message reception. For asynchronous reception similar to Java EEs message-driven bean style, Spring provides a number of message listener containers that are used to create Message-Driven POJOs (MDPs). Spring also provides a declarative way of creating message listeners.

JMS可以分为两种功能灵越,分别为生产消息和消费消息。JmsTemplate类被用于产生消息并且且同步接收消息。对于同步接收类似于JavaEE的消息驱动bean的风格。spring提供了一系列消息监听器容器用于创建消息驱动的POJOspring也提供了声明的方式来创建消息监听器。

 

The package org.springframework.jms.core provides the core functionality for using JMS. It contains JMS template classes that simplify the use of the JMS by handling the creation and release of resources, much like the JdbcTemplate does for JDBC. The design principle common to Spring template classes is to provide helper methods to perform common operations and for more sophisticated usage, delegate the essence of the processing task to user implemented callback interfaces. The JMS template follows the same design. The classes offer various convenience methods for the sending of messages, consuming a message synchronously, and exposing the JMS session and message producer to the user.

org.springframework.jms.core包提供了使用JMS的核心功能。他包括JMS模板类用于简单使用JMS通过处理创建和释放资源,就像JdbcTemplate用于JDBC一样。和spring的模板类的设计原则一样提供了helper方法用于执行相同的操作代替复杂的使用,委托处理任务通过实现回调接口。JMS模板符合相同的设计。这个类提供了不同的方便的方法用于发送消息、同步消费消息、暴露JMS会话和生产消息给用户。

 

The package org.springframework.jms.support provides JMSException translation functionality. The translation converts the checked JMSException hierarchy to a mirrored hierarchy of unchecked exceptions. If there are any provider specific subclasses of the checked javax.jms.JMSException, this exception is wrapped in the unchecked UncategorizedJmsException.

org.springframework.jms.support包提供了JMSException异常的翻译功能。翻译转换器转换JMSException的异常结构为一个小范围的非检查异常。如果子类抛出了检查异常javax.jms.JMSException,这个异常会被包裹为非检查的UncategorizedJmsException异常。

 

The package org.springframework.jms.support.converter provides a MessageConverter abstraction to convert between Java objects and JMS messages.

org.springframework.jms.support.converter提供了MessageConverter的抽象用于转换JavaobjectJMS的消息。

 

The package org.springframework.jms.support.destination provides various strategies for managing JMS destinations, such as providing a service locator for destinations stored in JNDI.

org.springframework.jms.support.destination提供了不同的策略用于管理JMS的目的地,例如提供一个服务定位器用于存储在JNDI中的目的地。

 

The package org.springframework.jms.annotation provides the necessary infrastructure to support annotation-driven listener endpoints using @JmsListener.

org.springframework.jms.annotation提供了必要的基础结构用于支持注解监听器端点通过使用@JmsListener

 

The package org.springframework.jms.config provides the parser implementation for the jms namespace as well the java config support to configure listener containers and create listener endpoints.

org.springframework.jms.config提供了解析实现对于jms命名空间类似于java配置来支持配置监听器容器和创建监听器端点。

 

Finally, the package org.springframework.jms.connection provides an implementation of the ConnectionFactory suitable for use in standalone applications. It also contains an implementation of Springs PlatformTransactionManager for JMS (the cunningly named JmsTransactionManager). This allows for seamless integration of JMS as a transactional resource into Springs transaction management mechanisms.

最后,org.springframework.jms.connection包提供了一个ConnectionFactory的实现用于单独使用的应用。他包括springPlatformTransactionManager实现用于JMS(名字为JmsTransactionManager)。允许无缝的集成JMS作为一个传统的资源到spring的视图管理策略中。

 

30.2 Using Spring JMS

使用springJMS

 

30.2.1 JmsTemplate

 

The JmsTemplate class is the central class in the JMS core package. It simplifies the use of JMS since it handles the creation and release of resources when sending or synchronously receiving messages.

JmsTemplate类是JMS核心包中的中心类。他使得简单的使用JMS因为他处理了创建和释放资源当发送或同步接收消息的时候。

 

Code that uses the JmsTemplate only needs to implement callback interfaces giving them a clearly defined high level contract. The MessageCreator callback interface creates a message given a Session provided by the calling code in JmsTemplate. In order to allow for more complex usage of the JMS API, the callback SessionCallback provides the user with the JMS session and the callback ProducerCallback exposes a Session and MessageProducer pair.

使用JmsTemplate的代码只需要实现回调接口使得可以实现很高级别的抽象。MessageCreator回调接口创建一个消息根据给定的sessionJmsTemplate中的调用代码来提供。用于允许调用复杂的JMSAPI,回调方法SessionCallback提供了用户使用JMSsession和回调ProducerCallback来暴露一个SessionMessageProducer的组合。

 

The JMS API exposes two types of send methods, one that takes delivery mode, priority, and time-to-live as Quality of Service (QOS) parameters and one that takes no QOS parameters which uses default values. Since there are many send methods in JmsTemplate, the setting of the QOS parameters have been exposed as bean properties to avoid duplication in the number of send methods. Similarly, the timeout value for synchronous receive calls is set using the property setReceiveTimeout.

JMSAPI暴露的两种类型的发送方法,一个是接收模式、优先级和存活时间作为服务的状态和另一没有QOS参数但是使用了默认值。虽然在JmsTemplate中有许多发送方法,QOS参数的设置可以暴露作为bean的属性来避免重复发送方法。相似的,同步接收调用的超时时间可以被设置使用setReceiveTimeout属性。

 

Some JMS providers allow the setting of default QOS values administratively through the configuration of the ConnectionFactory. This has the effect that a call to MessageProducers send method `send(Destination destination, Message message) will use different QOS default values than those specified in the JMS specification. In order to provide consistent management of QOS values, the JmsTemplate must therefore be specifically enabled to use its own QOS values by setting the boolean property isExplicitQosEnabled to true.

一些JMS的提供者允许设置默认的QOS值通过配置ConnectionFactory。这是受到了MessageProducer的发送方法的影响将使用不同QOS默认值不同于在JMS中的定义。为了提供一致的管理QOS值,JmsTemplate必须被定义允许使用他们自己的QOS值通过设置布尔属性isExplicitQosEnabledtrue

 

For convenience, JmsTemplate also exposes a basic request-reply operation that allows to send a message and wait for a reply on a temporary queue that is created as part of the operation.

为了方便,JmsTemplate也暴露了一个基本的请求返回选项允许发送消息并且等待返回在一个临时的队列作为创建操作的一部分。

 

[Note]

注意

 

Instances of the JmsTemplate class are thread-safe once configured. This is important because it means that you can configure a single instance of a JmsTemplate and then safely inject this shared reference into multiple collaborators. To be clear, the JmsTemplate is stateful, in that it maintains a reference to a ConnectionFactory, but this state is not conversational state.

JmsTemplate类的实例是线程安全的。这是很重要的因为他意味着你可以简单的配置一个JmsTemplate的单例并且安全的注入到共享引用在多个合作者中。为了清晰,JmsTemplate是有状态的,他包含了一个ConnectionFactory的引用,但是这个状态是不健全的状态。

 

As of Spring Framework 4.1, JmsMessagingTemplate is built on top of JmsTemplate and provides an integration with the messaging abstraction, i.e. org.springframework.messaging.Message. This allows you to create the message to send in generic manner.

由于spring框架4.1JmsMessagingTemplate构建于JmsTemplate之上并且提供了和消息抽象的集成,例如,org.springframework.messaging.Message。这允许你来创建一个消息并且发送通过一种通用的方式。

 

30.2.2 Connections

 

The JmsTemplate requires a reference to a ConnectionFactory. The ConnectionFactory is part of the JMS specification and serves as the entry point for working with JMS. It is used by the client application as a factory to create connections with the JMS provider and encapsulates various configuration parameters, many of which are vendor specific such as SSL configuration options.

JmsTemplate要求一个ConnectionFactory的引用。ConnectionFactoryJMS定义的一部分并且作为一个端点服务于JMS。他被客户端应用所使用作为一个工厂来创建连接用于JMS生产者并且有不同的配置参数,大部分配置参数是特定使用的例如SSL的配置选项。

 

When using JMS inside an EJB, the vendor provides implementations of the JMS interfaces so that they can participate in declarative transaction management and perform pooling of connections and sessions. In order to use this implementation, Java EE containers typically require that you declare a JMS connection factory as a resource-ref inside the EJB or servlet deployment descriptors. To ensure the use of these features with the JmsTemplate inside an EJB, the client application should ensure that it references the managed implementation of the ConnectionFactory.

当你使用JMS来代替EJB时,vendor提供了JMS接口的实现因此她们可以参与声明式事务管理和执行连接池和会话池。为了使用这个实现,JavaEE容器通常要求你定义一个JMS连接工厂作为EJB内部的资源引用或servlet部署描述符。为了保证使用这些在EJB中的特性,客户端应用应当保证他引用了ConnectionFactory的管理实现。

 

Caching Messaging Resources

缓存消息资源

 

The standard API involves creating many intermediate objects. To send a message the following 'API' walk is performed

标准的API调用创建许多中间的object。为了发送消息符合API的执行。

 

ConnectionFactory->Connection->Session->MessageProducer->send

 

Between the ConnectionFactory and the Send operation there are three intermediate objects that are created and destroyed. To optimise the resource usage and increase performance two implementations of ConnectionFactory are provided.

ConnectionFactory和发送操作之间有三个中间object会被创建和销毁。优化资源的使用和增加执行两个ConnectionFactory的实现是已经被提供的。

 

SingleConnectionFactory

 

Spring provides an implementation of the ConnectionFactory interface, SingleConnectionFactory, that will return the same Connection on all createConnection() calls and ignore calls to close(). This is useful for testing and standalone environments so that the same connection can be used for multiple JmsTemplate calls that may span any number of transactions. SingleConnectionFactory takes a reference to a standard ConnectionFactory that would typically come from JNDI.

spring提供了一个ConnectionFactory接口的实现SingleConnectionFactory用于返回相同的连接对于所有的createConnection调用和忽略调用close。这对于测试和单独的应用环境来说是有用的因为相同的连接被多个JmsTemplate调用使用区分多个事务。SingleConnectionFactory有一个标准的ConnectionFactory的引用将通常来源于JNDI

 

CachingConnectionFactory

 

The CachingConnectionFactory extends the functionality of SingleConnectionFactory and adds the caching of Sessions, MessageProducers, and MessageConsumers. The initial cache size is set to 1, use the property sessionCacheSize to increase the number of cached sessions. Note that the number of actual cached sessions will be more than that number as sessions are cached based on their acknowledgment mode, so there can be up to 4 cached session instances when sessionCacheSize is set to one, one for each acknowledgment mode. MessageProducers and MessageConsumers are cached within their owning session and also take into account the unique properties of the producers and consumers when caching. MessageProducers are cached based on their destination. MessageConsumers are cached based on a key composed of the destination, selector, noLocal delivery flag, and the durable subscription name (if creating durable consumers).

CachingConnectionFactory继承了SingleConnectionFactory的功能并且添加了会话的缓存、MessageProducersMessageConsumers。缓存的大小设置为1,使用属性sessionCacheSize来增加缓存会话的数量。注意实际缓存会话的数量见比这个数量多由于会话是缓存基于acknowledgment模式的,因此可以设置四个缓存会话当sessionCacheSize被设置为一的时候,一个用于acknowledgment模式。MessageProducersMessageConsumers被缓存在他们自己的会话中并且考虑独立的生产和消费属性当被缓存的时候。MessageProducers可以被缓存基于他们的目的地。MessageConsumers被缓存基于一个目的地的关键字,选择器,非本地传输标志和持久化的订阅名(如果创建持久化的消费者)。

 

30.2.3 Destination Management

目的地管理

 

Destinations, like ConnectionFactories, are JMS administered objects that can be stored and retrieved in JNDI. When configuring a Spring application context you can use the JNDI factory class JndiObjectFactoryBean / <jee:jndi-lookup> to perform dependency injection on your objects references to JMS destinations. However, often this strategy is cumbersome if there are a large number of destinations in the application or if there are advanced destination management features unique to the JMS provider. Examples of such advanced destination management would be the creation of dynamic destinations or support for a hierarchical namespace of destinations. The JmsTemplate delegates the resolution of a destination name to a JMS destination object to an implementation of the interface DestinationResolver. DynamicDestinationResolver is the default implementation used by JmsTemplate and accommodates resolving dynamic destinations. A JndiDestinationResolver is also provided that acts as a service locator for destinations contained in JNDI and optionally falls back to the behavior contained in DynamicDestinationResolver.

目的地,例如ConnectionFactoriesJMS管理object可以存储并且接收通过JNDI。当配置一个spring应用上下文你可以使用JNDI工厂类JndiObjectFactoryBean/<jee:jndi-lookup>来执行依赖注入你的object引用对于JMS目的地。然而,这种策略是无缝的如果一些目的地在应用中或他们是高级的目的地管理特性并且由JMS提供者唯一提供。例如一些高级的目的地管理将被动态目的地创建或支持目的地的结构化命名空间。JmsTemplate为了目的地名的解决方案对于JMS目的地object对于实现接口DestinationResolverDynamicDestinationResolver是一个默认的实现使用通过JmsTemplate并且解决动态的目的地。JndiDestinationResolver也提供了扮演一个服务定位器用于目的地容器在JNDI中和选择回调对于行为包好在DynamicDestinationResolver中。

 

Quite often the destinations used in a JMS application are only known at runtime and therefore cannot be administratively created when the application is deployed. This is often because there is shared application logic between interacting system components that create destinations at runtime according to a well-known naming convention. Even though the creation of dynamic destinations is not part of the JMS specification, most vendors have provided this functionality. Dynamic destinations are created with a name defined by the user which differentiates them from temporary destinations and are often not registered in JNDI. The API used to create dynamic destinations varies from provider to provider since the properties associated with the destination are vendor specific. However, a simple implementation choice that is sometimes made by vendors is to disregard the warnings in the JMS specification and to use the TopicSession method createTopic(String topicName) or the QueueSession method createQueue(String queueName) to create a new destination with default destination properties. Depending on the vendor implementation, DynamicDestinationResolver may then also create a physical destination instead of only resolving one.

通产目的地使用在JMS应用中可以在运行时可知并且不能创建当应用被部署之后。这是因为共享的应用逻辑在集成系统组件中在运行时创建目的地依赖于已知的命名规范。尽管动态目的地的创建不是JMS规范的一部分,大部分的vendor提供了这种功能。动态目的地被创建使用一个名字定义通过用户和临时的目的地是有差别的因为他们不会注册矮JNDI中。API使用创建动态目的地通过提供者当目的地的属性是特定的vendor。然而你,一个简单的选择实现是vendor完成的对于忽视JMS规范并且使用TopicSession方法createTopicQueueSession方法createQueue来创建一个新的目的地对于默认的目的地属性。依赖于vendor实现,DynamicDestinationResolver也可以创建一个物理的目的地代替被解析的。

 

The boolean property pubSubDomain is used to configure the JmsTemplate with knowledge of what JMS domain is being used. By default the value of this property is false, indicating that the point-to-point domain, Queues, will be used. This property used by JmsTemplate determines the behavior of dynamic destination resolution via implementations of the DestinationResolver interface.

布尔属性pubSubDomain被用于配置JmsTemplate通过一致的JMS主机来使用。这个属性的默认值是false,指定了点对点的主机、队列将被使用。JmsTemplate使用这个属性来决定动态目的地的行为通过DestinationResolver接口的实现。

 

You can also configure the JmsTemplate with a default destination via the property defaultDestination. The default destination will be used with send and receive operations that do not refer to a specific destination.

你也可以配置JmsTemplate使用默认的目的地通过defaultDestination属性。默认的目的地将被使用来发送和接收操作而不需要引用特定的目的地。

 

30.2.4 Message Listener Containers

消息监听容器

 

One of the most common uses of JMS messages in the EJB world is to drive message-driven beans (MDBs). Spring offers a solution to create message-driven POJOs (MDPs) in a way that does not tie a user to an EJB container. (See Section 30.4.2, Asynchronous Reception - Message-Driven POJOsfor detailed coverage of Springs MDP support.) As from Spring Framework 4.1, endpoint methods can be simply annotated using @JmsListener see Section 30.6, Annotation-driven listener endpointsfor more details.

一个JMS消息的通用使用在EJB中是消息驱动beanspring提供了一个创建消息驱动pojo的解决方案而不需要绑定到EJB的容器中。(见章节30.4.2,“异步的接收消息驱动POJO”来了解springMDP支持)。来自spirng框架4.1endpoint方法可以被简单的注解使用@JmsListener见章节30.6,“注解驱动监听器endpoint”来了解更多细节。

 

A message listener container is used to receive messages from a JMS message queue and drive the MessageListener that is injected into it. The listener container is responsible for all threading of message reception and dispatches into the listener for processing. A message listener container is the intermediary between an MDP and a messaging provider, and takes care of registering to receive messages, participating in transactions, resource acquisition and release, exception conversion and suchlike. This allows you as an application developer to write the (possibly complex) business logic associated with receiving a message (and possibly responding to it), and delegates boilerplate JMS infrastructure concerns to the framework.

消息监听器容器被使用来接收来自JMS消息队列的消息和驱动被注入的MessageListener。这个监听器容器对于消息线程接受和分发给处理监听器。消息监听器容器是MDP和消息提供者之间的桥梁并且处理注册收到消息,参与事务、资源获取和释放,异常转换等等。这允许你作为一个应用开发者来书写(比较复杂)的业务逻辑对于消息的处理(和对他的响应),并且定义引用JMS基础结构包括在框架中。

 

There are two standard JMS message listener containers packaged with Spring, each with its specialised feature set.

这里有两个标准的JMS消息监听容器包在spring中,都有其自己的特性。

 

SimpleMessageListenerContainer

 

This message listener container is the simpler of the two standard flavors. It creates a fixed number of JMS sessions and consumers at startup, registers the listener using the standard JMS MessageConsumer.setMessageListener() method, and leaves it up the JMS provider to perform listener callbacks. This variant does not allow for dynamic adaption to runtime demands or for participation in externally managed transactions. Compatibility-wise, it stays very close to the spirit of the standalone JMS specification - but is generally not compatible with Java EEs JMS restrictions.

这个消息监听器容器是两个标准实现之一。他创建一个固定数量的JMS会话和消费者在最初启动时,注册监听器使用标准的JMSMessageConsumer.setMessageListener方法并且将其绑定到JMS提供者来执行监听器的回调方法。这个变化不需要动态的适应对于运行时的需求来参与额外的管理事务。他接近于标准的JMS规范但是通常不适用于JavaEEJMS约束。

 

[Note]

注意

 

While SimpleMessageListenerContainer does not allow for the participation in externally managed transactions, it does support native JMS transactions: simply switch the 'sessionTransacted' flag to 'true' or, in the namespace, set the 'acknowledge' attribute to 'transacted': Exceptions thrown from your listener will lead to a rollback then, with the message getting redelivered. Alternatively, consider using 'CLIENT_ACKNOWLEDGE' mode which provides redelivery in case of an exception as well but does not use transacted Sessions and therefore does not include any other Session operations (such as sending response messages) in the transaction protocol.

SimpleMessageListenerContainer不需要参与额外的事务管理,他支持本地的JMS事务:简单的切换sessionTransacted标记为true或在命名空间中设置acknowledge属性为transacted:监听器中抛出的异常将导致回滚,消息会被再次投递。作为提到,考虑使用CLIENT_ACKNOWLEDGE模式提供了再次头次避免异常但是没有使用事务的会话并且不包括其他的会话操作(例如发送响应消息)在事务协议中。

 

DefaultMessageListenerContainer

 

This message listener container is the one used in most cases. In contrast to SimpleMessageListenerContainer, this container variant allows for dynamic adaptation to runtime demands and is able to participate in externally managed transactions. Each received message is registered with an XA transaction when configured with a JtaTransactionManager; so processing may take advantage of XA transaction semantics. This listener container strikes a good balance between low requirements on the JMS provider, advanced functionality such as the participation in externally managed transactions, and compatibility with Java EE environments.

这个消息监听器容器是一个用于大部分的情况。相对于SimpleMessageListenerContainer,这个容器变化允许动态的适应运行时的需求并且可以参与额外的事务管理。每个接收消息符合XA事务规范当配置了JtaTransactionManager:因此除了可以使用XA事务语义的优势。这个监听器容器有一个很好的平衡在低需求对于JMS提供者,高级的功能例如参与外部的事务管理和处理复杂的JavaEE环境。

 

The cache level of the container can be customized. Note that when no caching is enabled, a new connection and a new session is created for each message reception. Combining this with a non durable subscription with high loads may lead to message lost. Make sure to use a proper cache level in such case.

容器中缓存的级别可以是自定义的。注意当允许缓存时,一个新的容器和一个新的会话是创建对于每一个消息接收的。组合他们使用一个非持久的定于对于高负载会导致消息的丢失。保证使用适当的缓存级别在一些特定的情况中。

 

This container also has recoverable capabilities when the broker goes down. By default, a simple BackOff implementation retries every 5 seconds. It is possible to specify a custom BackOff implementation for more fine-grained recovery options, see ExponentialBackOff for an example.

这个容器也有可回收的功能当消息代理失效的时候。默认的一个简单的BackOff实现会在每五秒钟进行重试。他定义了自定义的BackOff实现用于大部分恢复选项,见ExponentialBackOff的例子。

 

[Note]

注意

 

Like its sibling SimpleMessageListenerContainer, DefaultMessageListenerContainer supports native JMS transactions and also allows for customizing the acknowledgment mode. This is strongly recommended over externally managed transactions if feasible for your scenario: that is, if you can live with occasional duplicate messages in case of the JVM dying. Custom duplicate message detection steps in your business logic may cover such situations, e.g. in the form of a business entity existence check or a protocol table check. Any such arrangements will be significantly more efficient than the alternative: wrapping your entire processing with an XA transaction (through configuring your DefaultMessageListenerContainer with an JtaTransactionManager), covering the reception of the JMS message as well as the execution of the business logic in your message listener (including database operations etc).

就像SimpleMessageListenerContainerDefaultMessageListenerContainer支持本地的JMS事务并且允许自定义确认模式。这是被推荐使用的对于外部的事务管理如果他符合你的场景:就是如果存在偶尔的重复消息由于JVM的失效。自定义的重复消息在你的业务逻辑中可以包含这样的请求,例如,在业务实例检查或一个协议表检查。任何这样的处理都是有意义的并且有很好的作用:包裹你的整个处理通过XA事务(通过配置你的DefaultMessageListenerContainer使用JtaTransactionManager),覆盖JMS消息的接收作为业务的执行逻辑在你的消息监听中(包括数据库的操作等等)。

 

30.2.5 Transaction management

事务管理

 

Spring provides a JmsTransactionManager that manages transactions for a single JMS ConnectionFactory. This allows JMS applications to leverage the managed transaction features of Spring as described in Chapter 17, Transaction Management. The JmsTransactionManager performs local resource transactions, binding a JMS Connection/Session pair from the specified ConnectionFactory to the thread. JmsTemplate automatically detects such transactional resources and operates on them accordingly.

spring提供了一个JmsTransactionManager来管理事务用于单个的JMSConnectionFactory。这允许JMS应用来影响管理spring的事务特性作为描述在章节17中“事务管理”。JmsTransactionManager执行本地的资源事务,绑定一个JMS连接或会话来自特定的ConnectionFactory相对于线程。JmsTemplate自动探测事务资源和操作。

 

In a Java EE environment, the ConnectionFactory will pool Connections and Sessions, so those resources are efficiently reused across transactions. In a standalone environment, using Springs SingleConnectionFactory will result in a shared JMS Connection, with each transaction having its own independent Session. Alternatively, consider the use of a provider-specific pooling adapter such as ActiveMQs PooledConnectionFactory class.

JavaEE环境中,ConnectionFactory将池化连接和会话,因此这些资源可以有效的重用跨事务。在独立的环境中,使用springSingleConnectionFactory将导致共享的JMS连接,每个事务有其独立的会话。作为替代,考虑使用特定的池适配器例如ActiveMQPooledConnectionFactory类。

 

JmsTemplate can also be used with the JtaTransactionManager and an XA-capable JMS ConnectionFactory for performing distributed transactions. Note that this requires the use of a JTA transaction manager as well as a properly XA-configured ConnectionFactory! (Check your Java EE servers / JMS providers documentation.)

JmsTemplate可以使用JtaTransactionManager和一个XAJMSConnectionFactory用于执行分布式的事务。注意这个需要是使用JTA事务管理作为XA配置的ConnectionFactory!(检查你的JavaEE服务器/JMS提供者的文档。)

 

Reusing code across a managed and unmanaged transactional environment can be confusing when using the JMS API to create a Session from a Connection. This is because the JMS API has only one factory method to create a Session and it requires values for the transaction and acknowledgment modes. In a managed environment, setting these values is the responsibility of the environments transactional infrastructure, so these values are ignored by the vendors wrapper to the JMS Connection. When using the JmsTemplate in an unmanaged environment you can specify these values through the use of the properties sessionTransacted and sessionAcknowledgeMode. When using a PlatformTransactionManager with JmsTemplate, the template will always be given a transactional JMS Session.

重用代码跨管理事务环境可以是复杂的当使用JMSAPI来创建一个会话来自一个连接。这是因为JMSAPI只有一个工厂方法来创建会话并且他要求用于事务和确认模式。在一个管理环境中,设置这些值是环境事务架构的任务,因此这些被vendor处理器忽略对于处理JMS连接。当使用JmsTemplate在一个非管理的环境中,你可以哦定义这些值通过使用属性sessionTransactedsessionAcknowledgeMode。当使用JmsTemplate中的PlatformTransactionManager,模板将被给予一个事务的JMS会话。

 

30.3 Sending a Message

发送一个消息

 

The JmsTemplate contains many convenience methods to send a message. There are send methods that specify the destination using a javax.jms.Destination object and those that specify the destination using a string for use in a JNDI lookup. The send method that takes no destination argument uses the default destination.

JmsTemplate容器包含许多方便的方法来发送消息。发送方法定义的目的地使用javax.jms.Destinationobject并且定义的目的地使用一个字符串用于使用在JNDI查找中。发送方法如果没有定义目的地则使用默认的目的地。

 

import javax.jms.ConnectionFactory;

import javax.jms.JMSException;

import javax.jms.Message;

import javax.jms.Queue;

import javax.jms.Session;

 

import org.springframework.jms.core.MessageCreator;

import org.springframework.jms.core.JmsTemplate;

 

public class JmsQueueSender {

 

    private JmsTemplate jmsTemplate;

    private Queue queue;

 

    public void setConnectionFactory(ConnectionFactory cf) {

        this.jmsTemplate = new JmsTemplate(cf);

    }

 

    public void setQueue(Queue queue) {

        this.queue = queue;

    }

 

    public void simpleSend() {

        this.jmsTemplate.send(this.queue, new MessageCreator() {

            public Message createMessage(Session session) throws JMSException {

                return session.createTextMessage("hello queue world");

            }

        });

    }

}

 

This example uses the MessageCreator callback to create a text message from the supplied Session object. The JmsTemplate is constructed by passing a reference to a ConnectionFactory. As an alternative, a zero argument constructor and connectionFactory is provided and can be used for constructing the instance in JavaBean style (using a BeanFactory or plain Java code). Alternatively, consider deriving from Springs JmsGatewaySupport convenience base class, which provides pre-built bean properties for JMS configuration.

这个例子使用了MessageCreator的回调方法来创建一个文本信息来自提供的会话objectJmsTemplate被创建通过传递一个ConnectionFactory的引用。作为替代,一个无参数构造器和connectionFactory被提供并且用于构造JavaBean风格的实例(使用BeanFactory或普通的Java代码)。考虑使用springJmsGatewaySupport的基类,提供了提前构建bean属性用于JMS配置。

 

The method send(String destinationName, MessageCreator creator) lets you send a message using the string name of the destination. If these names are registered in JNDI, you should set the destinationResolver property of the template to an instance of JndiDestinationResolver.

方法send(String destinationName, MessageCreator creator)使得你发送一个信息使用字符串类型的目的地。如果这些字符串注册在JNDI中,你应当设置模板的destinationResolver属性对于JndiDestinationResolver的实例。

 

If you created the JmsTemplate and specified a default destination, the send(MessageCreator c) sends a message to that destination.

如果你创建JmsTemplate并且指定默认的目的地,send(MessageCreator c)会发送消息到这个目的地。

 

30.3.1 Using Message Converters

使用消息转换器

 

In order to facilitate the sending of domain model objects, the JmsTemplate has various send methods that take a Java object as an argument for a messages data content. The overloaded methods convertAndSend() and receiveAndConvert() in JmsTemplate delegate the conversion process to an instance of the MessageConverter interface. This interface defines a simple contract to convert between Java objects and JMS messages. The default implementation SimpleMessageConverter supports conversion between String and TextMessage, byte[] and BytesMesssage, and java.util.Map and MapMessage. By using the converter, you and your application code can focus on the business object that is being sent or received via JMS and not be concerned with the details of how it is represented as a JMS message.

为了帮助发送domain模型objectJmsTemplate有不同的发送方法可以使得Javaobject作为一个消息数据内容的参数。重载的方法convertAndSendreceiveAndConvertJmsTemplate中定义了转换的程序对于MessageConverter接口的实例。这个接口定义了一个简单的转换对于JavaobjectJMS消息。默认实现SimpleMessageConverter支持字符串和TextMessage、字节数组和BytesMesssagejava.util.MapMapMessage之间的转换。通过使用转换器,你和你的应用代码可以关注于业务逻辑有关接收和发送通过JMS并且不需要关心他们是如何实现通过JMS的消息。

 

The sandbox currently includes a MapMessageConverter which uses reflection to convert between a JavaBean and a MapMessage. Other popular implementation choices you might implement yourself are Converters that use an existing XML marshalling package, such as JAXB, Castor, XMLBeans, or XStream, to create a TextMessage representing the object.

沙盒中当前包括一个MapMessageConverter使用反射来转换JavaBeanMapMessage。其他object实现选择你可以实现你自己是Converters使用一个已有的xml编辑包,例如JAXBCastorXMLBeansXStream来创建TextMessage来代表一个object

 

To accommodate the setting of a messages properties, headers, and body that can not be generically encapsulated inside a converter class, the MessagePostProcessor interface gives you access to the message after it has been converted, but before it is sent. The example below demonstrates how to modify a message header and a property after a java.util.Map is converted to a message.

为了使用消息属性、消息头和消息的设置你不能将其一起封装DAO一个转化器类中,MessagePostProcessor接口给予你访问消息在他被转换之后发送之前。下面的例子展示了如何修改一个消息头并且在java.util.Map被转换为一个消息后。

 

public void sendWithConversion() {

    Map map = new HashMap();

    map.put("Name", "Mark");

    map.put("Age", new Integer(47));

    jmsTemplate.convertAndSend("testQueue", map, new MessagePostProcessor() {

        public Message postProcessMessage(Message message) throws JMSException {

            message.setIntProperty("AccountID", 1234);

            message.setJMSCorrelationID("123-00001");

            return message;

        }

    });

}

 

This results in a message of the form:

消息的结果如下面的内容:

 

MapMessage={

Header={

... standard headers ...

CorrelationID={123-00001}

}

Properties={

AccountID={Integer:1234}

}

Fields={

Name={String:Mark}

Age={Integer:47}

}

}

 

30.3.2 SessionCallback and ProducerCallback

 

While the send operations cover many common usage scenarios, there are cases when you want to perform multiple operations on a JMS Session or MessageProducer. The SessionCallback and ProducerCallback expose the JMS Session and Session / MessageProducer pair respectively. The execute() methods on JmsTemplate execute these callback methods.

当发送操作覆盖许多通用的使用场景,当你希望执行多个选项对于JMS会话或MessageProducerSessionCallbackProducerCallback暴露了JMS会话和Session / MessageProducer组合。JmsTemplate中的execute方法会执行这些回调方法。

 

30.4 Receiving a message

接收一个消息

 

30.4.1 Synchronous Reception

同步接收

 

While JMS is typically associated with asynchronous processing, it is possible to consume messages synchronously. The overloaded receive(..) methods provide this functionality. During a synchronous receive, the calling thread blocks until a message becomes available. This can be a dangerous operation since the calling thread can potentially be blocked indefinitely. The property receiveTimeout specifies how long the receiver should wait before giving up waiting for a message.

JMS通常连接作为异步的接收,消费信息是同步的。重载的receive方法提供了这样的功能。在同步接收时,调用线程的阻塞直到消息完全可用。这是一个危险的操作因为调用线程可能不确定是否阻塞。receiveTimeout属性定义了等待接收的时间在等待一个接收消息之前。

 

30.4.2 Asynchronous Reception - Message-Driven POJOs

异步接受————消息驱动POJO

 

[Note]

注意

 

Spring also supports annotated-listener endpoints through the use of the @JmsListener annotation and provides an open infrastructure to register endpoints programmatically. This is by far the most convenient way to setup an asynchronous receiver, see Section 30.6.1, Enable listener endpoint annotationsfor more details.

spring也支持注解监听器端点通过使用@JmsListener注解并且提供了一个开发的基础设置来编程注册端点。这是十分方便的来设置一个异步的接收,见章节30.6.1,“允许监听端点注解”来了解详情。

 

In a fashion similar to a Message-Driven Bean (MDB) in the EJB world, the Message-Driven POJO (MDP) acts as a receiver for JMS messages. The one restriction (but see also below for the discussion of the MessageListenerAdapter class) on an MDP is that it must implement the javax.jms.MessageListener interface. Please also be aware that in the case where your POJO will be receiving messages on multiple threads, it is important to ensure that your implementation is thread-safe.

对于消息驱动的beanEJB中,消息驱动POJO作为一个接收消息的角色。一个限制(但参见用于目的地的MessageListenerAdapter类)对于MDP是必须实现javax.jms.MessageListener接口的。请注意在这个例子中你的POJO将接收消息来自多个线程,这是重要的来保证你的实现是线程安全的。

 

Below is a simple implementation of an MDP:

下面是一个MDP的简单实现:

 

import javax.jms.JMSException;

import javax.jms.Message;

import javax.jms.MessageListener;

import javax.jms.TextMessage;

 

public class ExampleListener implements MessageListener {

 

    public void onMessage(Message message) {

        if (message instanceof TextMessage) {

            try {

                System.out.println(((TextMessage) message).getText());

            }

            catch (JMSException ex) {

                throw new RuntimeException(ex);

            }

        }

        else {

            throw new IllegalArgumentException("Message must be of type TextMessage");

        }

    }

 

}

 

Once youve implemented your MessageListener, its time to create a message listener container.

一旦你实现了你的MessageListener,是时候创建一个消息监听容器了。

 

Find below an example of how to define and configure one of the message listener containers that ships with Spring (in this case the DefaultMessageListenerContainer).

发现下面一个例子有关如何定义和配置一个消息监听容器在spring中(在这个例子中是DefaultMessageListenerContainer)。

 

<!-- this is the Message Driven POJO (MDP) -->

<bean id="messageListener" class="jmsexample.ExampleListener" />

 

<!-- and this is the message listener container -->

<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">

    <property name="connectionFactory" ref="connectionFactory"/>

    <property name="destination" ref="destination"/>

    <property name="messageListener" ref="messageListener" />

</bean>

 

Please refer to the Spring javadocs of the various message listener containers for a full description of the features supported by each implementation.

请参考springjavadocs对于不同的消息监听器实现来了解详尽的特性支持对于每个实现。

 

30.4.3 the SessionAwareMessageListener interface

SessionAwareMessageListener接口

 

The SessionAwareMessageListener interface is a Spring-specific interface that provides a similar contract to the JMS MessageListener interface, but also provides the message handling method with access to the JMS Session from which the Message was received.

SessionAwareMessageListener是一个spring指定的接口提供了一个相似的缩写对于JMSMessageListener接口,但是也提供了消息处理方法跨越JMS会话对于消息的接收。

 

package org.springframework.jms.listener;

 

public interface SessionAwareMessageListener {

 

    void onMessage(Message message, Session session) throws JMSException;

 

}

 

You can choose to have your MDPs implement this interface (in preference to the standard JMS MessageListener interface) if you want your MDPs to be able to respond to any received messages (using the Session supplied in the onMessage(Message, Session) method). All of the message listener container implementations that ship with Spring have support for MDPs that implement either the MessageListener or SessionAwareMessageListener interface. Classes that implement the SessionAwareMessageListener come with the caveat that they are then tied to Spring through the interface. The choice of whether or not to use it is left entirely up to you as an application developer or architect.

你可以选择有你的MDP实现这个接口(优先于标准的JMSMessageListener接口)如果你希望你的MDP可以响应任何接收的消息(使用会话提供在onMessage(Message, Session)方法中)。所有的消息监听容器实现在spring中支持MDP实现MessageListener接口或SessionAwareMessageListener接口。类实现了SessionAwareMessageListener接口是有警告的她们绑定域spring通过这个接口。是否使用取决于应用开发者或架构师。

 

Please note that the 'onMessage(..)' method of the SessionAwareMessageListener interface throws JMSException. In contrast to the standard JMS MessageListener interface, when using the SessionAwareMessageListener interface, it is the responsibility of the client code to handle any exceptions thrown.

请注意SessionAwareMessageListener接口中的'onMessage(..)'方法抛出JMSException。相对于标准的JMSMessageListener接口,当使用SessionAwareMessageListener接口,他代表客户端代码来处理抛出的异常。

 

30.4.4 the MessageListenerAdapter

 

The MessageListenerAdapter class is the final component in Springs asynchronous messaging support: in a nutshell, it allows you to expose almost any class as a MDP (there are of course some constraints).

MessageListenerAdapter是一个spring的异步消息支持的最后组件:简单的,他允许你暴露几乎所有的类作为一个MDP(当然有一些限制)。

 

Consider the following interface definition. Notice that although the interface extends neither the MessageListener nor SessionAwareMessageListener interfaces, it can still be used as a MDP via the use of the MessageListenerAdapter class. Notice also how the various message handling methods are strongly typed according to the contents of the various Message types that they can receive and handle.

考虑下面的接口定义。注意尽管接口继承了MessageListenerSessionAwareMessageListener接口,他依然可以被使用作为一个MDP通过使用MessageListenerAdapter类。注意不同的消息处理方法是强类型相关的对于他们可以接收和处理的消息类型。

 

public interface MessageDelegate {

 

    void handleMessage(String message);

 

    void handleMessage(Map message);

 

    void handleMessage(byte[] message);

 

    void handleMessage(Serializable message);

 

}

 

public class DefaultMessageDelegate implements MessageDelegate {

    // implementation elided for clarity...

}

 

In particular, note how the above implementation of the MessageDelegate interface (the above DefaultMessageDelegate class) has no JMS dependencies at all. It truly is a POJO that we will make into an MDP via the following configuration.

特定的,注意上面的MessageDelegate接口实现(上面的DefaultMessageDelegate类)没有JMS依赖。他是一个POJO可以作为一个MDP通过下面的配置。

 

<!-- this is the Message Driven POJO (MDP) -->

<bean id="messageListener" class="org.springframework.jms.listener.adapter.MessageListenerAdapter">

    <constructor-arg>

        <bean class="jmsexample.DefaultMessageDelegate"/>

    </constructor-arg>

</bean>

 

<!-- and this is the message listener container... -->

<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">

    <property name="connectionFactory" ref="connectionFactory"/>

    <property name="destination" ref="destination"/>

    <property name="messageListener" ref="messageListener" />

</bean>

 

Below is an example of another MDP that can only handle the receiving of JMS TextMessage messages. Notice how the message handling method is actually called 'receive' (the name of the message handling method in a MessageListenerAdapter defaults to 'handleMessage'), but it is configurable (as you will see below). Notice also how the 'receive(..)' method is strongly typed to receive and respond only to JMS TextMessage messages.

下面是另一个MDP的例子只能处理接收JMSTextMessage消息。注意消息的处理实际是调用receive(消息处理方法的名字在MessageListenerAdapter中默认是handleMessage),但是他是可配置的(见如下的配置)。注意receive方法是相关于JMSTextMessage消息的接收和响应。

 

public interface TextMessageDelegate {

 

    void receive(TextMessage message);

 

}

 

public class DefaultTextMessageDelegate implements TextMessageDelegate {

    // implementation elided for clarity...

}

 

The configuration of the attendant MessageListenerAdapter would look like this:

额外的MessageListenerAdapter的配置看起来是如下的:

 

<bean id="messageListener" class="org.springframework.jms.listener.adapter.MessageListenerAdapter">

    <constructor-arg>

        <bean class="jmsexample.DefaultTextMessageDelegate"/>

    </constructor-arg>

    <property name="defaultListenerMethod" value="receive"/>

    <!-- we don't want automatic message context extraction -->

    <property name="messageConverter">

        <null/>

    </property>

</bean>

 

Please note that if the above 'messageListener' receives a JMS Message of a type other than TextMessage, an IllegalStateException will be thrown (and subsequently swallowed). Another of the capabilities of the MessageListenerAdapter class is the ability to automatically send back a response Message if a handler method returns a non-void value. Consider the interface and class:

请注意如果上面的messageListener接收一个JMS消息而不是TextMessage的类型,IllegalStateException异常将被抛出(并且随后被吞没)。MessageListenerAdapter类的另一个功能时可以自动发送响应消息如果处理器方法返回了一个非void的值。考虑下面接口和类:

 

public interface ResponsiveTextMessageDelegate {

 

    // notice the return type...

    String receive(TextMessage message);

 

}

 

public class DefaultResponsiveTextMessageDelegate implements ResponsiveTextMessageDelegate {

    // implementation elided for clarity...

}

 

If the above DefaultResponsiveTextMessageDelegate is used in conjunction with a MessageListenerAdapter then any non-null value that is returned from the execution of the 'receive(..)' method will (in the default configuration) be converted into a TextMessage. The resulting TextMessage will then be sent to the Destination (if one exists) defined in the JMS Reply-To property of the original Message, or the default Destination set on the MessageListenerAdapter (if one has been configured); if no Destination is found then an InvalidDestinationException will be thrown (and please note that this exception will not be swallowed and will propagate up the call stack).

如果上面的DefaultResponsiveTextMessageDelegate被用于连接MessageListenerAdapter任何的非空值来自receive方法的返回将(在默认的配置下)被转换为TextMessage。结果TextMessage将被发送给目的地(如果存在的话)定义在原始JMS消息的的Reply-To属性中,或默认的目的地被设置在MessageListenerAdapter中(如果已经被配置了),如果没有目的地被配置则InvalidDestinationException异常将被抛出(并且请注意这个异常不会被吞没)并且将传播给调用栈。

 

30.4.5 Processing messages within transactions

在事务中处理消息

 

Invoking a message listener within a transaction only requires reconfiguration of the listener container.

调用一个消息监听器在一个事务中只要求重新配置监听器容器。

 

Local resource transactions can simply be activated through the sessionTransacted flag on the listener container definition. Each message listener invocation will then operate within an active JMS transaction, with message reception rolled back in case of listener execution failure. Sending a response message (via SessionAwareMessageListener) will be part of the same local transaction, but any other resource operations (such as database access) will operate independently. This usually requires duplicate message detection in the listener implementation, covering the case where database processing has committed but message processing failed to commit.

本地资源事务可以简单被激活通过sessionTransacted标志在监听器容器定义中。每个消息监听器调用将被分开操作对于一个激活的JMS事务,消息接收回滚由于监听器执行失败。发送一个响应消息(通过SessionAwareMessageListener)将是相同的本地事务的一部分,但是任何资源操作(例如数据库访问)将直接操作。这通常需要重复消息目的地在监听器实现,覆盖数据库访问执行已经提交但是消息执行失败没有提交。

 

<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">

    <property name="connectionFactory" ref="connectionFactory"/>

    <property name="destination" ref="destination"/>

    <property name="messageListener" ref="messageListener"/>

    <property name="sessionTransacted" value="true"/>

</bean>

 

For participating in an externally managed transaction, you will need to configure a transaction manager and use a listener container which supports externally managed transactions: typically DefaultMessageListenerContainer.

对于在外部管理的事务中参与,你需要配置一个事务管理并且使用一个监听器容器来支持外部的事务管理:通常是DefaultMessageListenerContainer

 

To configure a message listener container for XA transaction participation, youll want to configure a JtaTransactionManager (which, by default, delegates to the Java EE servers transaction subsystem). Note that the underlying JMS ConnectionFactory needs to be XA-capable and properly registered with your JTA transaction coordinator! (Check your Java EE servers configuration of JNDI resources.) This allows message reception as well as e.g. database access to be part of the same transaction (with unified commit semantics, at the expense of XA transaction log overhead).

在配置一个消息容器用于XA分布式事务,你希望配置一个JtaTransactionManager(默认的,对于JavaEE服务器的事务子系统定义)。注意底层的JMSConnectionFactory需要是支持XA的并且注册了你的JTA事务参与。(检查你的JavaEE服务配置关于JNDI资源。)这允许消息接收例如数据库访问作为相同目的地的一部分(没有提交语义,是XA事务日志覆盖的扩张)。

 

<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>

 

Then you just need to add it to our earlier container configuration. The container will take care of the rest.

让你需要将其添加到我们之前的容器配置中。容器的剩余部分是。

 

<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">

    <property name="connectionFactory" ref="connectionFactory"/>

    <property name="destination" ref="destination"/>

    <property name="messageListener" ref="messageListener"/>

    <property name="transactionManager" ref="transactionManager"/>

</bean>

 

30.5 Support for JCA Message Endpoints

用于支持JCA消息端点

 

Beginning with version 2.5, Spring also provides support for a JCA-based MessageListener container. The JmsMessageEndpointManager will attempt to automatically determine the ActivationSpec class name from the providers ResourceAdapter class name. Therefore, it is typically possible to just provide Springs generic JmsActivationSpecConfig as shown in the following example.

开始版本2.5spring也提供了支持对于基于JCA的消息监听器容器。JmsMessageEndpointManager将试图访问自动探测ActivationSpec类名来自提供者的ResourceAdapter的类的名字。此外,通常可以提供spirng的通用的JmsActivationSpecConfig作为展示在下面的例子中。

 

<bean class="org.springframework.jms.listener.endpoint.JmsMessageEndpointManager">

    <property name="resourceAdapter" ref="resourceAdapter"/>

    <property name="activationSpecConfig">

        <bean class="org.springframework.jms.listener.endpoint.JmsActivationSpecConfig">

            <property name="destinationName" value="myQueue"/>

        </bean>

    </property>

    <property name="messageListener" ref="myMessageListener"/>

</bean>

 

Alternatively, you may set up a JmsMessageEndpointManager with a given ActivationSpec object. The ActivationSpec object may also come from a JNDI lookup (using <jee:jndi-lookup>).

作为替代,你可以设置JmsMessageEndpointManager而需要一个给定的ActivationSpecobjectActivationSpecobject可以来自JNDI查找(使用<jee:jndi-lookup>)。

 

<bean class="org.springframework.jms.listener.endpoint.JmsMessageEndpointManager">

    <property name="resourceAdapter" ref="resourceAdapter"/>

    <property name="activationSpec">

        <bean class="org.apache.activemq.ra.ActiveMQActivationSpec">

            <property name="destination" value="myQueue"/>

            <property name="destinationType" value="javax.jms.Queue"/>

        </bean>

    </property>

    <property name="messageListener" ref="myMessageListener"/>

</bean>

 

Using Springs ResourceAdapterFactoryBean, the target ResourceAdapter may be configured locally as depicted in the following example.

使用springResourceAdapterFactoryBean,目标的ResourceAdapter可以配置本地化描述在下面的例子中。

 

<bean id="resourceAdapter" class="org.springframework.jca.support.ResourceAdapterFactoryBean">

    <property name="resourceAdapter">

        <bean class="org.apache.activemq.ra.ActiveMQResourceAdapter">

            <property name="serverUrl" value="tcp://localhost:61616"/>

        </bean>

    </property>

    <property name="workManager">

        <bean class="org.springframework.jca.work.SimpleTaskWorkManager"/>

    </property>

</bean>

 

The specified WorkManager may also point to an environment-specific thread pool - typically through SimpleTaskWorkManagers "asyncTaskExecutor" property. Consider defining a shared thread pool for all your ResourceAdapter instances if you happen to use multiple adapters.

指定的WorkManager也指向一个指定环境的线程池————通常通过SimpleTaskWorkManagerasyncTaskExecutor属性。考虑定义一个共享的线程池用于你的ResourceAdapter实例如果你需要使用多个适配器。

 

In some environments (e.g. WebLogic 9 or above), the entire ResourceAdapter object may be obtained from JNDI instead (using <jee:jndi-lookup>). The Spring-based message listeners can then interact with the server-hosted ResourceAdapter, also using the servers built-in WorkManager.

在一个情况(例如WebLogic9或以上的版本),整个ResourceAdapterobject可以来自JNDI(或者使用<jee:jndi-lookup>)。基于spring的消息监听可以连接服务器为主的ResourceAdapter,并且使用了服务器内置的WorkManager

 

Please consult the JavaDoc for JmsMessageEndpointManager, JmsActivationSpecConfig, and ResourceAdapterFactoryBean for more details.

请参考JavaDoc用于JmsMessageEndpointManagerJmsActivationSpecConfigResourceAdapterFactoryBean来了解更多的内容。

 

Spring also provides a generic JCA message endpoint manager which is not tied to JMS: org.springframework.jca.endpoint.GenericMessageEndpointManager. This component allows for using any message listener type (e.g. a CCI MessageListener) and any provider-specific ActivationSpec object. Check out your JCA providers documentation to find out about the actual capabilities of your connector, and consult `GenericMessageEndpointManagers JavaDoc for the Spring-specific configuration details.

spring也提供了一个通用的JCA消息端点管理器绑定到JMSorg.springframework.jca.endpoint.GenericMessageEndpointManager。这个组件允许使用任何消息监听器类型(例如一个CCIMessageListener)和任何指定提供的ActivationSpecobject。检查你的JCA提供者文档来找到你连接器实际的功能以及参考GenericMessageEndpointManagerjavadocs来了解特定spring配置的细节。

 

[Note]

注意

 

JCA-based message endpoint management is very analogous to EJB 2.1 Message-Driven Beans; it uses the same underlying resource provider contract. Like with EJB 2.1 MDBs, any message listener interface supported by your JCA provider can be used in the Spring context as well. Spring nevertheless provides explicit 'convenience' support for JMS, simply because JMS is the most common endpoint API used with the JCA endpoint management contract.

基于JCA的消息端点管理是不同于EJB2.1的消息驱动bean的,他使用相同的底层资源提供者,类似于EJB2.1MDB,任何消息监听器接口支持通过你的JCA提供者可以使用在spring上下文中。spring只是提供了明确的方便的支持对于JMS,简单因为JMS是大部分通用的端点API通过使用于JCA的端点管理规范。

 

30.6 Annotation-driven listener endpoints

注解驱动监听器端点

 

The easiest way to receive a message asynchronously is to use the annotated listener endpoint infrastructure. In a nutshell, it allows you to expose a method of a managed bean as a JMS listener endpoint.

最简单的方式来接收异步小四是需要使用注解驱动监听器端点结构。简而言之,他允许你来暴露一个管理bean的方法作为JMS监听器端点。

 

@Component

public class MyService {

 

    @JmsListener(destination = "myDestination")

    public void processOrder(String data) { ... }

}

 

The idea of the example above is that whenever a message is available on the javax.jms.Destination "myDestination", the processOrder method is invoked accordingly (in this case, with the content of the JMS message similarly to what the MessageListenerAdapter provides).

上面的例子中的想法是当消息可用对于javax.jms.Destination "myDestination",那么processOrder方法被调用(在这个例子中,对于JMS消息的内容类似于MessageListenerAdapter提供的内容)。

 

The annotated endpoint infrastructure creates a message listener container behind the scenes for each annotated method, using a JmsListenerContainerFactory. Such a container is not registered against the application context but can be easily located for management purposes using the JmsListenerEndpointRegistry bean.

注解端点结构创建一个消息监听器容器在每个注解方法的场景中,使用JmsListenerContainerFactory。例如一个容器没有注册在应用上下文中但是可以简单的定位为管理的目的使用JmsListenerEndpointRegistrybean

 

[Tip]

提示

 

@JmsListener is a repeatable annotation on Java 8, so it is possible to associate several JMS destinations to the same method by adding additional @JmsListener declarations to it. On Java 6 and 7, you can use the @JmsListeners annotation.

@JmsListener是一个重复的注解对于Java8,因此它可以访问一些JMS目的地对于相同的方法额外添加到@JmsListener定义中。对于Java67,你可以使用@JmsListener注解。

 

30.6.1 Enable listener endpoint annotations

允许监听器端点注解

 

To enable support for @JmsListener annotations add @EnableJms to one of your @Configuration classes.

为了允许支持@JmsListener注解添加@EnableJms对于每一个你的@Configuration注解类。

 

@Configuration

@EnableJms

public class AppConfig {

 

    @Bean

    public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {

        DefaultJmsListenerContainerFactory factory =

                new DefaultJmsListenerContainerFactory();

        factory.setConnectionFactory(connectionFactory());

        factory.setDestinationResolver(destinationResolver());

        factory.setConcurrency("3-10");

        return factory;

    }

}

 

By default, the infrastructure looks for a bean named jmsListenerContainerFactory as the source for the factory to use to create message listener containers. In this case, and ignoring the JMS infrastructure setup, the processOrder method can be invoked with a core poll size of 3 threads and a maximum pool size of 10 threads.

默认的,架构寻找bean名字为jmsListenerContainerFactory作为工厂的源用于创建消息监听器容器。在这种情况中忽略JMS的基础结构设置,processOrder方法可以被调用在核心池中含有三个线程和一个最大有10个线程的池。

 

It is possible to customize the listener container factory to use per annotation or an explicit default can be configured by implementing the JmsListenerConfigurer interface. The default is only required if at least one endpoint is registered without a specific container factory. See the javadoc for full details and examples.

可以自定义监听器容器工厂用于每个注解或默认可以被配置通过实现JmsListenerConfigurer接口。默认的是要求的如果至少有一个端点是没有注册到指定的容器工厂中。详见javadocs和样例。

 

If you prefer XML configuration use the <jms:annotation-driven> element.

如果你倾向于使用xml配置可以使用<jms:annotation-driven>标签。

 

<jms:annotation-driven/>

 

<bean id="jmsListenerContainerFactory"

        class="org.springframework.jms.config.DefaultJmsListenerContainerFactory">

    <property name="connectionFactory" ref="connectionFactory"/>

    <property name="destinationResolver" ref="destinationResolver"/>

    <property name="concurrency" value="3-10"/>

</bean>

 

30.6.2 Programmatic endpoints registration

编程端点注册

 

JmsListenerEndpoint provides a model of an JMS endpoint and is responsible for configuring the container for that model. The infrastructure allows you to configure endpoints programmatically in addition to the ones that are detected by the JmsListener annotation.

JmsListenerEndpoint提供了一个JMS的端点模式并且可以配置容器用于模式。结构允许你来编程配置端点对于每一个通过JmsListener注解探测到的内容。

 

@Configuration

@EnableJms

public class AppConfig implements JmsListenerConfigurer {

 

    @Override

    public void configureJmsListeners(JmsListenerEndpointRegistrar registrar) {

        SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();

        endpoint.setId("myJmsEndpoint");

        endpoint.setDestination("anotherQueue");

        endpoint.setMessageListener(message -> {

            // processing

        });

        registrar.registerEndpoint(endpoint);

    }

}

 

In the example above, we used SimpleJmsListenerEndpoint which provides the actual MessageListener to invoke but you could just as well build your own endpoint variant describing a custom invocation mechanism.

在上面的例子中,我们使用了SimpleJmsListenerEndpoint提供了实际的MessageListener来调用但是你只是构建了你自己的端点变量描述了一个自定义的调用方法。

 

It should be noted that you could just as well skip the use of @JmsListener altogether and only register your endpoints programmatically through JmsListenerConfigurer.

他可以被需要你也可以跳过使用@JmsListener注解并且只是编程注册你的端点通过JmsListenerConfigurer

 

30.6.3 Annotated endpoint method signature

注解端点方法签名

 

So far, we have been injecting a simple String in our endpoint but it can actually have a very flexible method signature. Lets rewrite it to inject the Order with a custom header:

因此,我们已经注入了一个简单的字符串在我们的端点但是他可以使用有一个非常方便的方法签名。让我们重写他来注入Order使用一个自定义的头信息。

 

@Component

public class MyService {

 

    @JmsListener(destination = "myDestination")

    public void processOrder(Order order, @Header("order_type") String orderType) {

        ...

    }

}

 

These are the main elements you can inject in JMS listener endpoints:

这些事主要的元素你可以注入到JMS监听器端点中:

 

    The raw javax.jms.Message or any of its subclasses (provided of course that it matches the incoming message type).

原生的javax.jms.Message或任何他的子类(当然需要匹配输入的消息类型)

    The javax.jms.Session for optional access to the native JMS API e.g. for sending a custom reply.

java.jms.Session用于选择访问本地的JMSAPI例如对于发送自定义回复

    The org.springframework.messaging.Message representing the incoming JMS message. Note that this message holds both the custom and the standard headers (as defined by JmsHeaders).

org.springframework.Message代表输入的JMS消息。注意这些消息有自定义和标准的头信息(定义通过JmsHeaders

    @Header-annotated method arguments to extract a specific header value, including standard JMS headers.

@Header-annotated注解方法参数来表示一个特定头消息值,包括标准的JMS消息头。

    @Headers-annotated argument that must also be assignable to java.util.Map for getting access to all headers.

@Headers-annotated注解参数必须可以归为java.util.Map用于获得访问所有的头信息。

    A non-annotated element that is not one of the supported types (i.e. Message and Session) is considered to be the payload. You can make that explicit by annotating the parameter with @Payload. You can also turn on validation by adding an extra @Valid.

非注解元素是一个支持的类型(例如,MessageSession)被考虑可以被处理。你可以使用注解参数通过@Payload注解。你也可以打开验证通过添加额外的@Valid注解。

 

The ability to inject Springs Message abstraction is particularly useful to benefit from all the information stored in the transport-specific message without relying on transport-specific API.

注入spring的消息抽象的能力时有意义的对于所有的消息存储在特定的传输消息中而不需要回复通过特定的传输的API

 

@JmsListener(destination = "myDestination")

public void processOrder(Message<Order> order) { ... }

 

Handling of method arguments is provided by DefaultMessageHandlerMethodFactory which can be further customized to support additional method arguments. The conversion and validation support can be customized there as well.

方法参数的处理被提供通过DefaultMessageHandlerMethodFactory可以自定义来支持额外的方法参数。规范和验证支持也可以被自定义。

 

For instance, if we want to make sure our Order is valid before processing it, we can annotate the payload with @Valid and configure the necessary validator as follows:

对于实例,如果我们希望保证执行之前验证的属性,我们可以注解使用@Valid并且配置必要的验证器如下:

 

@Configuration

@EnableJms

public class AppConfig implements JmsListenerConfigurer {

 

    @Override

    public void configureJmsListeners(JmsListenerEndpointRegistrar registrar) {

        registrar.setMessageHandlerMethodFactory(myJmsHandlerMethodFactory());

    }

 

    @Bean

    public DefaultMessageHandlerMethodFactory myHandlerMethodFactory() {

        DefaultMessageHandlerMethodFactory factory = new DefaultMessageHandlerMethodFactory();

        factory.setValidator(myValidator());

        return factory;

    }

}

 

30.6.4 Response management

响应管理

 

The existing support in MessageListenerAdapter already allows your method to have a non-void return type. When thats the case, the result of the invocation is encapsulated in a javax.jms.Message sent either in the destination specified in the JMSReplyTo header of the original message or in the default destination configured on the listener. That default destination can now be set using the @SendTo annotation of the messaging abstraction.

已有的支持在MessageListenerAdapter中允许你的方法有一个非空的返回类型。当存在这样的情况,调用的结果被压缩在javax.jms.Message中发送定义在JMSReplyTo的原始信息的头部或对于默认的目的地配置于监听器。默认的目的地可以被设置使用@SendTo注解对于消息的抽象。

 

Assuming our processOrder method should now return an OrderStatus, it is possible to write it as follow to automatically send a response:

假设我们的processOrder方法应当返回一个OrderStatus,可以将其写入符合自动发送消息:

 

@JmsListener(destination = "myDestination")

@SendTo("status")

public OrderStatus processOrder(Order order) {

    // order processing

    return status;

}

 

[Tip]

提示

 

If you have several @JmsListener-annotated methods, you can also place the @SendTo annotation at the class level to share a default reply destination.

如果你有多个@JmsListener-annotated方法,你可以替换@SendTo注解在类的级别对于共享默认的回复目的地。

 

If you need to set additional headers in a transport-independent manner, you could return a Message instead, something like:

如果你需要设置额外的头信息在独立的传输中,你可以返回一个Message作为代替,例如:

 

@JmsListener(destination = "myDestination")

@SendTo("status")

public Message<OrderStatus> processOrder(Order order) {

    // order processing

    return MessageBuilder

            .withPayload(status)

            .setHeader("code", 1234)

            .build();

}

 

If you need to compute the response destination at runtime, you can encapsulate your response in a JmsResponse instance that also provides the destination to use at runtime. The previous example can be rewritten as follows:

如果你需要计算响应目的地在运行时,你可以压缩你的响应在JmsResponse实例并且提供目的地来使用在运行时。之前的样例可以被重写如下:

 

@JmsListener(destination = "myDestination")

public JmsResponse<Message<OrderStatus>> processOrder(Order order) {

    // order processing

    Message<OrderStatus> response = MessageBuilder

            .withPayload(status)

            .setHeader("code", 1234)

            .build();

    return JmsResponse.forQueue(response, "status");

}

 

30.7 JMS namespace support

JMS命名空间支持

 

Spring provides an XML namespace for simplifying JMS configuration. To use the JMS namespace elements you will need to reference the JMS schema:

spring提供了一个xml命名空间用于简化JMS配置。为了使用JMS命名空间元素你需要引用JMSschema

 

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

        xmlns:jms="http://www.springframework.org/schema/jms"

        xsi:schemaLocation="

            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

            http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms.xsd">

 

    <!-- bean definitions here -->

 

</beans>

 

The namespace consists of three top-level elements: <annotation-driven/>, <listener-container/> and <jca-listener-container/>. <annotation-driven enables the use of annotation-driven listener endpoints. <listener-container/> and <jca-listener-container/> defines shared listener container configuration and may contain <listener/> child elements. Here is an example of a basic configuration for two listeners.

命名空间包含三个顶级的元素:<annotation-driven/>, <listener-container/> <jca-listener-container/><annotation-driven/>允许使用注解驱动的监听器端点。<listener-container/> <jca-listener-container/>定义了共享的监听器容器和可以包含<listener/>子元素。这是一个基本的配置对于两个监听器。

 

<jms:listener-container>

 

    <jms:listener destination="queue.orders" ref="orderService" method="placeOrder"/>

 

    <jms:listener destination="queue.confirmations" ref="confirmationLogger" method="log"/>

 

</jms:listener-container>

 

The example above is equivalent to creating two distinct listener container bean definitions and two distinct MessageListenerAdapter bean definitions as demonstrated in Section 30.4.4, the MessageListenerAdapter. In addition to the attributes shown above, the listener element may contain several optional ones. The following table describes all available attributes:

上面的例子相当于创建两个不同的监听器容器的bean的定义和两个不同的MessageListenerAdapterbean定义描述在章节30.4.4中,“the MessageListenerAdapter”。此外对于属性的展示,监听器元素可以包含多个选项。下面的表格描述了所有的可用属性:

 

Table 30.1. Attributes of the JMS <listener> element

JMS<listener>元素的属性

Attribute

属性

Description

描述

id

A bean name for the hosting listener container. If not specified, a bean name will be automatically generated.

监听器容器的bean的名字。如果不指定则名字是自动生成的。

destination (required)

The destination name for this listener, resolved through the DestinationResolver strategy.

这个监听器的目的地,通过DestinationResolver策略来解析处理。

ref (required)

The bean name of the handler object.

处理的objectbean的名字

method

The name of the handler method to invoke. If the ref points to a MessageListener or Spring SessionAwareMessageListener, this attribute may be omitted.

被调用的处理器方法的名字。如果引用指向一个MessageListener或springSessionAwareMessageListener则这个属性会被忽略。

response-destination

The name of the default response destination to send response messages to. This will be applied in case of a request message that does not carry a "JMSReplyTo" field. The type of this destination will be determined by the listener-containers "response-destination-type" attribute. Note: This only applies to a listener method with a return value, for which each result object will be converted into a response message.

默认响应目的地的名字来发送响应消息。这将被应用由于请求消息没有包含JMSReplyTo域的时候。这个目的地的类型将被决定通过监听器容器的response-destination-type属性。注意:这只是应用于监听器方法带有返回值的,对于每个结果将被转换为一个响应消息。

subscription

The name of the durable subscription, if any.

持续定于的名字,可以是任意值。

selector

An optional message selector for this listener.

用于这个监听器的可选的消息选择器。

concurrency

The number of concurrent sessions/consumers to start for this listener. Can either be a simple number indicating the maximum number (e.g. "5") or a range indicating the lower as well as the upper limit (e.g. "3-5"). Note that a specified minimum is just a hint and might be ignored at runtime. Default is the value provided by the container

并发session/consumer的数量对于个这个监听器。可以是简单的指定最大值例如5或者一个范围例如3-5.注意指定的最小值只是一个简易并且可以在运行时被忽略。默认的值是由容器来提供的。

The <listener-container/> element also accepts several optional attributes. This allows for customization of the various strategies (for example, taskExecutor and destinationResolver) as well as basic JMS settings and resource references. Using these attributes, it is possible to define highly-customized listener containers while still benefiting from the convenience of the namespace.

<listener-container/>元素也接收一些可选属性。这些允许自定义不同的策略(例如,taskExecutordestinationResolver)可以是基本的JMS设置和资源引用。使用这些属性,可以定义自定义的监听器容器可以从命名空间中得到方便。

 

Such settings can be automatically exposed as a JmsListenerContainerFactory by specifying the id of the bean to expose through the factory-id attribute.

这样的设置可以自动被暴露作为JmsListenerContainerFactory通过指定beanid来暴露通过factory-id属性。

 

<jms:listener-container connection-factory="myConnectionFactory"

        task-executor="myTaskExecutor"

        destination-resolver="myDestinationResolver"

        transaction-manager="myTransactionManager"

        concurrency="10">

 

    <jms:listener destination="queue.orders" ref="orderService" method="placeOrder"/>

 

    <jms:listener destination="queue.confirmations" ref="confirmationLogger" method="log"/>

 

</jms:listener-container>

 

The following table describes all available attributes. Consult the class-level javadocs of the AbstractMessageListenerContainer and its concrete subclasses for more details on the individual properties. The javadocs also provide a discussion of transaction choices and message redelivery scenarios.

下面的表格描述了所有可用的属性。查阅类级别的javadocs有关AbstractMessageListenerContainer和他相关的子类来了解更多有关独立的属性。javadocs也提供了讨论有关事务的选项和消息的接收场景。

 

Table 30.2. Attributes of the JMS <listener-container> element

JMS<listener-container>元素的属性

Attribute

属性

Description

描述

container-type

The type of this listener container. Available options are: default, simple, default102, or simple102 (the default value is 'default').

监听器容器的类型。可选项是:default、simple、default102或simple102(默认值是default102

container-class

A custom listener container implementation class as fully qualified class name. Default is Springs standard DefaultMessageListenerContainer or SimpleMessageListenerContainer, according to the "container-type" attribute.

自定义监听器容器实现类作为全限定类名。默认是spring的标准的DefaultMessageListenerContainer或SimpleMessageListenerContainer取决于"container-type"属性。

factory-id

Exposes the settings defined by this element as a JmsListenerContainerFactory with the specified id so that they can be reused with other endpoints.

暴露的设置定义这个元素作为JmsListenerContainerFactory使用指定的id因此她们可以重用对于其他的端点。

connection-factory

A reference to the JMS ConnectionFactory bean (the default bean name is 'connectionFactory').

一个引用对于JMSConnectionFactory的bean(默认的bean的名字是'connectionFactory')

task-executor

A reference to the Spring TaskExecutor for the JMS listener invokers.

一个引用对于springTaskExecutor对于JMS监听器的调用者

destination-resolver

A reference to the DestinationResolver strategy for resolving JMS Destinations.

一个引用对于DestinationResolver策略用来解析JMS的目的地。

message-converter

A reference to the MessageConverter strategy for converting JMS Messages to listener method arguments. Default is a SimpleMessageConverter.

一个引用对于MessageConverter策略用于转换JMS消息为监听器参数。默认是SimpleMessageConverter。

error-handler

A reference to an ErrorHandler strategy for handling any uncaught Exceptions that may occur during the execution of the MessageListener.

一个引用对于ErrorHandler策略用于处理一些未捕获的异常可能发生在MessageListener的执行过程中。

destination-type

The JMS destination type for this listener: queue, topic, durableTopic, sharedTopic or sharedDurableTopic. This enables potentially the pubSubDomain, subscriptionDurable and subscriptionShared properties of the container. The default is queue (i.e. disabling those 3 properties).

JMS的目的地类型对于这个监听器:queuetopicdurableTopicsharedTopicsharedDurableTopic。这允许潜在的pubSubDomain、subscriptionDurable和subscriptionShared属性对于容器。默认是queue

response-destination-type

The JMS destination type for responses: "queue", "topic". Default is the value of the "destination-type" attribute.

JMS目的地类型用于响应:queuetopic。默认值是destination-type属性的值。

client-id

The JMS client id for this listener container. Needs to be specified when using durable subscriptions.

JMS客户端ID对于监听器容器。需要被指定当使用持久订阅时。

cache

The cache level for JMS resources: none, connection, session, consumer or auto. By default ( auto), the cache level will effectively be "consumer", unless an external transaction manager has been specified - in which case the effective default will be none (assuming Java EE-style transaction management where the given ConnectionFactory is an XA-aware pool).

缓存级别对于JMS资源:noneconnectionsessionconsumerauto。默认是auto,缓存级别将影响通过consumer除非外部的事务管理器可以被定义——由于默认是none(假设JavaEE风格的事务管理可以被给定ConnectionFactory是一个XA-aware的池)

acknowledge

The native JMS acknowledge mode: auto, client, dups-ok or transacted. A value of transacted activates a locally transacted Session. As an alternative, specify the transaction-manager attribute described below. Default is auto.

本地的JMS消息模型:autoclientdups-oktransacted。事务激活一个本地的事务Session。作为替代,指定transaction-manager属性描述在下面,默认是auto

transaction-manager

A reference to an external PlatformTransactionManager (typically an XA-based transaction coordinator, e.g. Springs JtaTransactionManager). If not specified, native acknowledging will be used (see "acknowledge" attribute).

一个引用对于外部的PlatformTransactionManager(通常是一个基于XA是事务,例如springJtaTransactionManager)。如果没有指定本地acknowledging的值将被使用(见acknowledge属性)

concurrency

The number of concurrent sessions/consumers to start for each listener. Can either be a simple number indicating the maximum number (e.g. "5") or a range indicating the lower as well as the upper limit (e.g. "3-5"). Note that a specified minimum is just a hint and might be ignored at runtime. Default is 1; keep concurrency limited to 1 in case of a topic listener or if queue ordering is important; consider raising it for general queues.

当前session/consumers的数量对于开始的每个监听器。可以是简单的指定最大值例如5或一个范围例如3-5.注意指定的最小值只是一个建议并且可以在运行时被忽略。默认是1;保持并发限制对于1由于topic监听器或如果队列的顺序是重要的,考虑将其作为一个普通的队列。

prefetch

The maximum number of messages to load into a single session. Note that raising this number might lead to starvation of concurrent consumers!

消息的最大数量来加载一个单一的会话。注意加大这个值会导致一些并发消费者饿死。

receive-timeout

The timeout to use for receive calls (in milliseconds). The default is 1000 ms (1 sec); -1 indicates no timeout at all.

收到调用的超时(单位是毫秒)。默认是1000ms-1指定没有超时时间。

back-off

Specify the BackOff instance to use to compute the interval between recovery attempts. If the BackOffExecution implementation returns BackOffExecution#STOP, the listener container will not further attempt to recover. The recovery-interval value is ignored when this property is set. The default is a FixedBackOff with an interval of 5000 ms, that is 5 seconds.

指定BackOff实例用于计算间隔对于恢复尝试。如果BackOffExecution实现返回BackOffExecution#STOP,监听器容器将不会尝试恢复。恢复间隔值被忽略如果这个属性被设置之后。默认是一个FixedBackOff的时间为5000毫秒,也就是5秒。

recovery-interval

Specify the interval between recovery attempts, in milliseconds. Convenience way to create a FixedBackOff with the specified interval. For more recovery options, consider specifying a BackOff instance instead. The default is 5000 ms, that is 5 seconds.

指定恢复尝试的间隔,单位是毫秒。方便的方式来创建FixedBackOff使用指定的间隔。对于更多的恢复选项,考虑指定一个BackOff实例作为替代。默认是5000毫秒,也就是5秒。

phase

The lifecycle phase within which this container should start and stop. The lower the value the earlier this container will start and the later it will stop. The default is Integer.MAX_VALUE meaning the container will start as late as possible and stop as soon as possible.

生命周期阶段就是这个容器应当开始和结束。值越小则容器开始时间越早结束时间越晚。默认是Integer的最大值,意味着这个容器将最后一个开始并且最先结束。

Configuring a JCA-based listener container with the "jms" schema support is very similar.

配置一个基于JCA的监听器容器使用jmsschema支持是类似的。

 

<jms:jca-listener-container resource-adapter="myResourceAdapter"

        destination-resolver="myDestinationResolver"

        transaction-manager="myTransactionManager"

        concurrency="10">

 

    <jms:listener destination="queue.orders" ref="myMessageListener"/>

 

</jms:jca-listener-container>

 

The available configuration options for the JCA variant are described in the following table:

可选项目用于JCA描述在下面的表格中:

 

Table 30.3. Attributes of the JMS <jca-listener-container/> element

JMS<jca-listener-container/>元素的属性

Attribute

属性

Description

描述

factory-id

Exposes the settings defined by this element as a JmsListenerContainerFactory with the specified id so that they can be reused with other endpoints.

暴露设置定义通过这个元素作为JmsListenerContainerFactory使用指定的id因此她们可以重用对于其他的端点。

resource-adapter

A reference to the JCA ResourceAdapter bean (the default bean name is 'resourceAdapter').

一个引用对于JCAResourceAdapter的bean(默认的bean的名字是'resourceAdapter')

activation-spec-factory

A reference to the JmsActivationSpecFactory. The default is to autodetect the JMS provider and its ActivationSpec class (see DefaultJmsActivationSpecFactory)

JmsActivationSpecFactory的引用。默认是自动他侧JMS提供者和他的ActivationSpec类(见DefaultJmsActivationSpecFactory)

destination-resolver

A reference to the DestinationResolver strategy for resolving JMS Destinations.

对于DestinationResolver策略的引用用于解析JMS的目的地。

message-converter

A reference to the MessageConverter strategy for converting JMS Messages to listener method arguments. Default is a SimpleMessageConverter.

对于MessageConverter策略的引用用于转换JMS消息为监听器方法参数。默认是SimpleMessageConverter。

destination-type

The JMS destination type for this listener: queue, topic, durableTopic, sharedTopic or sharedDurableTopic. This enables potentially the pubSubDomain, subscriptionDurable and subscriptionShared properties of the container. The default is queue (i.e. disabling those 3 properties).

JMS的目的地类型用于这个监听器:queuetopicdurableTopic、sharedTopic或sharedDurableTopic。这允许潜在的pubSubDomain、subscriptionDurable和subscriptionShared属性对于这个容器。默认是queue。(也就是,取消这三个属性)。

response-destination-type

The JMS destination type for responses: "queue", "topic". Default is the value of the "destination-type" attribute.

JMS的目的地类型对于响应:queuetopic。默认值是destination-type的属性值。

client-id

The JMS client id for this listener container. Needs to be specified when using durable subscriptions.

JMS客户端id用于这个监听器容器。需要被设置当使用持久化订阅的时候。

acknowledge

The native JMS acknowledge mode: auto, client, dups-ok or transacted. A value of transacted activates a locally transacted Session. As an alternative, specify the transaction-manager attribute described below. Default is auto.

本地的确认模式:autoclientdups-oktransacted。交易激活的值是本地的会话。作为替代,指定transaction-manager属性描述在下面,默认是auto

transaction-manager

A reference to a Spring JtaTransactionManager or a javax.transaction.TransactionManager for kicking off an XA transaction for each incoming message. If not specified, native acknowledging will be used (see the "acknowledge" attribute).

对于springJtaTransactionManager的引用或javax.transaction.TransactionManager用于开始对于每个输入消息的XA事务。如果没有指定,本地的确认方式会被使用(见acknowledge属性)。

concurrency

The number of concurrent sessions/consumers to start for each listener. Can either be a simple number indicating the maximum number (e.g. "5") or a range indicating the lower as well as the upper limit (e.g. "3-5"). Note that a specified minimum is just a hint and will typically be ignored at runtime when using a JCA listener container. Default is 1.

并发sessionconsumer的数目对于每个监听器。可以是一个简单是数字指定上限例如5或者一个范围指定范围例如3-5.注意最小值只是一个建议并且使用JCA监听器时通常会被忽略。默认是1.

prefetch

The maximum number of messages to load into a single session. Note that raising this number might lead to starvation of concurrent consumers!

消息加载到单个session中的最大数量。注意增加这个数量可能导致并发消费者饿死。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 简介 1.1. 概览 1.2. 使用场景 2. Spring 2.0 的新特性 2.1. 简介 2.2. 控制反转(IoC)容器 2.2.1. 更简单的XML配置 2.2.2. 新的bean作用域 2.2.3. 可扩展的XML编写 2.3. 面向切面编程(AOP) 2.3.1. 更加简单的AOP XML配置 2.3.2. 对@AspectJ 切面的支持 2.4. 中间层 2.4.1. 在XML里更为简单的声明性事务配置 2.4.2. JPA 2.4.3. 异步的JMS 2.4.4. JDBC 2.5. Web层 2.5.1. Spring MVC的表单标签库 2.5.2. Spring MVC合理的默认值 2.5.3. Portlet 框架 2.6. 其他特性 2.6.1. 动态语言支持 2.6.2. JMX 2.6 .3. 任务规划 2.6.4. 对Java 5(Tiger)的支持 2.7. 移植到Spring 2.0 2.7.1. 一些变化 2.7.1.1. Jar包 2.7.1.2. XML配置 2.7.1.3. Deprecated的类和方法 2.7.1.4. Apache OJB 2.7.1.5. iBatis 2.8. 更新的样例应用 2.9. 改进的文档 I. 核心技术 3. 控制反转容器 3.1. 简介 3.2. 容器和bean的基本原理 3.2.1. 容器 3.2.1.1. 配置元数据 3.2.2. 实例化容器 3.2.2.1. 组成基于XML配置元数据 3.2.3. 多种bean 3.2.3.1. 命名bean 3.2.3.2. 实例化bean 3.2.4. 使用容器 3.3. 依赖 3.3.1. 注入依赖 3.3.1.1. Setter注入 3.3.1.2. 构造器注入 3.3.1.3. 一些例子 3.3.2. 构造器参数的解析 3.3.2.1. 构造器参数类型匹配 3.3.2.2. 构造器参数的索引 3.3.3. bean属性及构造器参数详解 3.3.3.1. 直接量(基本类型、Strings类型等。) 3.3.3.2. 引用其它的bean(协作者) 3.3.3.3. 内部bean 3.3.3.4. 集合 3.3.3.5. Nulls 3.3.3.6. XML-based configuration metadata shortcuts 3.3.3.7. 组合属性名称 3.3.4. 使用depends-on 3.3.5. 延迟初始化bean 3.3.6. 自动装配(autowire)协作者 3.3.6.1. 设置Bean使自动装配失效 3.3.7. 依赖检查 3.3.8. 方法注入 3.3.8.1. Lookup方法注入 3.3.8.2. 自定义方法的替代方案 3.4. bean的作用域 3.4.1. Singleton作用域 3.4.2. Prototype作用域 3.4.3. 其他作用域 3.4.3.1. 初始化web配置 3.4.3.2. Request作用域 3.4.3.3. Session作用域 3.4.3.4. global session作用域 3.4.3.5. 作用域bean与依赖 3.4.4. 自定义作用域 3.5. 定制bean特性 3.5.1. Lifecycle接口 3.5.1.1. 初始化回调 3.5.1.2. 析构回调 3.5.2. 了解自己 3.5.2.1. BeanFactoryAware 3.5.2.2. BeanNameAware 3.6. bean定义的继承 3.7. 容器扩展点 3.7.1. 用BeanPostProcessor定制bean 3.7.1.1. 使用BeanPostProcessor的Hello World示例 3.7.1.2. RequiredAnnotationBeanPostProcessor示例 3.7.2. 用BeanFactoryPostProcessor定制配置元数据 3.7.2.1. PropertyPlaceholderConfigurer示例 3.7.2.2. PropertyOverrideConfigurer示例 3.7.3. 使用FactoryBean定制实例化逻辑 3.8. ApplicationContext 3.8.1. 利用MessageSource实现国际化 3.8.2. 事件 3.8.3. 底层资源的访问 3.8.4. ApplicationContext在WEB应用中的实例化 3.9. 粘合代码和可怕的singleton 3.9.1. 使用Singleton-helper类 4. 资源 4.1. 简介 4.2. Resource 接口 4.3. 内置 Resource 实现 4.3.1. UrlResource 4.3.2. ClassPathResource 4.3.3. FileSystemResource 4.3.4. ServletContextResource 4.3.5. InputStreamResource 4.3.6. ByteArrayResource 4.4. ResourceLoader 4.5. ResourceLoaderAware 接口 4.6. 把Resource作为属性来配置 4.7. Application context 和Resource 路径 4.7.1. 构造application context 4.7.1.1. 创建 ClassPathXmlApplicationContext 实例 - 简介 4.7.2. Application context构造器中资源路径的通配符 4.7.2.1. Ant风格的pattern 4.7.2.2. classpath*: 前缀 4.7.2.3. 其他关于通配符的说明 4.7.3. FileSystemResource 提示 5. 校验,数据绑定,BeanWrapper,与属性编辑器 5.1. 简介 5.2. 使用Spring的Validator接口进行校验 5.3. 从错误代码到错误信息 5.4. Bean处理和BeanWrapper 5.4.1. 设置和获取属性值以及嵌套属性 5.4.2. 内建的PropertyEditor实现 5.4.2.1. 注册用户自定义的PropertyEditor 6. 使用Spring进行面向切面编程(AOP) 6.1. 简介 6.1.1. AOP概念 6.1.2. Spring AOP的功能和目标 6.1.3. Spring的AOP代理 6.2. @AspectJ支持 6.2.1. 启用@AspectJ支持 6.2.2. 声明一个切面 6.2.3. 声明一个切入点(pointcut) 6.2.3.1. 切入点指定者的支持 6.2.3.2. 合并切入点表达式 6.2.3.3. 共享常见的切入点(pointcut)定义 6.2.3.4. 示例 6.2.4. 声明通知 6.2.4.1. 前置通知(Before advice) 6.2.4.2. 返回后通知(After returning advice) 6.2.4.3. 抛出后通知(After throwing advice) 6.2.4.4. 后通知(After (finally) advice) 6.2.4.5. 环绕通知(Around Advice) 6.2.4.6. 通知参数(Advice parameters) 6.2.4.7. 通知(Advice)顺序 6.2.5. 引入(Introductions) 6.2.6. 切面实例化模型 6.2.7. 例子 6.3. Schema-based AOP support 6.3.1. 声明一个切面 6.3.2. 声明一个切入点 6.3.3. 声明通知 6.3.3.1. 通知(Advice) 6.3.3.2. 返回后通知(After returning advice) 6.3.3.3. 抛出异常后通知(After throwing advice) 6.3.3.4. 后通知(After (finally) advice) 6.3.3.5. 通知 6.3.3.6. 通知参数 6.3.3.7. 通知顺序 6.3.4. 引入 6.3.5. 切面实例化模型 6.3.6. Advisors 6.3.7. 例子 6.4. AOP声明风格的选择 6.4.1. Spring AOP还是完全用AspectJ? 6.4.2. Spring AOP中使用@AspectJ还是XML? 6.5. 混合切面类型 6.6. 代理机制 6.7. 编程方式创建@AspectJ代理 6.8. 在Spring应用中使用AspectJ 6.8.1. 在Spring中使用AspectJ来为domain object进行依赖注入 6.8.1.1. @Configurable object的单元测试 6.8.1.2. 多application context情况下的处理 6.8.2. Spring中其他的AspectJ切面 6.8.3. 使用Spring IoC来配置AspectJ的切面 6.8.4. 在Spring应用中使用AspectJ Load-time weaving(LTW) 6.9. 其它资源 7. Spring AOP APIs 7.1. 简介 7.2. Spring中的切入点API 7.2.1. 概念 7.2.2. 切入点实施 7.2.3. AspectJ切入点表达式 7.2.4. 便利的切入点实现 7.2.4.1. 静态切入点 7.2.4.2. 动态切入点 7.2.5. 切入点的基类 7.2.6. 自定义切入点 7.3. Spring的通知API 7.3.1. 通知的生命周期 7.3.2. Spring里的通知类型 7.3.2.1. 拦截around通知 7.3.2.2. 前置通知 7.3.2.3. 异常通知 7.3.2.4. 后置通知 7.3.2.5. 引入通知 7.4. Spring里的advisor(Advisor) API 7.5. 使用ProxyFactoryBean创建AOP代理 7.5.1. 基础 7.5.2. JavaBean属性 7.5.3. 基于JDK和CGLIB的代理 7.5.4. 对接口进行代理 7.5.5. 对类进行代理 7.5.6. 使用“全局”advisor 7.6. 简化代理定义 7.7. 使用ProxyFactory通过编程创建AOP代理 7.8. 操作被通知对象 7.9. 使用“自动代理(autoproxy)”功能 7.9.1. 自动代理bean定义 7.9.1.1. BeanNameAutoProxyCreator 7.9.1.2. DefaultAdvisorAutoProxyCreator 7.9.1.3. AbstractAdvisorAutoProxyCreator 7.9.2. 使用元数据驱动的自动代理 7.10. 使用TargetSources 7.10.1. 热交换目标源 7.10.2. 池化目标源 7.10.3. 原型目标源 7.10.4. ThreadLocal目标源 7.11. 定义新的通知类型 7.12. 更多资源 8. 测试 8.1. 简介 8.2. 单元测试 8.3. 集成测试 8.3.1. Context管理和缓存 8.3.2. 测试fixture的依赖注入 8.3.3. 事务管理 8.3.4. 方便的变量 8.3.5. 示例 8.3.6. 运行集成测试 8.4. 更多资源 II. 中间层数据访问 9. 事务管理 9.1. 简介 9.2. 动机 9.3. 关键抽象 9.4. 使用资源同步的事务 9.4.1. 高层次方案 9.4.2. 低层次方案 9.4.3. TransactionAwareDataSourceProxy 9.5. 声明式事务管理 9.5.1. 理解Spring的声明式事务管理实现 9.5.2. 第一个例子 9.5.3. 回滚 9.5.4. 为不同的bean配置不同的事务语义 9.5.5. <tx:advice/> 有关的设置 9.5.6. 使用 @Transactional 9.5.6.1. @Transactional 有关的设置 9.5.7. 插入事务操作 9.5.8. 结合AspectJ使用 @Transactional 9.6. 编程式事务管理 9.6.1. 使用 TransactionTemplate 9.6.2. 使用 PlatformTransactionManager 9.7. 选择编程式事务管理还是声明式事务管理 9.8. 与特定应用服务器集成 9.8.1. BEA WebLogic 9.8.2. IBM WebSphere 9.9. 公共问题的解决方案 9.9.1. 对一个特定的 DataSource 使用错误的事务管理器 9.10. 更多的资源 10. DAO支持 10.1. 简介 10.2. 一致的异常层次 10.3. 一致的DAO支持抽象类 11. 使用JDBC进行数据访问 11.1. 简介 11.1.1. Spring JDBC包结构 11.2. 利用JDBC核心类实现JDBC的基本操作和错误处理 11.2.1. JdbcTemplate类 11.2.2. NamedParameterJdbcTemplate类 11.2.3. SimpleJdbcTemplate类 11.2.4. DataSource接口 11.2.5. SQLExceptionTranslator接口 11.2.6. 执行SQL语句 11.2.7. 执行查询 11.2.8. 更新数据库 11.3. 控制数据库连接 11.3.1. DataSourceUtils类 11.3.2. SmartDataSource接口 11.3.3. AbstractDataSource类 11.3.4. SingleConnectionDataSource类 11.3.5. DriverManagerDataSource类 11.3.6. TransactionAwareDataSourceProxy类 11.3.7. DataSourceTransactionManager类 11.4. 用Java对象来表达JDBC操作 11.4.1. SqlQuery类 11.4.2. MappingSqlQuery类 11.4.3. SqlUpdate类 11.4.4. StoredProcedure类 11.4.5. SqlFunction类 12. 使用ORM工具进行数据访问 12.1. 简介 12.2. Hibernate 12.2.1. 资源管理 12.2.2. 在Spring的application context中创建 SessionFactory 12.2.3. HibernateTemplate 12.2.4. 不使用回调的基于Spring的DAO实现 12.2.5. 基于Hibernate3的原生API实现DAO 12.2.6. 编程式的事务划分 12.2.7. 声明式的事务划分 12.2.8. 事务管理策略 12.2.9. 容器资源 vs 本地资源 12.2.10. 在应用服务器中使用Hibernate的注意点 12.3. JDO 12.3.1. 建立PersistenceManagerFactory 12.3.2. JdoTemplate和JdoDaoSupport 12.3.3. 基于原生的JDO API实现DAO 12.3.4. 事务管理 12.3.5. JdoDialect 12.4. Oracle TopLink 12.4.1. SessionFactory 抽象层 12.4.2. TopLinkTemplate 和 TopLinkDaoSupport 12.4.3. 基于原生的TopLink API的DAO实现 12.4.4. 事务管理 12.5. iBATIS SQL Maps 12.5.1. iBATIS 1.x和2.x的概览与区别 12.5.2. iBATIS SQL Maps 1.x 12.5.2.1. 创建SqlMap 12.5.2.2. 使用 SqlMapTemplate 和 SqlMapDaoSupport 12.5.3. iBATIS SQL Maps 2.x 12.5.3.1. 创建SqlMapClient 12.5.3.2. 使用 SqlMapClientTemplate 和 SqlMapClientDaoSupport 12.5.3.3. 基于原生的iBATIS API的DAO实现 12.6. JPA 12.6.1. 在Spring环境中建立JPA 12.6.1.1. LocalEntityManagerFactoryBean 12.6.1.2. LocalContainerEntityManagerFactoryBean 12.6.1.3. 处理多个持久化单元 12.6.2. JpaTemplate 和 JpaDaoSupport 12.6.3. 基于原生的JPA实现DAO 12.6.4. 异常转化 12.6.5. 事务管理 12.6.6. JpaDialect III. Web 13. Web框架 13.1. 介绍 13.1.1. 与其他web框架的集成 13.1.2. Spring Web MVC框架的特点 13.2. DispatcherServlet 13.3. 控制器 13.3.1. AbstractController 和 WebContentGenerator 13.3.2. 其它的简单控制器 13.3.3. MultiActionController 13.3.4. 命令控制器 13.4. 处理器映射(handler mapping) 13.4.1. BeanNameUrlHandlerMapping 13.4.2. SimpleUrlHandlerMapping 13.4.3. 拦截器(HandlerInterceptor) 13.5. 视图与视图解析 13.5.1. 视图解析器 13.5.2. 视图解析链 13.5.3. 重定向(Rediret)到另一个视图 13.5.3.1. RedirectView 13.5.3.2. redirect:前缀 13.5.3.3. forward:前缀 13.6. 本地化解析器 13.6.1. AcceptHeaderLocaleResolver 13.6.2. CookieLocaleResolver 13.6.3. SessionLocaleResolver 13.6.4. LocaleChangeInterceptor 13.7. 使用主题 13.7.1. 简介 13.7.2. 如何定义主题 13.7.3. 主题解析器 13.8. Spring对分段文件上传(multipart file upload)的支持 13.8.1. 介绍 13.8.2. 使用MultipartResolver 13.8.3. 在表单中处理分段文件上传 13.9. 使用Spring的表单标签库 13.9.1. 配置标签库 13.9.2. form标签 13.9.3. input标签 13.9.4. checkbox标签 13.9.5. radiobutton标签 13.9.6. password标签 13.9.7. select标签 13.9.8. option标签 13.9.9. options标签 13.9.10. textarea标签 13.9.11. hidden标签 13.9.12. errors标签 13.10. 处理异常 13.11. 惯例优先原则(convention over configuration) 13.11.1. 对控制器的支持: ControllerClassNameHandlerMapping 13.11.2. 对模型的支持:ModelMap (ModelAndView) 13.11.3. 对视图的支持: RequestToViewNameTranslator 13.12. 其它资源 14. 集成视图技术 14.1. 简介 14.2. JSP和JSTL 14.2.1. 视图解析器 14.2.2. 'Plain-old' JSPs versus JSTL 'Plain-old' JSP与JSTL 14.2.3. 帮助简化开发的额外的标签 14.3. Tiles 14.3.1. 需要的资源 14.3.2. 如何集成Tiles 14.3.2.1. InternalResourceViewResolver 14.3.2.2. ResourceBundleViewResolver 14.4. Velocity和FreeMarker 14.4.1. 需要的资源 14.4.2. Context 配置 14.4.3. 创建模板 14.4.4. 高级配置 14.4.4.1. velocity.properties 14.4.4.2. FreeMarker 14.4.5. 绑定支持和表单处理 14.4.5.1. 用于绑定的宏 14.4.5.2. 简单绑定 14.4.5.3. 表单输入生成宏 14.4.5.4. 重载HTML转码行为并使你的标签符合XHTML 14.5. XSLT 14.5.1. 写在段首 14.5.1.1. Bean 定义 14.5.1.2. 标准MVC控制器代码 14.5.1.3. 把模型数据转化为XML 14.5.1.4. 定义视图属性 14.5.1.5. 文档转换 14.5.2. 小结 14.6. 文档视图(PDF/Excel) 14.6.1. 简介 14.6.2. 配置和安装 14.6.2.1. 文档视图定义 14.6.2.2. Controller 代码 14.6.2.3. Excel视图子类 14.6.2.4. PDF视图子类 14.7. JasperReports 14.7.1. 依赖的资源 14.7.2. 配置 14.7.2.1. 配置ViewResolver 14.7.2.2. 配置View 14.7.2.3. 关于报表文件 14.7.2.4. 使用 JasperReportsMultiFormatView 14.7.3. 构造ModelAndView 14.7.4. 使用子报表 14.7.4.1. 配置子报表文件 14.7.4.2. 配置子报表数据源 14.7.5. 配置Exporter的参数 15. 集成其它Web框架 15.1. 简介 15.2. 通用配置 15.3. JavaServer Faces 15.3.1. DelegatingVariableResolver 15.3.2. FacesContextUtils 15.4. Struts 15.4.1. ContextLoaderPlugin 15.4.1.1. DelegatingRequestProcessor 15.4.1.2. DelegatingActionProxy 15.4.2. ActionSupport 类 15.5. Tapestry 15.5.1. 注入 Spring 托管的 beans 15.5.1.1. 将 Spring Beans 注入到 Tapestry 页面中 15.5.1.2. 组件定义文件 15.5.1.3. 添加抽象访问方法 15.5.1.4. 将 Spring Beans 注入到 Tapestry 页面中 - Tapestry 4.0+ 风格 15.6. WebWork 15.7. 更多资源 16. Portlet MVC框架 16.1. 介绍 16.1.1. 控制器 - MVC中的C 16.1.2. 视图 - MVC中的V 16.1.3. Web作用范围的Bean 16.2. DispatcherPortlet 16.3. ViewRendererServlet 16.4. 控制器 16.4.1. AbstractController和PortletContentGenerator 16.4.2. 其它简单的控制器 16.4.3. Command控制器 16.4.4. PortletWrappingController 16.5. 处理器映射 16.5.1. PortletModeHandlerMapping 16.5.2. ParameterHandlerMapping 16.5.3. PortletModeParameterHandlerMapping 16.5.4. 增加 HandlerInterceptor 16.5.5. HandlerInterceptorAdapter 16.5.6. ParameterMappingInterceptor 16.6. 视图和它们的解析 16.7. Multipart文件上传支持 16.7.1. 使用PortletMultipartResolver 16.7.2. 处理表单里的文件上传 16.8. 异常处理 16.9. Portlet应用的部署 IV. 整合 17. 使用Spring进行远程访问与Web服务 17.1. 简介 17.2. 使用RMI暴露服务 17.2.1. 使用 RmiServiceExporter 暴露服务 17.2.2. 在客户端链接服务 17.3. 使用Hessian或者Burlap通过HTTP远程调用服务 17.3.1. 为Hessian配置DispatcherServlet 17.3.2. 使用HessianServiceExporter暴露你的bean 17.3.3. 客户端连接服务 17.3.4. 使用Burlap 17.3.5. 对通过Hessian或Burlap暴露的服务使用HTTP基础认证 17.4. 使用HTTP调用器暴露服务 17.4.1. 暴露服务对象 17.4.2. 在客户端连接服务 17.5. Web服务 17.5.1. 使用JAXI-RPC暴露服务 17.5.2. 访问Web服务 17.5.3. 注册bean映射 17.5.4. 注册自己的处理方法 17.5.5. 使用XFire来暴露Web服务 17.6. 对远程接口不提供自动探测 17.7. 在选择这些技术时的一些考虑 18. Enterprise Java Bean(EJB)集成 18.1. 简介 18.2. 访问EJB 18.2.1. 概念 18.2.2. 访问本地的无状态Session Bean(SLSB) 18.2.3. 访问远程SLSB 18.3. 使用Spring提供的辅助类实现EJB组件 19. JMS 19.1. 简介 19.2. 使用Spring JMS 19.2.1. JmsTemplate 19.2.2. 连接工厂 19.2.3. (消息)目的地管理 19.2.4. 消息侦听容器 19.2.4.1. SimpleMessageListenerContainer 19.2.4.2. DefaultMessageListenerContainer 19.2.4.3. ServerSessionMessageListenerContainer 19.2.5. 事务管理 19.3. 发送一条消息 19.3.1. 使用消息转换器 19.3.2. SessionCallback 和ProducerCallback 19.4. 接收消息 19.4.1. 同步接收 19.4.2. 异步接收 - 消息驱动的POJOs 19.4.3. SessionAwareMessageListener 接口 19.4.4. MessageListenerAdapter 19.4.5. 事务中的多方参与 20. JMX 20.1. 介绍 20.2. 输出bean到JMX 20.2.1. 创建一个MBeanServer 20.2.2. 复用现有的MBeanServer 20.2.3. MBean的惰性初始化 20.2.4. MBean的自动注册 20.2.5. 控制注册行为 20.3. 控制bean的管理接口 20.3.1. MBeanInfoAssembler 接口 20.3.2. 使用源码级元数据 20.3.3. 使用JDK 5.0注解 20.3.4. 源代码级的元数据类型 20.3.5. 接口AutodetectCapableMBeanInfoAssembler 20.3.6. 用Java接口定义管理接口 20.3.7. 使用MethodNameBasedMBeanInfoAssembler 20.4. 控制bean的 ObjectName 20.4.1. 从Properties中读取ObjectName 20.4.2. 使用 MetadataNamingStrategy 20.5. JSR-160连接器 20.5.1. 服务器端连接器 20.5.2. 客户端连接器 20.5.3. 基于Burlap/Hessian/SOAP的JMX 20.6. 通过代理访问MBeans 20.7. 通知 20.7.1. 为通知注册监听器 20.7.2. 发布通知 20.8. 更多资源 21. JCA CCI 21.1. 介绍 21.2. 配置CCI 21.2.1. 连接器配置 21.2.2. 在Spring中配置ConnectionFactory 21.2.3. 配置CCI连接 21.2.4. 使用一个 CCI 单连接 21.3. 使用Spring的 CCI访问支持 21.3.1. 记录转换 21.3.2. CciTemplate 类 21.3.3. DAO支持 21.3.4. 自动输出记录生成 21.3.5. 总结 21.3.6. 直接使用一个 CCI Connection 接口和Interaction接口 21.3.7. CciTemplate 使用示例 21.4. 建模CCI访问为操作对象 21.4.1. MappingRecordOperation 21.4.2. MappingCommAreaOperation 21.4.3. 自动输出记录生成 21.4.4. 总结 21.4.5. MappingRecordOperation 使用示例 21.4.6. MappingCommAreaOperation 使用示例 21.5. 事务 22. Spring邮件抽象层 22.1. 简介 22.2. Spring邮件抽象结构 22.3. 使用Spring邮件抽象 22.3.1. 可插拔的MailSender实现 22.4. 使用 JavaMail MimeMessageHelper 22.4.1. 创建一条简单的MimeMessage,并且发送出去 22.4.2. 发送附件和嵌入式资源(inline resources) 23. Spring中的定时调度(Scheduling)和线程池(Thread Pooling) 23.1. 简介 23.2. 使用OpenSymphony Quartz 调度器 23.2.1. 使用JobDetailBean 23.2.2. 使用 MethodInvokingJobDetailFactoryBean 23.2.3. 使用triggers和SchedulerFactoryBean来包装任务 23.3. 使用JDK Timer支持类 23.3.1. 创建定制的timers 23.3.2. 使用 MethodInvokingTimerTaskFactoryBean类 23.3.3. 打包:使用TimerFactoryBean来设置任务 23.4. SpringTaskExecutor抽象 23.4.1. TaskExecutor接口 23.4.2. 何时使用TaskExecutor接口 23.4.3. TaskExecutor类型 23.4.4. 使用TaskExecutor接口 24. 动态语言支持 24.1. 介绍 24.2. 第一个例子 24.3. 定义动态语言支持的bean 24.3.1. 公共概念 24.3.1.1. <lang:language/> 元素 24.3.1.2. Refreshable bean 24.3.1.3. 内置动态语言源文件 24.3.1.4. 理解dynamic-language-backed bean context的构造器注入 24.3.2. JRuby beans 24.3.3. Groovy beans 24.3.4. BeanShell beans 24.4. 场景 24.4.1. Spring MVC控制器脚本化 24.4.2. Validator脚本化 24.5. 更多的资源 25. 注解和源代码级的元数据支持 25.1. 简介 25.2. Spring的元数据支持 25.3. 注解 25.3.1. @Required 25.3.2. Spring中的其它@Annotations 25.4. 集成Jakarta Commons Attributes 25.5. 元数据和Spring AOP自动代理 25.5.1. 基本原理 25.5.2. 声明式事务管理 25.5.3. 缓冲 25.5.4. 自定义元数据 25.6. 使用属性来减少MVC web层配置 25.7. 元数据属性的其它用法 25.8. 增加对额外元数据API的支持 A. XML Schema-based configuration A.1. Introduction A.2. XML Schema-based configuration A.2.1. Referencing the schemas A.2.2. The util schema A.2.2.1. <util:constant/> A.2.2.2. <util:property-path/> A.2.2.3. <util:properties/> A.2.2.4. <util:list/> A.2.2.5. <util:map/> A.2.2.6. <util:set/> A.2.3. The jee schema A.2.3.1. <jee:jndi-lookup/> (simple) A.2.3.2. <jee:jndi-lookup/> (with single JNDI environment setting) A.2.3.3. <jee:jndi-lookup/> (with multiple JNDI environment settings) A.2.3.4. <jee:jndi-lookup/> (complex) A.2.3.5. <jee:local-slsb/> (simple) A.2.3.6. <jee:local-slsb/> (complex) A.2.3.7. <jee:remote-slsb/> A.2.4. The lang schema A.2.5. The tx (transaction) schema A.2.6. The aop schema A.2.7. The tool schema A.2.8. The beans schema A.3. Setting up your IDE A.3.1. Setting up Eclipse A.3.2. Setting up IntelliJ IDEA A.3.3. Integration issues A.3.3.1. XML parsing errors in the Resin v.3 application server B. Extensible XML authoring B.1. Introduction B.2. Authoring the schema B.3. Coding a NamespaceHandler B.4. Coding a BeanDefinitionParser B.5. Registering the handler and the schema B.5.1. META-INF/spring.handlers B.5.2. META-INF/spring.schemas C. spring-beans-2.0.dtd D. spring.tld D.1. Introduction D.2. The bind tag D.3. The escapeBody tag D.4. The hasBindErrors tag D.5. The htmlEscape tag D.6. The message tag D.7. The nestedPath tag D.8. The theme tag D.9. The transform tag E. spring-form.tld E.1. Introduction E.2. The checkbox tag E.3. The errors tag E.4. The form tag E.5. The hidden tag E.6. The input tag E.7. The label tag E.8. The option tag E.9. The options tag E.10. The password tag E.11. The radiobutton tag E.12. The select tag E.13. The textarea tag F. Spring 2.0 开发手册中文化项目 F.1. 声明 F.2. 致谢 F.3. 参与人员及任务分配 F.4. Spring 2.0 正式版开发手册翻译说明 F.5. 项目历程 F.5.1. Spring 2.0 RC2 开发手册翻译项目 F.5.2. Spring 2.0 正式版开发手册翻译项目

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值