RabbitMQ中的RPC实现
Posted dairongsheng
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RabbitMQ中的RPC实现相关的知识,希望对你有一定的参考价值。
1、先上例子:
pom依赖:
<dependencies>
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>4.6.0</version>
</dependency>
</dependencies>
1 DefaultConsumer c = new DefaultConsumer(channel) { 2 @Override 3 public void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body) 4 throws IOException { 5 System.out.println(new String(body)); 6 7 AMQP.BasicProperties.Builder builder = new AMQP.BasicProperties.Builder(); 8 builder.correlationId(properties.getCorrelationId()); 9 AMQP.BasicProperties prop = builder.build(); 10 11 channel.basicPublish("", properties.getReplyTo(), prop, (new String(body) + "-回复").getBytes()); 12 13 } 14 };
<dependencies> <dependency> <groupId>com.rabbitmq</groupId> <artifactId>amqp-client</artifactId> <version>4.6.0</version> </dependency> </dependencies>
以上是关于RabbitMQ中的RPC实现的主要内容,如果未能解决你的问题,请参考以下文章