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 — for example,
* "5-10" — or a simple upper limit String — 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 (上限)