org.springframework.amqp.rabbit.AsyncRabbitTemplate Java Examples

The following examples show how to use org.springframework.amqp.rabbit.AsyncRabbitTemplate. 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: 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 #2
Source File: PaymentRequesterService.java    From Spring-5.0-By-Example with MIT License 5 votes vote down vote up
public PaymentRequesterService(@Value("${amqp.payments.exchange.payment}") String paymentExchange,
    @Value("${amqp.payments.key.request}") String requestPaymentKey,
    AsyncRabbitTemplate asyncRabbitTemplate) {
  this.paymentExchange = paymentExchange;
  this.requestPaymentKey = requestPaymentKey;
  this.asyncRabbitTemplate = asyncRabbitTemplate;
}
 
Example #3
Source File: PaymentResponseService.java    From Spring-5.0-By-Example with MIT License 5 votes vote down vote up
public PaymentResponseService(@Value("${amqp.payments.exchange.payment}") String paymentExchange,
                               @Value("${amqp.payments.key.response}") String responsePaymentKey,
                               AsyncRabbitTemplate asyncRabbitTemplate) {
  this.paymentExchange = paymentExchange;
  this.responsePaymentKey = responsePaymentKey;
  this.asyncRabbitTemplate = asyncRabbitTemplate;
}
 
Example #4
Source File: RabbitConfig.java    From SpringBootBucket with MIT License 4 votes vote down vote up
@Bean
public AsyncRabbitTemplate asyncRabbitTemplate(RabbitTemplate template, SimpleMessageListenerContainer container) {
    return new AsyncRabbitTemplate(template, container);
}
 
Example #5
Source File: RabbitConfig.java    From SpringBootBucket with MIT License 4 votes vote down vote up
@Bean
public AsyncRabbitTemplate asyncRabbitTemplate(RabbitTemplate template, SimpleMessageListenerContainer container) {
    return new AsyncRabbitTemplate(template, container);
}
 
Example #6
Source File: SendAsyncEventLogin.java    From Spring-5.0-Cookbook with MIT License 4 votes vote down vote up
public SendAsyncEventLogin(Queue requestQueue, AsyncRabbitTemplate rabbitTemplate) {
	this.asyncRabbitTemplate = rabbitTemplate;
	//this.asyncRabbitTemplate.setReceiveTimeout(1000);
	this.requestQueue = requestQueue;
}
 
Example #7
Source File: SendAsyncLogin.java    From Spring-5.0-Cookbook with MIT License 4 votes vote down vote up
public SendAsyncLogin(AsyncRabbitTemplate rabbitTemplate) {
	this.asyncRabbitTemplate = rabbitTemplate;
  //this.asyncRabbitTemplate.setReceiveTimeout(1000);
}
 
Example #8
Source File: RabbitMQConfiguration.java    From Spring-5.0-By-Example with MIT License 4 votes vote down vote up
@Bean
public AsyncRabbitTemplate asyncRabbitTemplate(RabbitTemplate rabbitTemplate){
  return new AsyncRabbitTemplate(rabbitTemplate);
}
 
Example #9
Source File: RabbitMQConfiguration.java    From Spring-5.0-By-Example with MIT License 4 votes vote down vote up
@Bean
public AsyncRabbitTemplate asyncRabbitTemplate(RabbitTemplate rabbitTemplate){
  return new AsyncRabbitTemplate(rabbitTemplate);
}