【发布时间】:2018-01-29 15:22:06
【问题描述】:
我正在构建一个简单的 REST api,它将 Web 服务器连接到后端服务,该服务执行简单的检查并发送响应。
所以客户端(通过 HTTP)-> 到 Web 服务器(通过 ACTIVEMQ/CAMEL)-> 到 Checking-Service,然后再返回。
GET 请求的端点是 "/{id}"。我试图通过 queue:ws-out 向 queue:cs-in 发送一条消息,并将其重新映射回原始 GET 请求。
Checking-Service (cs) 代码很好,它只是使用 jmslistener 将 CheckMessage 对象中的值更改为 true。
我已经在网上彻底搜索了示例,但找不到任何工作。我找到的最接近的是following。
这是我目前在 Web 服务器上所拥有的 (ws)。
RestController
import ...
@RestController
public class RESTController extends Exception{
@Autowired
CamelContext camelContext;
@Autowired
JmsTemplate jmsTemplate;
@GetMapping("/{id}")
public String testCamel(@PathVariable String id) {
//Object used to send out
CheckMessage outMsg = new CheckMessage(id);
//Object used to receive response
CheckMessage inMsg = new CheckMessage(id);
//Sending the message out (working)
jmsTemplate.convertAndSend("ws-out", outMsg);
//Returning the response to the client (need correlation to the out message"
return jmsTemplate.receiveSelectedAndConvert("ws-in", ??);
}
}
ws 上的监听器
@Service
public class WSListener {
//For receiving the response from Checking-Service
@JmsListener(destination = "ws-in")
public void receiveMessage(CheckMessage response) {
}
}
谢谢!
【问题讨论】:
标签: spring-boot activemq spring-jms