文档章节

SpringFramework4系列之SpringJMS:(五)Jms namespace的使用

Garrry
 Garrry
发布于 2015/07/07 22:37
字数 993
阅读 1060
收藏 11

Spring jms 的命名空间

xmlns:jms=" 
xsi:schemaLocation="
http://www.springframework.org/schema/jms
http://www.springframework.org/schema/jms/spring-jms.xsd"

Spring jms 的命名空间元素

SpringJMS 提供了 三种 命名空间元素

<jms:annotation-drive>
<jms:listener-container>
<jms:jca-listener-container>

<jms:annotation-drive>


<jms:listener-container>

用例

<jms:listener-container>
    <jms:listener destination="queue.orders" ref="orderService" method="placeOrder"/>
    <jms:listener destination="queue.confirmations" ref="confirmationLogger" method="log"/>
</jms:listener-container>

可见<jms:listener-container> 是用来定义Listener Container和容器内的监听器的。使配置简洁明了。

对于<jms:listener-container> 它只有一个子节点<jms:listener>.而它本身可以定义多个属性

<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>

table2.1 <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').
container-class A custom listener container   implementation class as fully qualified class name. Default is Spring’s   standard DefaultMessageListenerContainer or SimpleMessageListenerContainer, according to the "container-type" attribute.
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.
connection-factory A reference to the JMS ConnectionFactory bean (the default   bean name is 'connectionFactory').
task-executor A reference to the Spring TaskExecutor for the JMS listener   invokers.
destination-resolver A reference to the DestinationResolver strategy for   resolving JMS Destinations.
message-converter A reference to the MessageConverter strategy for   converting JMS Messages to listener method arguments. Default is a SimpleMessageConverter.
error-handler A reference to an ErrorHandler strategy for handling   any uncaught Exceptions that may occur during the execution of the 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).
client-id The JMS client id for this   listener container. Needs to be specified when using durable subscriptions.
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).
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.
transaction-manager A reference to an external PlatformTransactionManager   (typically an XA-based transaction coordinator, e.g. Spring’s JtaTransactionManager). If not   specified, native acknowledging will be used (see "acknowledge"   attribute).
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.
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.
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.
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.
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.


table 2.2 <jms:listener>的属性

Attribute Description
id A bean name for the hosting   listener container. If not specified, a bean name will be automatically   generated.
destination   (required) The destination name for this   listener, resolved through the DestinationResolver strategy.
ref (required) The bean name of the handler   object.
method The name of the handler method   to invoke. If the ref points   to a MessageListener or   Spring SessionAwareMessageListener, this attribute may be omitted.
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-container’s "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.
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

<jms:jca-listener-container>

© 著作权归作者所有

Garrry
粉丝 27
博文 46
码字总数 48703
作品 0
浦东
技术主管
私信 提问
SpringFramework4系列之SpringJMS:(四)异步接收消息 2.构建监听器

在Spring中,构建监听器 有三种方式: 实现监听器接口 适配器托管 注解监听器 其中,实现接口和注解监听器 都需要一个监听器容器的支持。 构建实现接口的监听器 编写监听器类并且实现监听器接...

Garrry
2015/07/07
1K
2
SpringFramework4系列之SpringJMS:(一)搭建JMS-注解加XML版

Maven dependency maven的dependency用着 隐形的依赖传递性,如果只是用到 JMS这部分功能 引用一下Maven坐标即可 <dependency> <groupId>org.springframework</groupId> <artifactId>spring......

Garrry
2015/07/06
3K
0
SpringFramework4系列之整合Resteasy

对于和jboss as7的集成不需要做任何工作,jboss默认集成了resteasy,只需要对业务pojo做一些jax-rs的注解标注即可。 对于非Jboss的Servlet容器 Spring和resteasy集成,主要有三种方式, 运行...

Garrry
2015/07/21
1K
0
SpringFramework4系列之SpringJMS:(四)异步接收消息 1.基本介绍

以往我们监听消息队列的时候,通常都是用EJB的MDB(Message-driven bean). 这需要EJB容器的支持。springframework4 对JMS的支持 使得我们使用常规的POJO就可以作为监听器 接收消息队列的信息...

Garrry
2015/07/07
314
0
idea 中web.xml 文件的标签疯狂报错

element XXX is not allowed here的错误。网上很多说重启idea或者Tomcat的jar包配置的,真是希望自己试一下再转帖啊,几篇错误的能抄的到处都是,害人害己啊。 1、注意比对web.xml的头文件格...

Aeroever
09/25
17
0

没有更多内容

加载失败,请刷新页面

加载更多

golang-字符串-地址分析

demo package mainimport "fmt"func main() {str := "map.baidu.com"fmt.Println(&str, str)str = str[0:5]fmt.Println(&str, str)str = "abc"fmt.Println(&s......

李琼涛
55分钟前
4
0
Spring Boot WebFlux 增删改查完整实战 demo

03:WebFlux Web CRUD 实践 前言 上一篇基于功能性端点去创建一个简单服务,实现了 Hello 。这一篇用 Spring Boot WebFlux 的注解控制层技术创建一个 CRUD WebFlux 应用,让开发更方便。这里...

泥瓦匠BYSocket
今天
6
0
从0开始学FreeRTOS-(列表与列表项)-3

FreeRTOS列表&列表项的源码解读 第一次看列表与列表项的时候,感觉很像是链表,虽然我自己的链表也不太会,但是就是感觉很像。 在FreeRTOS中,列表与列表项使用得非常多,是FreeRTOS的一个数...

杰杰1号
今天
4
0
Java反射

Java 反射 反射是框架设计的灵魂(使用的前提条件:必须先得到代表的字节码的 Class,Class 类 用于表示.class 文件(字节码)) 一、反射的概述 定义:JAVA 反射机制是在运行状态中,对于任...

zzz1122334
今天
5
0
聊聊nacos的LocalConfigInfoProcessor

序 本文主要研究一下nacos的LocalConfigInfoProcessor LocalConfigInfoProcessor nacos-1.1.3/client/src/main/java/com/alibaba/nacos/client/config/impl/LocalConfigInfoProcessor.java p......

go4it
昨天
8
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部