Java Code Examples for org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#setConnectionFactory()
The following examples show how to use
org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#setConnectionFactory() .
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: SzzRestApplication.java From OpenSZZ-Cloud-Native with GNU General Public License v3.0 | 5 votes |
@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 2
Source File: SzzRestApplication.java From OpenSZZ-Cloud-Native with GNU General Public License v3.0 | 5 votes |
@Bean SimpleMessageListenerContainer containerAnaylsis(ConnectionFactory connectionFactory) { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setConnectionFactory(connectionFactory()); container.setQueueNames(queueNameSzz); container.setMessageListener(new MessageReceivedComponent(rabbitTemplate(connectionFactory()))); return container; }
Example 3
Source File: SpringIntegrationTest.java From rabbitmq-mock with Apache License 2.0 | 5 votes |
@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 4
Source File: SpringIntegrationTest.java From rabbitmq-mock with Apache License 2.0 | 5 votes |
@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 5
Source File: RabbitConfig.java From cloud-espm-cloud-native with Apache License 2.0 | 5 votes |
/** * @param rabbitConnectionFactory * @return SimpleMessageListenerContainer */ @Primary public SimpleMessageListenerContainer rabbitListener(ConnectionFactory rabbitConnectionFactory) { SimpleMessageListenerContainer factory = new SimpleMessageListenerContainer(); factory.setConnectionFactory(rabbitConnectionFactory); factory.setPrefetchCount(prefetchCount); factory.setAcknowledgeMode(AcknowledgeMode.MANUAL); factory.setConcurrentConsumers(consumerCount); return factory; }
Example 6
Source File: Issue178ListenerConfiguration.java From spring-cloud-contract with Apache License 2.0 | 5 votes |
@Bean SimpleMessageListenerContainer messageListenerContainer( ConnectionFactory connectionFactory, RabbitTemplate rabbitTemplate) { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setConnectionFactory(connectionFactory); container.addQueueNames("rated-item-service.rated-item-event.exchange"); container.setMessageListener(exampleListener(rabbitTemplate)); return container; }
Example 7
Source File: AmqpMessagingApplication.java From spring-cloud-contract with Apache License 2.0 | 5 votes |
@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 8
Source File: AmqpConfig.java From demo_springboot_rabbitmq with Apache License 2.0 | 5 votes |
@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 9
Source File: EMSConfiguration.java From generic-vnfm with Apache License 2.0 | 5 votes |
@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 10
Source File: ScrapingResultConsumerConfiguration.java From scraping-microservice-java-python-rabbitmq with Apache License 2.0 | 5 votes |
@Bean public SimpleMessageListenerContainer listenerContainer() { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setConnectionFactory(connectionFactory()); container.setQueueNames(this.scrapingResultQueue); container.setMessageListener(messageListenerAdapter()); return container; }
Example 11
Source File: ExceptionQueueContextConfig.java From sinavi-jfw with Apache License 2.0 | 5 votes |
/** * {@link SimpleMessageListenerContainer}のインスタンスを生成します。 * このインスタンスを生成後にRabbitMQへのコネクション{@link #factory()}の設定や * メッセージ受信側での例外ハンドラ{@link #errorHandler()}の設定、 * リトライ処理{@link #advice()}の設定を行います。 * @return {@link SimpleMessageListenerContainer}のインスタンス */ protected SimpleMessageListenerContainer messageListenerContainer() { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setConnectionFactory(factory()); container.setErrorHandler(errorHandler()); container.setAdviceChain(advice()); return container; }
Example 12
Source File: MessageListenerRetryTest.java From sinavi-jfw with Apache License 2.0 | 5 votes |
private SimpleMessageListenerContainer container() { SimpleMessageListenerContainer c = new SimpleMessageListenerContainer(ctx.getBean(ConnectionFactory.class)); c.setConnectionFactory(ctx.getBean(ConnectionFactory.class)); c.setErrorHandler(ctx.getBean(ErrorHandler.class)); c.setAdviceChain(ctx.getBean(Advice[].class)); return c; }
Example 13
Source File: MessageListenerConfig_Pre_1_4_0.java From pinpoint with Apache License 2.0 | 5 votes |
@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; }