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

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>的属性

AttributeDescription
container-typeThe type of this listener   container. Available options are: default, simple,   default102, or simple102 (the default value is 'default').
container-classA 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-idExposes the settings defined by   this element as a JmsListenerContainerFactory with the specified id so that they can be reused with other   endpoints.
connection-factoryA reference to the JMS ConnectionFactory bean (the default   bean name is 'connectionFactory').
task-executorA reference to the Spring TaskExecutor for the JMS listener   invokers.
destination-resolverA reference to the DestinationResolver strategy for   resolving JMS Destinations.
message-converterA reference to the MessageConverter strategy for   converting JMS Messages to listener method arguments. Default is a SimpleMessageConverter.
error-handlerA reference to an ErrorHandler strategy for handling   any uncaught Exceptions that may occur during the execution of the MessageListener.
destination-typeThe 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-idThe JMS client id for this   listener container. Needs to be specified when using durable subscriptions.
cacheThe 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).
acknowledgeThe 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-managerA 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).
concurrencyThe 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.
prefetchThe maximum number of messages   to load into a single session. Note that raising this number might lead to   starvation of concurrent consumers!
receive-timeoutThe timeout to use for receive   calls (in milliseconds). The default is 1000 ms (1 sec); -1 indicates no timeout at all.
back-offSpecify 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-intervalSpecify 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.
phaseThe 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>的属性

AttributeDescription
idA 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.
methodThe name of the handler method   to invoke. If the ref points   to a MessageListener or   Spring SessionAwareMessageListener, this attribute may be omitted.
response-destinationThe 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.
subscriptionThe name of the durable   subscription, if any.
selectorAn optional message selector for   this listener.
concurrencyThe 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>

转载于:https://my.oschina.net/u/1041012/blog/475848

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值