Java Code Examples for org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#setQueueNames()

The following examples show how to use org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#setQueueNames() . 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 File: RabbitAutoConfiguration.java    From easy-rabbitmq with Apache License 2.0 5 votes vote down vote up
@Bean
public SimpleMessageListenerContainer simpleMessageListenerContainer(MessageConverter converter,
    ConnectionFactory connectionFactory, @Autowired(required = false) List<Consumer<?>> list) {
  SimpleMessageListenerContainer container =
      new SimpleMessageListenerContainer(connectionFactory);
  init(list);
  Receiver receiver = new Receiver(converter);
  container.setMessageListener(new MessageListenerAdapter(receiver, converter));
  container.setQueueNames(queueNames.toArray(new String[0]));
  container.setAcknowledgeMode(AcknowledgeMode.MANUAL);
  container.setPrefetchCount(prefetchCount);
  container.setTxSize(txSize);
  return container;
}
 
Example 2
Source File: MessageListenerConfig_Pre_1_4_0.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Bean
public SimpleMessageListenerContainer listenerContainer(ConnectionFactory connectionFactory, TestMessageHandler testMessageHandler) {
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    container.setConnectionFactory(connectionFactory);
    container.setQueueNames(RabbitMQTestConstants.QUEUE_PUSH);
    container.setMessageListener(new MessageListenerAdapter(testMessageHandler));
    return container;
}
 
Example 3
Source File: ScrapingResultConsumerConfiguration.java    From scraping-microservice-java-python-rabbitmq with Apache License 2.0 5 votes vote down vote up
@Bean
public SimpleMessageListenerContainer listenerContainer() {
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	container.setConnectionFactory(connectionFactory());
	container.setQueueNames(this.scrapingResultQueue);
	container.setMessageListener(messageListenerAdapter());

	return container;
}
 
Example 4
Source File: EMSConfiguration.java    From generic-vnfm with Apache License 2.0 5 votes vote down vote up
@Bean
SimpleMessageListenerContainer container_emsRegistrator() {
  if (listenerAdapter_emsRegistrator != null) {
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    container.setConnectionFactory(emsConnectionFactory);
    container.setQueueNames(queueName_emsRegistrator);
    container.setMessageListener(listenerAdapter_emsRegistrator);
    return container;
  } else return null;
}
 
Example 5
Source File: AmqpConfig.java    From demo_springboot_rabbitmq with Apache License 2.0 5 votes vote down vote up
@Bean
public SimpleMessageListenerContainer messageListenerContainer(MessageListenerAdapter listenerAdapter) {
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    container.setConnectionFactory(connectionFactory());
    container.setQueueNames(AmqpConfig.QUEUE_NAME);
    container.setExposeListenerChannel(true);
    container.setMaxConcurrentConsumers(1);
    container.setConcurrentConsumers(1);
    container.setAcknowledgeMode(AcknowledgeMode.MANUAL); //设置确认模式手工确认
    container.setMessageListener(listenerAdapter);
    return container;
}
 
Example 6
Source File: AmqpMessagingApplication.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Bean
public SimpleMessageListenerContainer simpleMessageListenerContainer(
		ConnectionFactory connectionFactory,
		MessageListenerAdapter listenerAdapter) {
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	container.setConnectionFactory(connectionFactory);
	container.setQueueNames("test.queue");
	container.setMessageListener(listenerAdapter);

	return container;
}
 
Example 7
Source File: BusConfig.java    From SpringCloud with Apache License 2.0 5 votes vote down vote up
@Bean
SimpleMessageListenerContainer simpleMessageListenerContainer(ConnectionFactory connectionFactory, MessageListenerAdapter messageListenerAdapter, Queue queue) {
    log.info("init simpleMessageListenerContainer: {}", queue.getName());
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
    container.setQueueNames(queue.getName());
    container.setMessageListener(messageListenerAdapter);
    return container;
}
 
Example 8
Source File: BusConfig.java    From SpringCloud with Apache License 2.0 5 votes vote down vote up
@Bean
SimpleMessageListenerContainer simpleMessageListenerContainer(ConnectionFactory connectionFactory, MessageListenerAdapter messageListenerAdapter, Queue queue) {
    log.info("init simpleMessageListenerContainer {}", queue.getName());
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
    container.setQueueNames(queue.getName());
    container.setMessageListener(messageListenerAdapter);
    return container;
}
 
Example 9
Source File: BusConfig.java    From SpringCloud with Apache License 2.0 5 votes vote down vote up
@Bean
SimpleMessageListenerContainer mqContainer(ConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {
    log.info("init mqContainer");
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
    container.setQueueNames(QUEUE_NAME);
    container.setMessageListener(listenerAdapter);
    return container;
}
 
Example 10
Source File: BusConfig.java    From JetfireCloud with Apache License 2.0 5 votes vote down vote up
@Bean
SimpleMessageListenerContainer mqContainer(ConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {
    log.info("init mqContainer");
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
    container.setQueueNames(QUEUE_NAME);
    container.setMessageListener(listenerAdapter);
    return container;
}
 
Example 11
Source File: RabbitConfig.java    From SpringBootBucket with MIT License 5 votes vote down vote up
@Bean
@Primary
public SimpleMessageListenerContainer replyContainer(ConnectionFactory connectionFactory) {
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
    container.setQueueNames(repliesQueue().getName());
    return container;
}
 
Example 12
Source File: RabbitConfig.java    From SpringBootBucket with MIT License 5 votes vote down vote up
@Bean
@Primary
public SimpleMessageListenerContainer replyContainer(ConnectionFactory connectionFactory) {
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
    container.setQueueNames(repliesQueue().getName());
    return container;
}
 
Example 13
Source File: RabbitConfig.java    From notes with Apache License 2.0 5 votes vote down vote up
/**
     * 创建制定的 监听容器
     *
     * @param queueName  监听的队列名字
     * @param listenerChannel 设置是否将监听的频道 公开给已注册的
     * @param PrefetchCount  告诉代理一次请求多少条消息过来
     * @param ConcurrentConsumers  制定创建多少个并发的消费者数量
     * @param acknowledgeMode  消息确认模式
     * @param listener 监听器
     * @return org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer
     * @author fruiqi
     * @date 19-2-11 下午4:13
     **/
    public SimpleMessageListenerContainer setSimpleMessageListenerContainer(String queueName, boolean listenerChannel,
                                                                            int PrefetchCount, int ConcurrentConsumers,
                                                                            AcknowledgeMode acknowledgeMode,
                                                                            ChannelAwareMessageListener listener) throws Exception {
        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(getConnection());
//        container.setQueueNames(getMACAddressRrefix(queueName));
        container.setQueueNames(queueName);
        container.setExposeListenerChannel(listenerChannel);
        container.setPrefetchCount(PrefetchCount);
        container.setConcurrentConsumers(ConcurrentConsumers);
        container.setAcknowledgeMode(acknowledgeMode);
        container.setMessageListener(listener);
        return container;
    }
 
Example 14
Source File: SpringIntegrationTest.java    From rabbitmq-mock with Apache License 2.0 5 votes vote down vote up
@Test
void reply_direct_to() throws ExecutionException, InterruptedException {
    String messageBody = "Hello world!";
    try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AmqpConfiguration.class)) {
        RabbitTemplate rabbitTemplate = queueAndExchangeSetup(context);

        // using AsyncRabbitTemplate to avoid automatic fallback to temporary queue 
        AsyncRabbitTemplate asyncRabbitTemplate = new AsyncRabbitTemplate(rabbitTemplate);
        
        Receiver receiver = new Receiver();
        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
        container.setConnectionFactory(context.getBean(ConnectionFactory.class));
        container.setQueueNames(QUEUE_NAME);
        container.setMessageListener(new MessageListenerAdapter(receiver, "receiveMessageAndReply"));
        try {
            container.start();
            asyncRabbitTemplate.start();

            AsyncRabbitTemplate.RabbitConverterFuture<Object> result = asyncRabbitTemplate.convertSendAndReceive(EXCHANGE_NAME, "test.key2", messageBody);
            
            assertThat(result.get()).isEqualTo(new StringBuilder(messageBody).reverse().toString());
            assertThat(receiver.getMessages()).containsExactly(messageBody);
        } finally {
            container.stop();
            asyncRabbitTemplate.stop();
        }
    }
}
 
Example 15
Source File: SpringIntegrationTest.java    From rabbitmq-mock with Apache License 2.0 5 votes vote down vote up
@Test
void basic_consume_case() {
    String messageBody = "Hello world!";
    try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AmqpConfiguration.class)) {
        RabbitTemplate rabbitTemplate = queueAndExchangeSetup(context);

        Receiver receiver = new Receiver();
        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
        container.setConnectionFactory(context.getBean(ConnectionFactory.class));
        container.setQueueNames(QUEUE_NAME);
        container.setMessageListener(new MessageListenerAdapter(receiver, "receiveMessage"));
        try {
            container.start();

            rabbitTemplate.convertAndSend(EXCHANGE_NAME, "test.key2", messageBody);

            List<String> receivedMessages = new ArrayList<>();
            assertTimeoutPreemptively(ofMillis(500L), () -> {
                    while (receivedMessages.isEmpty()) {
                        receivedMessages.addAll(receiver.getMessages());
                        TimeUnit.MILLISECONDS.sleep(100L);
                    }
                }
            );

            assertThat(receivedMessages).containsExactly(messageBody);
        } finally {
            container.stop();
        }
    }
}
 
Example 16
Source File: SzzRestApplication.java    From OpenSZZ-Cloud-Native with GNU General Public License v3.0 5 votes vote down vote up
@Bean
SimpleMessageListenerContainer containerAnaylsis(ConnectionFactory connectionFactory) {
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    container.setConnectionFactory(connectionFactory());
    container.setQueueNames(queueNameSzz);
    container.setMessageListener(new MessageReceivedComponent(rabbitTemplate(connectionFactory())));
    return container;
}
 
Example 17
Source File: SzzRestApplication.java    From OpenSZZ-Cloud-Native with GNU General Public License v3.0 5 votes vote down vote up
@Bean
SimpleMessageListenerContainer containerAnaylsis(ConnectionFactory connectionFactory) {
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	container.setConnectionFactory(connectionFactory());
	container.setQueueNames(queueNameSzz);
	container.setMessageListener(new MessageReceivedComponent(rabbitTemplate(connectionFactory()), dbEntryDao));
	return container;
}
 
Example 18
Source File: AmqpServer.java    From tutorials with MIT License 4 votes vote down vote up
@Bean SimpleMessageListenerContainer listener(ConnectionFactory factory, AmqpInvokerServiceExporter exporter, Queue queue) {
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(factory);
    container.setMessageListener(exporter);
    container.setQueueNames(queue.getName());
    return container;
}
 
Example 19
Source File: RabbitMQConfigAsync.java    From Spring-5.0-Cookbook with MIT License 4 votes vote down vote up
@Bean
public SimpleMessageListenerContainer simpleMessageListenerContainer() {
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(rabbitConnectionFactory);
	container.setQueueNames("msg.reply");
	return container;
}