Java源码示例:org.springframework.amqp.rabbit.AsyncRabbitTemplate
示例1
@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();
}
}
}
示例2
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;
}
示例3
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;
}
示例4
@Bean
public AsyncRabbitTemplate asyncRabbitTemplate(RabbitTemplate template, SimpleMessageListenerContainer container) {
return new AsyncRabbitTemplate(template, container);
}
示例5
@Bean
public AsyncRabbitTemplate asyncRabbitTemplate(RabbitTemplate template, SimpleMessageListenerContainer container) {
return new AsyncRabbitTemplate(template, container);
}
示例6
public SendAsyncEventLogin(Queue requestQueue, AsyncRabbitTemplate rabbitTemplate) {
this.asyncRabbitTemplate = rabbitTemplate;
//this.asyncRabbitTemplate.setReceiveTimeout(1000);
this.requestQueue = requestQueue;
}
示例7
public SendAsyncLogin(AsyncRabbitTemplate rabbitTemplate) {
this.asyncRabbitTemplate = rabbitTemplate;
//this.asyncRabbitTemplate.setReceiveTimeout(1000);
}
示例8
@Bean
public AsyncRabbitTemplate asyncRabbitTemplate(RabbitTemplate rabbitTemplate){
return new AsyncRabbitTemplate(rabbitTemplate);
}
示例9
@Bean
public AsyncRabbitTemplate asyncRabbitTemplate(RabbitTemplate rabbitTemplate){
return new AsyncRabbitTemplate(rabbitTemplate);
}