Java Code Examples for org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory

The following examples show how to use org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory. 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
Source Project: ChengFeng1.5   Source File: RabbitmqConfig.java    License: MIT License 5 votes vote down vote up
@Bean
    public RabbitListenerContainerFactory<?> rabbitListenerContainerFactory(){
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory());
//        factory.setMessageConverter(new Jackson2JsonMessageConverter());
        factory.setAcknowledgeMode(AcknowledgeMode.MANUAL);
        return factory;
    }
 
Example 2
Source Project: common-project   Source File: BaseConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 配置接收消息的MessageConverter
 *
 * @param connectionFactory 连接工厂
 * @return
 */
@Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(ConnectionFactory connectionFactory) {
    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
    factory.setConnectionFactory(connectionFactory);
    factory.setPrefetchCount(50);
    factory.setConcurrentConsumers(5);
    factory.setMessageConverter(new ProtobufMessageConverter());
    factory.setAcknowledgeMode(AcknowledgeMode.AUTO);
    return factory;
}
 
Example 3
@Bean
@ConditionalOnMissingBean(name = "rabbitListenerContainerFactory")
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(
    SimpleRabbitListenerContainerFactoryConfigurer configurer, ConnectionFactory connectionFactory) {
    SimpleRabbitListenerContainerFactoryExtend factory = new SimpleRabbitListenerContainerFactoryExtend();
    configurer.configure(factory, connectionFactory);
    return factory;
}
 
Example 4
Source Project: java-specialagent   Source File: SpringRabbitMQTest.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory() {
  final SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
  factory.setConnectionFactory(connectionFactory());
  factory.setConcurrentConsumers(3);
  factory.setMaxConcurrentConsumers(10);
  return factory;
}
 
Example 5
@Bean
public SimpleRabbitListenerContainerFactory listenerContainer() {
	SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
	factory.setConnectionFactory(connectionFactory());
	factory.setMaxConcurrentConsumers(5);
	return factory;
}
 
Example 6
Source Project: iot-dc3   Source File: TopicRabbitConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public RabbitListenerContainerFactory<?> rabbitListenerContainerFactory(ConnectionFactory connectionFactory) {
    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
    factory.setConnectionFactory(connectionFactory);
    factory.setMessageConverter(new Jackson2JsonMessageConverter());
    return factory;
}
 
Example 7
Source Project: iot-dc3   Source File: RabbitConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public RabbitListenerContainerFactory<?> rabbitListenerContainerFactory(ConnectionFactory connectionFactory) {
    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
    factory.setConnectionFactory(connectionFactory);
    factory.setMessageConverter(new Jackson2JsonMessageConverter());
    return factory;
}
 
Example 8
Source Project: iot-dc3   Source File: TopicRabbitConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public RabbitListenerContainerFactory<?> rabbitListenerContainerFactory(ConnectionFactory connectionFactory) {
    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
    factory.setConnectionFactory(connectionFactory);
    factory.setMessageConverter(new Jackson2JsonMessageConverter());
    return factory;
}
 
Example 9
Source Project: seed   Source File: RabbitMQConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public SimpleRabbitListenerContainerFactory jadyerRabbitListenerContainerFactory(ConnectionFactory connectionFactory){
    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
    factory.setConnectionFactory(connectionFactory);
    factory.setMessageConverter(new Jackson2JsonMessageConverter());
    return factory;
}
 
Example 10
Source Project: myth   Source File: AmqpConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * My container factory simple rabbit listener container factory.
 *
 * @param configurer        the configurer
 * @param connectionFactory the connection factory
 * @return the simple rabbit listener container factory
 */
@Bean
@ConditionalOnProperty(prefix = "spring.rabbitmq", name = "host")
public SimpleRabbitListenerContainerFactory myContainerFactory(
        SimpleRabbitListenerContainerFactoryConfigurer configurer,
        ConnectionFactory connectionFactory) {
    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
    factory.setPrefetchCount(100);
    configurer.configure(factory, connectionFactory);
    return factory;
}
 
Example 11
Source Project: myth   Source File: AmqpConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnProperty(prefix = "spring.rabbitmq", name = "host")
public SimpleRabbitListenerContainerFactory myContainerFactory(
        SimpleRabbitListenerContainerFactoryConfigurer configurer,
        ConnectionFactory connectionFactory) {
    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
    factory.setPrefetchCount(100);
    configurer.configure(factory, connectionFactory);
    return factory;
}
 
Example 12
Source Project: myth   Source File: AmqpConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * My container factory simple rabbit listener container factory.
 *
 * @param configurer        the configurer
 * @param connectionFactory the connection factory
 * @return the simple rabbit listener container factory
 */
@Bean
@ConditionalOnProperty(prefix = "spring.rabbitmq", name = "host")
public SimpleRabbitListenerContainerFactory myContainerFactory(
        SimpleRabbitListenerContainerFactoryConfigurer configurer,
        ConnectionFactory connectionFactory) {
    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
    factory.setPrefetchCount(100);
    configurer.configure(factory, connectionFactory);
    return factory;
}
 
Example 13
@Bean
public RabbitListenerContainerFactory<SimpleMessageListenerContainer> rabbitListenerContainerFactory() {
    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
    factory.setConnectionFactory(connectionFactory());
    factory.setDefaultRequeueRejected(false);
    factory.setMessageConverter(messageConverter());
    return factory;
}
 
Example 14
Source Project: konker-platform   Source File: RabbitMQRouterConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(ConnectionFactory connectionFactory) {
    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
    factory.setConnectionFactory(connectionFactory);
    factory.setAcknowledgeMode(AcknowledgeMode.AUTO);
    factory.setConcurrentConsumers(1);
    factory.setMaxConcurrentConsumers(20);

    Advice[] adviceChain = new Advice[] { interceptor() };
    factory.setAdviceChain(adviceChain);
    return factory;
}
 
Example 15
Source Project: piper   Source File: AmqpMessageBrokerConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
private SimpleRabbitListenerContainerFactory createContainerFactory (int aConcurrency) {
  SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
  factory.setConcurrentConsumers(aConcurrency);
  factory.setConnectionFactory(connectionFactory);
  factory.setDefaultRequeueRejected(false);
  factory.setMessageConverter(jacksonAmqpMessageConverter(objectMapper));
  factory.setPrefetchCount(rabbit.getListener().getDirect().getPrefetch());
  return factory;
}
 
Example 16
@Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(ConnectionFactory connectionFactory) {
    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
    factory.setConnectionFactory(connectionFactory);
    factory.setMessageConverter(new Jackson2JsonMessageConverter());
    return factory;
}
 
Example 17
@Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(ConnectionFactory connectionFactory) {
    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
    factory.setConnectionFactory(connectionFactory);
    factory.setMessageConverter(new Jackson2JsonMessageConverter());
    return factory;
}
 
Example 18
@Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(
		ConnectionFactory connectionFactory, MessageConverter messageConverter) {
	SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
	factory.setConnectionFactory(connectionFactory);
	factory.setConcurrentConsumers(3);
	factory.setMaxConcurrentConsumers(10);
	factory.setMessageConverter(messageConverter);
	return factory;
}
 
Example 19
@Bean(name = "rabbitListenerContainerFactory")
public SimpleRabbitListenerContainerFactory simpleRabbitListenerContainerFactory(ConnectionFactory connectionFactory) {
    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();

    factory.setConnectionFactory(connectionFactory);
    return factory;
}
 
Example 20
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName)
		throws BeansException {
	if (bean instanceof RabbitTemplate) {
		return rabbitTracing().decorateRabbitTemplate((RabbitTemplate) bean);
	}
	else if (bean instanceof SimpleRabbitListenerContainerFactory) {
		return rabbitTracing().decorateSimpleRabbitListenerContainerFactory(
				(SimpleRabbitListenerContainerFactory) bean);
	}
	return bean;
}
 
Example 21
Source Project: cukes   Source File: RabbitMQConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(org.springframework.amqp.rabbit.connection.ConnectionFactory  cf,
                                                                    ObjectMapper mapper) {
    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
    factory.setConnectionFactory(cf);
    factory.setMessageConverter(new Jackson2JsonMessageConverter(mapper));
    return factory;
}
 
Example 22
Source Project: tutorials   Source File: RabbitConfiguration.java    License: MIT License 5 votes vote down vote up
@Bean
public SimpleRabbitListenerContainerFactory defaultContainerFactory(ConnectionFactory connectionFactory) {
    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
    factory.setConnectionFactory(connectionFactory);

    return factory;
}
 
Example 23
Source Project: tutorials   Source File: RabbitConfiguration.java    License: MIT License 5 votes vote down vote up
@Bean
public SimpleRabbitListenerContainerFactory retryContainerFactory(ConnectionFactory connectionFactory, RetryOperationsInterceptor retryInterceptor) {
    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
    factory.setConnectionFactory(connectionFactory);

    Advice[] adviceChain = { retryInterceptor };
    factory.setAdviceChain(adviceChain);

    return factory;
}
 
Example 24
Source Project: tutorials   Source File: RabbitConfiguration.java    License: MIT License 5 votes vote down vote up
@Bean
public SimpleRabbitListenerContainerFactory retryQueuesContainerFactory(ConnectionFactory connectionFactory, RetryQueuesInterceptor retryInterceptor) {
    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
    factory.setConnectionFactory(connectionFactory);

    Advice[] adviceChain = { retryInterceptor };
    factory.setAdviceChain(adviceChain);

    return factory;
}
 
Example 25
@Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(
  ConnectionFactory connectionFactory,
  SimpleRabbitListenerContainerFactoryConfigurer configurer) {
    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
    configurer.configure(factory, connectionFactory);
    factory.setErrorHandler(errorHandler());
    return factory;
}
 
Example 26
Source Project: tutorials   Source File: ListenerErrorHandlerAmqpConfiguration.java    License: MIT License 5 votes vote down vote up
@Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(ConnectionFactory connectionFactory,
                                                                           SimpleRabbitListenerContainerFactoryConfigurer configurer) {
    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
    configurer.configure(factory, connectionFactory);
    factory.setErrorHandler(errorHandler());
    return factory;
}
 
Example 27
Source Project: brave   Source File: SpringRabbitTracing.java    License: Apache License 2.0 5 votes vote down vote up
/** Creates an instrumented {@linkplain SimpleRabbitListenerContainerFactory} */
public SimpleRabbitListenerContainerFactory newSimpleRabbitListenerContainerFactory(
  ConnectionFactory connectionFactory
) {
  SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
  factory.setConnectionFactory(connectionFactory);
  factory.setAdviceChain(new TracingRabbitListenerAdvice(this));
  return factory;
}
 
Example 28
Source Project: brave   Source File: SpringRabbitTracing.java    License: Apache License 2.0 5 votes vote down vote up
/** Instruments an existing {@linkplain SimpleRabbitListenerContainerFactory} */
public SimpleRabbitListenerContainerFactory decorateSimpleRabbitListenerContainerFactory(
  SimpleRabbitListenerContainerFactory factory
) {
  Advice[] chain = factory.getAdviceChain();

  TracingRabbitListenerAdvice tracingAdvice = new TracingRabbitListenerAdvice(this);
  // If there are no existing advice, return only the tracing one
  if (chain == null) {
    factory.setAdviceChain(tracingAdvice);
    return factory;
  }

  // If there is an existing tracing advice return
  for (Advice advice : chain) {
    if (advice instanceof TracingRabbitListenerAdvice) {
      return factory;
    }
  }

  // Otherwise, add ours and return
  Advice[] newChain = new Advice[chain.length + 1];
  newChain[0] = tracingAdvice;
  System.arraycopy(chain, 0, newChain, 1, chain.length);
  factory.setAdviceChain(newChain);
  return factory;
}
 
Example 29
Source Project: brave   Source File: SpringRabbitTracingTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test public void decorateSimpleRabbitListenerContainerFactory_skips_when_present() {
  SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
  factory.setAdviceChain(new TracingRabbitListenerAdvice(rabbitTracing));

  assertThat(rabbitTracing.decorateSimpleRabbitListenerContainerFactory(factory).getAdviceChain())
    .hasSize(1);
}
 
Example 30
Source Project: brave   Source File: SpringRabbitTracingTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test public void decorateSimpleRabbitListenerContainerFactory_appends_as_first_when_absent() {
  SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
  factory.setAdviceChain(new CacheInterceptor());

  // the order of advices is important for the downstream interceptor to see the tracing context
  assertThat(rabbitTracing.decorateSimpleRabbitListenerContainerFactory(factory).getAdviceChain())
    .hasSize(2)
    .matches(adviceArray -> adviceArray[0] instanceof TracingRabbitListenerAdvice);
}