spring activemq @JmsListener 参数配置

5 篇文章 0 订阅

id

	/**
	 * The unique identifier of the container managing this endpoint.
	 * <p>If none is specified, an auto-generated one is provided.
	 * @see org.springframework.jms.config.JmsListenerEndpointRegistry#getListenerContainer(String)
	 */
	String id() default "";

唯一标志符,如果不填,则会默认生成为:
org.springframework.jms.JmsListenerEndpointContainer#0
org.springframework.jms.JmsListenerEndpointContainer#1

默认生成代码为:

	private final AtomicInteger counter = new AtomicInteger();
	...
	private String getEndpointId(JmsListener jmsListener) {
		if (StringUtils.hasText(jmsListener.id())) {
			return resolve(jmsListener.id());
		}
		else {
			return "org.springframework.jms.JmsListenerEndpointContainer#" + this.counter.getAndIncrement();
		}
	}

containerFactory

	/**
	 * The bean name of the {@link org.springframework.jms.config.JmsListenerContainerFactory}
	 * to use to create the message listener container responsible for serving this endpoint.
	 * <p>If not specified, the default container factory is used, if any.
	 */
	String containerFactory() default "";

用来创建MessageListenerContainer
JmsListenerAnnotationBeanPostProcessor>JmsListenerEndpointRegistrar>JmsListenerEndpointRegistry>

/**
	 * Create and start a new container using the specified factory.
	 */
	protected MessageListenerContainer createListenerContainer(JmsListenerEndpoint endpoint,
			JmsListenerContainerFactory<?> factory) {

		MessageListenerContainer listenerContainer = factory.createListenerContainer(endpoint);

		if (listenerContainer instanceof InitializingBean) {
			try {
				((InitializingBean) listenerContainer).afterPropertiesSet();
			}
			catch (Exception ex) {
				throw new BeanInitializationException("Failed to initialize message listener container", ex);
			}
		}

		int containerPhase = listenerContainer.getPhase();
		if (containerPhase < Integer.MAX_VALUE) {  // a custom phase value
			if (this.phase < Integer.MAX_VALUE && this.phase != containerPhase) {
				throw new IllegalStateException("Encountered phase mismatch between container factory definitions: " +
						this.phase + " vs " + containerPhase);
			}
			this.phase = listenerContainer.getPhase();
		}

		return listenerContainer;
	}

containerFactory的配置

@Aspect
@Configuration
@EnableJms
public class ActiveMqConfig {

    @Bean
    public ConnectionFactory connectionFactory(@Value("${activemq.broker.url}") String brokerURL) {
        return new CachingConnectionFactory(new ActiveMQConnectionFactory(brokerURL));
    }

	    @Bean
    public SimpleJmsListenerContainerFactory jmsListenerContainerFactory(ConnectionFactory connectionFactory) {
        SimpleJmsListenerContainerFactory factory = new SimpleJmsListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory);
        return factory;
    }
}

destination

/**
	 * The destination name for this listener, resolved through the container-wide
	 * {@link org.springframework.jms.support.destination.DestinationResolver} strategy.
	 */
	String destination();

监听的queue或者topic

subscription

	/**
	 * The name for the durable subscription, if any.
	 */
	String subscription() default "";

持久化订阅名字,监听topic的时候,如果需要持久化订阅,需要设置该名字,还需要在配置containFactory的时候进行一下配置

	factory.setSubscriptionDurable(true);
    factory.setClientId("clientId");

selector

	/**
	 * The JMS message selector expression, if any.
	 * <p>See the JMS specification for a detailed definition of selector expressions.
	 */
	String selector() default "";

选择器,一个条件表达式,遵循sql 92语法,只会过滤property或者消息头信息,没仔细验证过,估计就是Message里面的getset方法的大部分属性

concurrency

	/**
	 * The concurrency limits for the listener, if any.
	 * <p>The concurrency limits can be a "lower-upper" String &mdash; for example,
	 * "5-10" &mdash; or a simple upper limit String &mdash; for example, "10", in
	 * which case the lower limit will be 1.
	 * <p>Note that the underlying container may or may not support all features.
	 * For instance, it may not be able to scale, in which case only the upper limit
	 * is used.
	 */
	String concurrency() default "";

并发数量的设置,格式 num-num (下限-上限) 或者 num (上限)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值