在春季启动微服务API,使用AMQP队列如何调用另一台服务器,请从其他业务队列响应,发送响应

问题描述 投票:0回答:2

我们正在写的微服务平台。我们已经写在春季启动其API暴露给外界的服务器。

我们有哪些需要从A.称为又一个春天启动的microService乙

例:

我们有在服务A.端点/ createOrder

当我们调用此,A的控制器被调用,需要发送使用AMQP JMS集成的消息到服务器B,B接收队列过程控制,将消息发送回服务器A,这样,响应可以发送到/ API请求创造秩序。

----> / createorder - > A服务器---> A发送一个消息队列到B的服务器--->它--->发送一个消息到A --->一个响应该请求乙服务器进程。

在这个过程中如何保持请求在服务器A和等待来自服务器B的响应

spring-boot microservices message-queue spring-jms spring-amqp
2个回答
2
投票

听起来像是你需要让自己熟悉Enterprise Integration Patterns,并实现与Spring Integration。有没有像网关模式,这个框架对JMS出站请求/应答对它的一个实现:https://docs.spring.io/spring-integration/docs/current/reference/html/jms.html#jms-outbound-gateway

在另一方面弹簧AMQP不支持AMQP 1.0协议,这是更可能可以通过定期JMS API处理。

从春天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;

所以,你可以考虑使用此为好,如果Spring集成是太难带给你的项目的时候了。

如果你感到困惑AMQP 0.9与JMS,那么你真的可以留在春天AMQP项目及其RabbitTemplate.sendAndReceive()


0
投票

等待响应,你可以尝试使用异步兔子。下面是从baeldung教程:https://www.baeldung.com/spring-amqp-reactive

© www.soinside.com 2019 - 2024. All rights reserved.