Spring boot 在Springboot microservices api中,如何使用AMQP队列调用另一台服务器,从另一个服务队列获取响应,发送响应

Spring boot 在Springboot microservices api中,如何使用AMQP队列调用另一台服务器,从另一个服务队列获取响应,发送响应,spring-boot,microservices,message-queue,spring-jms,spring-amqp,Spring Boot,Microservices,Message Queue,Spring Jms,Spring Amqp,我们正在编写微服务平台。我们有一个用spring boot编写的服务器,它向外界公开API 我们有另一个spring boot微服务B,它需要从A调用 示例: 我们在服务A中有一个端点/createOrder 当我们调用它时,A的控制器被调用,需要使用AMQP JMS集成向服务器B发送消息,B接收队列进程控制器,将消息发送回服务器A,以便可以向/create order的API请求发送响应 ---->/createorder-->服务器-->A向B的服务器发送消息队列-->B服务器处理它-->向

我们正在编写微服务平台。我们有一个用spring boot编写的服务器,它向外界公开API

我们有另一个spring boot微服务B,它需要从A调用

示例:

我们在服务A中有一个端点/createOrder

当我们调用它时,A的控制器被调用,需要使用AMQP JMS集成向服务器B发送消息,B接收队列进程控制器,将消息发送回服务器A,以便可以向/create order的API请求发送响应

---->/createorder-->服务器-->A向B的服务器发送消息队列-->B服务器处理它-->向A发送消息-->A响应请求


在此过程中,如何在服务器A中保存请求并等待服务器B的响应听起来您需要熟悉它的实现。有一种类似网关的模式,该框架为JMS出站请求/回复提供了一个实现:

另一方面,Spring AMQP不支持AMQP1.0协议,这更可能由常规JMS API处理

Spring JMS的
JmsTemplate
还为我们提供了一个API,如:

/**
 * Send a message and receive the reply from the specified destination. The
 * {@link MessageCreator} callback creates the message given a Session. A temporary
 * queue is created as part of this operation and is set in the {@code JMSReplyTO}
 * header of the message.
 * @param destinationName the name of the destination to send this message to
 * (to be resolved to an actual destination by a DestinationResolver)
 * @param messageCreator callback to create a message
 * @return the reply, possibly {@code null} if the message could not be received,
 * for example due to a timeout
 * @throws JmsException checked JMSException converted to unchecked
 * @since 4.1
 */
@Nullable
Message sendAndReceive(String destinationName, MessageCreator messageCreator) throws JmsException;
<> P>所以,如果Spring积分太难,不能马上带到你的项目中,你也可以考虑使用这个。
如果您混淆了AMQP 0.9和JMS,那么您真的可以继续使用Spring AMQP项目及其
rabbitmplate.sendAndReceive()
听起来您需要熟悉它的实现。有一种类似网关的模式,该框架为JMS出站请求/回复提供了一个实现:

另一方面,Spring AMQP不支持AMQP1.0协议,这更可能由常规JMS API处理

Spring JMS的
JmsTemplate
还为我们提供了一个API,如:

/**
 * Send a message and receive the reply from the specified destination. The
 * {@link MessageCreator} callback creates the message given a Session. A temporary
 * queue is created as part of this operation and is set in the {@code JMSReplyTO}
 * header of the message.
 * @param destinationName the name of the destination to send this message to
 * (to be resolved to an actual destination by a DestinationResolver)
 * @param messageCreator callback to create a message
 * @return the reply, possibly {@code null} if the message could not be received,
 * for example due to a timeout
 * @throws JmsException checked JMSException converted to unchecked
 * @since 4.1
 */
@Nullable
Message sendAndReceive(String destinationName, MessageCreator messageCreator) throws JmsException;
<> P>所以,如果Spring积分太难,不能马上带到你的项目中,你也可以考虑使用这个。
如果您将AMQP 0.9与JMS混淆,那么您确实可以继续使用Spring AMQP项目及其
rabbitmplate.sendAndReceive()
来等待响应,您可以尝试使用async rabbit。下面是来自baeldung的教程:

要等待响应,您可以尝试使用async rabbit。这里有一个来自贝尔东的教程: