Java Code Examples for org.springframework.jms.config.JmsListenerContainerFactory

The following examples show how to use org.springframework.jms.config.JmsListenerContainerFactory. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Bean
public JmsListenerContainerFactory<?> myFactory(ConnectionFactory connectionFactory,
		DefaultJmsListenerContainerFactoryConfigurer configurer) {
	DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
	// This provides all boot's default to this factory, including the message
	// converter
	configurer.configure(factory, connectionFactory);

	// You could still override some of Boot's default if necessary.

	// 设置连接数
	factory.setConcurrency("3-10");
	// 重连间隔时间
	factory.setRecoveryInterval(1000L);

	return factory;
}
 
Example 2
Source Project: flowable-engine   Source File: JmsChannelModelProcessor.java    License: Apache License 2.0 6 votes vote down vote up
protected JmsListenerContainerFactory<?> resolveContainerFactory(JmsListenerEndpoint endpoint, JmsListenerContainerFactory<?> containerFactory) {
    if (containerFactory != null) {
        return containerFactory;
    } else if (this.containerFactory != null) {
        return this.containerFactory;
    } else if (containerFactoryBeanName != null) {
        Assert.state(beanFactory != null, "BeanFactory must be set to obtain container factory by bean name");
        // Consider changing this if live change of the factory is required...
        this.containerFactory = beanFactory.getBean(containerFactoryBeanName, JmsListenerContainerFactory.class);
        return this.containerFactory;
    } else {
        throw new IllegalStateException("Could not resolve the " +
            JmsListenerContainerFactory.class.getSimpleName() + " to use for [" +
            endpoint + "] no factory was given and no default is set.");
    }
}
 
Example 3
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
	if (bean instanceof AopInfrastructureBean || bean instanceof JmsListenerContainerFactory ||
			bean instanceof JmsListenerEndpointRegistry) {
		// Ignore AOP infrastructure such as scoped proxies.
		return bean;
	}

	Class<?> targetClass = AopProxyUtils.ultimateTargetClass(bean);
	if (!this.nonAnnotatedClasses.contains(targetClass) &&
			AnnotationUtils.isCandidateClass(targetClass, JmsListener.class)) {
		Map<Method, Set<JmsListener>> annotatedMethods = MethodIntrospector.selectMethods(targetClass,
				(MethodIntrospector.MetadataLookup<Set<JmsListener>>) method -> {
					Set<JmsListener> listenerMethods = AnnotatedElementUtils.getMergedRepeatableAnnotations(
							method, JmsListener.class, JmsListeners.class);
					return (!listenerMethods.isEmpty() ? listenerMethods : null);
				});
		if (annotatedMethods.isEmpty()) {
			this.nonAnnotatedClasses.add(targetClass);
			if (logger.isTraceEnabled()) {
				logger.trace("No @JmsListener annotations found on bean type: " + targetClass);
			}
		}
		else {
			// Non-empty set of methods
			annotatedMethods.forEach((method, listeners) ->
					listeners.forEach(listener -> processJmsListener(listener, method, bean)));
			if (logger.isDebugEnabled()) {
				logger.debug(annotatedMethods.size() + " @JmsListener methods processed on bean '" + beanName +
						"': " + annotatedMethods);
			}
		}
	}
	return bean;
}
 
Example 4
/**
 * Process the given {@link JmsListener} annotation on the given method,
 * registering a corresponding endpoint for the given bean instance.
 * @param jmsListener the annotation to process
 * @param mostSpecificMethod the annotated method
 * @param bean the instance to invoke the method on
 * @see #createMethodJmsListenerEndpoint()
 * @see JmsListenerEndpointRegistrar#registerEndpoint
 */
protected void processJmsListener(JmsListener jmsListener, Method mostSpecificMethod, Object bean) {
	Method invocableMethod = AopUtils.selectInvocableMethod(mostSpecificMethod, bean.getClass());

	MethodJmsListenerEndpoint endpoint = createMethodJmsListenerEndpoint();
	endpoint.setBean(bean);
	endpoint.setMethod(invocableMethod);
	endpoint.setMostSpecificMethod(mostSpecificMethod);
	endpoint.setMessageHandlerMethodFactory(this.messageHandlerMethodFactory);
	endpoint.setEmbeddedValueResolver(this.embeddedValueResolver);
	endpoint.setBeanFactory(this.beanFactory);
	endpoint.setId(getEndpointId(jmsListener));
	endpoint.setDestination(resolve(jmsListener.destination()));
	if (StringUtils.hasText(jmsListener.selector())) {
		endpoint.setSelector(resolve(jmsListener.selector()));
	}
	if (StringUtils.hasText(jmsListener.subscription())) {
		endpoint.setSubscription(resolve(jmsListener.subscription()));
	}
	if (StringUtils.hasText(jmsListener.concurrency())) {
		endpoint.setConcurrency(resolve(jmsListener.concurrency()));
	}

	JmsListenerContainerFactory<?> factory = null;
	String containerFactoryBeanName = resolve(jmsListener.containerFactory());
	if (StringUtils.hasText(containerFactoryBeanName)) {
		Assert.state(this.beanFactory != null, "BeanFactory must be set to obtain container factory by bean name");
		try {
			factory = this.beanFactory.getBean(containerFactoryBeanName, JmsListenerContainerFactory.class);
		}
		catch (NoSuchBeanDefinitionException ex) {
			throw new BeanInitializationException("Could not register JMS listener endpoint on [" +
					mostSpecificMethod + "], no " + JmsListenerContainerFactory.class.getSimpleName() +
					" with id '" + containerFactoryBeanName + "' was found in the application context", ex);
		}
	}

	this.registrar.registerEndpoint(endpoint, factory);
}
 
Example 5
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
	if (bean instanceof AopInfrastructureBean || bean instanceof JmsListenerContainerFactory ||
			bean instanceof JmsListenerEndpointRegistry) {
		// Ignore AOP infrastructure such as scoped proxies.
		return bean;
	}

	Class<?> targetClass = AopProxyUtils.ultimateTargetClass(bean);
	if (!this.nonAnnotatedClasses.contains(targetClass)) {
		Map<Method, Set<JmsListener>> annotatedMethods = MethodIntrospector.selectMethods(targetClass,
				(MethodIntrospector.MetadataLookup<Set<JmsListener>>) method -> {
					Set<JmsListener> listenerMethods = AnnotatedElementUtils.getMergedRepeatableAnnotations(
							method, JmsListener.class, JmsListeners.class);
					return (!listenerMethods.isEmpty() ? listenerMethods : null);
				});
		if (annotatedMethods.isEmpty()) {
			this.nonAnnotatedClasses.add(targetClass);
			if (logger.isTraceEnabled()) {
				logger.trace("No @JmsListener annotations found on bean type: " + targetClass);
			}
		}
		else {
			// Non-empty set of methods
			annotatedMethods.forEach((method, listeners) ->
					listeners.forEach(listener -> processJmsListener(listener, method, bean)));
			if (logger.isDebugEnabled()) {
				logger.debug(annotatedMethods.size() + " @JmsListener methods processed on bean '" + beanName +
						"': " + annotatedMethods);
			}
		}
	}
	return bean;
}
 
Example 6
/**
 * Process the given {@link JmsListener} annotation on the given method,
 * registering a corresponding endpoint for the given bean instance.
 * @param jmsListener the annotation to process
 * @param mostSpecificMethod the annotated method
 * @param bean the instance to invoke the method on
 * @see #createMethodJmsListenerEndpoint()
 * @see JmsListenerEndpointRegistrar#registerEndpoint
 */
protected void processJmsListener(JmsListener jmsListener, Method mostSpecificMethod, Object bean) {
	Method invocableMethod = AopUtils.selectInvocableMethod(mostSpecificMethod, bean.getClass());

	MethodJmsListenerEndpoint endpoint = createMethodJmsListenerEndpoint();
	endpoint.setBean(bean);
	endpoint.setMethod(invocableMethod);
	endpoint.setMostSpecificMethod(mostSpecificMethod);
	endpoint.setMessageHandlerMethodFactory(this.messageHandlerMethodFactory);
	endpoint.setEmbeddedValueResolver(this.embeddedValueResolver);
	endpoint.setBeanFactory(this.beanFactory);
	endpoint.setId(getEndpointId(jmsListener));
	endpoint.setDestination(resolve(jmsListener.destination()));
	if (StringUtils.hasText(jmsListener.selector())) {
		endpoint.setSelector(resolve(jmsListener.selector()));
	}
	if (StringUtils.hasText(jmsListener.subscription())) {
		endpoint.setSubscription(resolve(jmsListener.subscription()));
	}
	if (StringUtils.hasText(jmsListener.concurrency())) {
		endpoint.setConcurrency(resolve(jmsListener.concurrency()));
	}

	JmsListenerContainerFactory<?> factory = null;
	String containerFactoryBeanName = resolve(jmsListener.containerFactory());
	if (StringUtils.hasText(containerFactoryBeanName)) {
		Assert.state(this.beanFactory != null, "BeanFactory must be set to obtain container factory by bean name");
		try {
			factory = this.beanFactory.getBean(containerFactoryBeanName, JmsListenerContainerFactory.class);
		}
		catch (NoSuchBeanDefinitionException ex) {
			throw new BeanInitializationException("Could not register JMS listener endpoint on [" +
					mostSpecificMethod + "], no " + JmsListenerContainerFactory.class.getSimpleName() +
					" with id '" + containerFactoryBeanName + "' was found in the application context", ex);
		}
	}

	this.registrar.registerEndpoint(endpoint, factory);
}
 
Example 7
Source Project: hdw-dubbo   Source File: ActiveMQConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean(name = "topicJmsListenerContainerFactory")
public JmsListenerContainerFactory<?> topicJmsListenerContainerFactory() {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    factory.setPubSubDomain(true);
    factory.setConnectionFactory(cachingConnectionFactory());
    return factory;
}
 
Example 8
Source Project: hdw-dubbo   Source File: ActiveMQConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean(name = "queueJmsListenerContainerFactory")
public JmsListenerContainerFactory<?> queueJmsListenerContainerFactory() {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    factory.setPubSubDomain(false);
    factory.setConnectionFactory(cachingConnectionFactory());
    return factory;
}
 
Example 9
Source Project: promregator   Source File: JMSSpringConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public JmsListenerContainerFactory<?> jmsListenerContainerFactory(ConnectionFactory connectionFactory,
		DefaultJmsListenerContainerFactoryConfigurer configurer) {
	DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
	configurer.configure(factory, connectionFactory);
	return factory;
}
 
Example 10
Source Project: seckill   Source File: SecKillEventConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
JmsListenerContainerFactory<?> containerFactory(ConnectionFactory connectionFactory,
    DefaultJmsListenerContainerFactoryConfigurer configurer) {
  DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
  configurer.configure(factory, connectionFactory);
  return factory;
}
 
Example 11
Source Project: myth   Source File: JmsConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Jms listener container queue jms listener container factory.
 *
 * @param activeMQConnectionFactory the active mq connection factory
 * @return the jms listener container factory
 */
@Bean(name = "queueListenerContainerFactory")
@ConditionalOnProperty(prefix = "spring.activemq", name = "broker-url")
public JmsListenerContainerFactory<?> jmsListenerContainerQueue(ConnectionFactory activeMQConnectionFactory) {
    DefaultJmsListenerContainerFactory bean = new DefaultJmsListenerContainerFactory();
    bean.setConnectionFactory(activeMQConnectionFactory);
    bean.setPubSubDomain(Boolean.FALSE);
    return bean;
}
 
Example 12
Source Project: myth   Source File: JmsConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Jms listener container queue jms listener container factory.
 *
 * @param activeMQConnectionFactory the active mq connection factory
 * @return the jms listener container factory
 */
@Bean(name = "queueListenerContainerFactory")
@ConditionalOnProperty(prefix = "spring.activemq", name = "broker-url")
public JmsListenerContainerFactory<?> jmsListenerContainerQueue(ConnectionFactory activeMQConnectionFactory) {
    DefaultJmsListenerContainerFactory bean = new DefaultJmsListenerContainerFactory();
    bean.setConnectionFactory(activeMQConnectionFactory);
    bean.setPubSubDomain(Boolean.FALSE);
    return bean;
}
 
Example 13
Source Project: myth   Source File: JmsConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean(name = "queueListenerContainerFactory")
@ConditionalOnProperty(prefix = "spring.activemq", name = "broker-url")
public JmsListenerContainerFactory<?> jmsListenerContainerQueue(ConnectionFactory activeMQConnectionFactory) {
    DefaultJmsListenerContainerFactory bean = new DefaultJmsListenerContainerFactory();
    bean.setConnectionFactory(activeMQConnectionFactory);
    bean.setPubSubDomain(Boolean.FALSE);
    return bean;
}
 
Example 14
Source Project: myth   Source File: JmsConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Jms listener container queue jms listener container factory.
 *
 * @param activeMQConnectionFactory the active mq connection factory
 * @return the jms listener container factory
 */
@Bean(name = "queueListenerContainerFactory")
@ConditionalOnProperty(prefix = "spring.activemq", name = "broker-url")
public JmsListenerContainerFactory<?> jmsListenerContainerQueue(ConnectionFactory activeMQConnectionFactory) {
    DefaultJmsListenerContainerFactory bean = new DefaultJmsListenerContainerFactory();
    bean.setConnectionFactory(activeMQConnectionFactory);
    bean.setPubSubDomain(Boolean.FALSE);
    return bean;
}
 
Example 15
Source Project: myth   Source File: JmsConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Jms listener container queue jms listener container factory.
 *
 * @param activeMQConnectionFactory the active mq connection factory
 * @return the jms listener container factory
 */
@Bean(name = "queueListenerContainerFactory")
@ConditionalOnProperty(prefix = "spring.activemq", name = "broker-url")
public JmsListenerContainerFactory<?> jmsListenerContainerQueue(ConnectionFactory activeMQConnectionFactory) {
    DefaultJmsListenerContainerFactory bean = new DefaultJmsListenerContainerFactory();
    bean.setConnectionFactory(activeMQConnectionFactory);
    bean.setPubSubDomain(Boolean.FALSE);
    return bean;
}
 
Example 16
Source Project: myth   Source File: JmsConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Jms listener container queue jms listener container factory.
 *
 * @param activeMQConnectionFactory the active mq connection factory
 * @return the jms listener container factory
 */
@Bean(name = "queueListenerContainerFactory")
@ConditionalOnProperty(prefix = "spring.activemq", name = "broker-url")
public JmsListenerContainerFactory<?> jmsListenerContainerQueue(ConnectionFactory activeMQConnectionFactory) {
    DefaultJmsListenerContainerFactory bean = new DefaultJmsListenerContainerFactory();
    bean.setConnectionFactory(activeMQConnectionFactory);
    bean.setPubSubDomain(Boolean.FALSE);
    return bean;
}
 
Example 17
Source Project: jim-framework   Source File: ActivemqConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
public JmsListenerContainerFactory<?> jmsListenerAContainerQueue() {
    DefaultJmsListenerContainerFactory bean = new DefaultJmsListenerContainerFactory();

    bean.setConnectionFactory(this.pooledConnectionFactory);
    bean.setConcurrency("3-10");

    return bean;
}
 
Example 18
Source Project: jim-framework   Source File: ActivemqConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
public JmsListenerContainerFactory<?> jmsListenerBContainerQueue() {
    DefaultJmsListenerContainerFactory bean = new DefaultJmsListenerContainerFactory();
    ActiveMQConnectionFactory connectionFactory=new ActiveMQConnectionFactory(Constans.CONSUMER_B_BROKER_URL);
    //connectionFactory
    bean.setConnectionFactory(connectionFactory);
    bean.setConcurrency("3-10");

    return bean;
}
 
Example 19
@Bean(name = "QpidJMSContainerFactory")
public JmsListenerContainerFactory<?> queue(ConnectionFactory cf) {
    SimpleJmsListenerContainerFactory factory = new SimpleJmsListenerContainerFactory();

    // Configure the factory using the provided JMS ConnectionFactory and apply
    // application defined configuration to the SimpleJmsListenerContainerFactory
    factory.setConnectionFactory(cf);
    factory.setSessionTransacted(false);

    return factory;
}
 
Example 20
Source Project: java-spring-cloud   Source File: JmsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public JmsListenerContainerFactory<?> myFactory(ConnectionFactory connectionFactory,
    DefaultJmsListenerContainerFactoryConfigurer configurer) {
  DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
  // This provides all boot's default to this factory, including the message converter
  configurer.configure(factory, connectionFactory);
  // You could still override some of Boot's default if necessary.
  return factory;
}
 
Example 21
Source Project: java-spring-cloud   Source File: JmsArtemisStarterTest.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public JmsListenerContainerFactory<?> myFactory(ConnectionFactory connectionFactory,
    DefaultJmsListenerContainerFactoryConfigurer configurer) {
  DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
  // This provides all boot's default to this factory, including the message converter
  configurer.configure(factory, connectionFactory);
  // You could still override some of Boot's default if necessary.
  return factory;
}
 
Example 22
@Bean
public JmsListenerContainerFactory<?> myFactory(final ConnectionFactory connectionFactory,
    final DefaultJmsListenerContainerFactoryConfigurer configurer) {
  final DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();

  // anonymous class
  factory.setErrorHandler(t -> LOG.error("An error has occurred in the transaction", t));

  configurer.configure(factory, connectionFactory);
  factory.setSessionTransacted(false);
  return factory;
}
 
Example 23
/**
 * Process the given {@link JmsListener} annotation on the given method,
 * registering a corresponding endpoint for the given bean instance.
 * @param jmsListener the annotation to process
 * @param mostSpecificMethod the annotated method
 * @param bean the instance to invoke the method on
 * @see #createMethodJmsListenerEndpoint()
 * @see JmsListenerEndpointRegistrar#registerEndpoint
 */
protected void processJmsListener(JmsListener jmsListener, Method mostSpecificMethod, Object bean) {
	Method invocableMethod = MethodIntrospector.selectInvocableMethod(mostSpecificMethod, bean.getClass());

	MethodJmsListenerEndpoint endpoint = createMethodJmsListenerEndpoint();
	endpoint.setBean(bean);
	endpoint.setMethod(invocableMethod);
	endpoint.setMostSpecificMethod(mostSpecificMethod);
	endpoint.setMessageHandlerMethodFactory(this.messageHandlerMethodFactory);
	endpoint.setBeanFactory(this.beanFactory);
	endpoint.setId(getEndpointId(jmsListener));
	endpoint.setDestination(resolve(jmsListener.destination()));
	if (StringUtils.hasText(jmsListener.selector())) {
		endpoint.setSelector(resolve(jmsListener.selector()));
	}
	if (StringUtils.hasText(jmsListener.subscription())) {
		endpoint.setSubscription(resolve(jmsListener.subscription()));
	}
	if (StringUtils.hasText(jmsListener.concurrency())) {
		endpoint.setConcurrency(resolve(jmsListener.concurrency()));
	}

	JmsListenerContainerFactory<?> factory = null;
	String containerFactoryBeanName = resolve(jmsListener.containerFactory());
	if (StringUtils.hasText(containerFactoryBeanName)) {
		Assert.state(this.beanFactory != null, "BeanFactory must be set to obtain container factory by bean name");
		try {
			factory = this.beanFactory.getBean(containerFactoryBeanName, JmsListenerContainerFactory.class);
		}
		catch (NoSuchBeanDefinitionException ex) {
			throw new BeanInitializationException("Could not register JMS listener endpoint on [" +
					mostSpecificMethod + "], no " + JmsListenerContainerFactory.class.getSimpleName() +
					" with id '" + containerFactoryBeanName + "' was found in the application context", ex);
		}
	}

	this.registrar.registerEndpoint(endpoint, factory);
}
 
Example 24
Source Project: flowable-engine   Source File: JmsChannelModelProcessor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Register a new {@link JmsListenerEndpoint} alongside the
 * {@link JmsListenerContainerFactory} to use to create the underlying container.
 * <p>The {@code factory} may be {@code null} if the default factory has to be
 * used for that endpoint.
 */
protected void registerEndpoint(JmsListenerEndpoint endpoint, JmsListenerContainerFactory<?> factory) {
    Assert.notNull(endpoint, "Endpoint must not be null");
    Assert.hasText(endpoint.getId(), "Endpoint id must be set");

    Assert.state(this.endpointRegistry != null, "No JmsListenerEndpointRegistry set");
    endpointRegistry.registerListenerContainer(endpoint, resolveContainerFactory(endpoint, factory), true);
}
 
Example 25
Source Project: POC   Source File: JMSApplicationConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public JmsListenerContainerFactory<?> myFactory(ConnectionFactory connectionFactory,
		DefaultJmsListenerContainerFactoryConfigurer configurer) {
	final DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
	// This provides all boot's default to this factory, including the message
	// converter
	configurer.configure(factory, connectionFactory);
	// You could still override some of Boot's default if necessary.
	return factory;
}
 
Example 26
Source Project: java-specialagent   Source File: SpringJMSITest.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public JmsListenerContainerFactory<?> myFactory(final DefaultJmsListenerContainerFactoryConfigurer configurer) {
  final DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
  configurer.configure(factory, connectionFactory());
  return factory;
}
 
Example 27
Source Project: piper   Source File: JmsMessageBrokerConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public JmsListenerContainerFactory<?> jmsListenerContainerFactory(ConnectionFactory connectionFactory, DefaultJmsListenerContainerFactoryConfigurer configurer) {
  DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
  configurer.configure(factory, connectionFactory);
  return factory;
}
 
Example 28
Source Project: flowable-engine   Source File: JmsChannelModelProcessor.java    License: Apache License 2.0 4 votes vote down vote up
public JmsListenerContainerFactory<?> getContainerFactory() {
    return containerFactory;
}
 
Example 29
Source Project: flowable-engine   Source File: JmsChannelModelProcessor.java    License: Apache License 2.0 4 votes vote down vote up
public void setContainerFactory(JmsListenerContainerFactory<?> containerFactory) {
    this.containerFactory = containerFactory;
}