我有两个弹簧启动应用程序.一个在端口8081上运行ZuulProxy服务器,并将对/ notification的所有请求转发到在端口8086上运行的另一个Spring引导应用程序(通知服务器).
zuul配置看起来像这样
zuul:
routes:
notification:
path: /notification/**
url: http://localhost:8086
Run Code Online (Sandbox Code Playgroud)
通知服务器代码如下所示
@RestController
public class JmsController {
private Logger log = Logger.getLogger(this.getClass());
private final List<SseEmitter> emitters = new ArrayList<>();
@Autowired
private JmsService jmsService;
@RequestMapping(value = "send", method = RequestMethod.POST, consumes= MediaType.APPLICATION_JSON_VALUE)
public NotificationDTO sendMessage(@RequestBody NotificationDTO dto){
jmsService.sendMessage(dto);
return dto;
}
@RequestMapping(path = "/stream", method = RequestMethod.GET)
public SseEmitter stream() throws IOException {
SseEmitter emitter = new SseEmitter();
emitters.add(emitter);
emitter.onCompletion(() -> emitters.remove(emitter));
return emitter;
}
@JmsListener(destination = "${queue.name}", containerFactory = "myJmsContainerFactory")
public …Run Code Online (Sandbox Code Playgroud) spring-cloud ×1