spring activemq @JmsListener 參數配置

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 (上限)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章