对我来说效果很好:
@SpringBootApplication@RestControllerpublic class SpringIntegrationSseDemoApplication { public static void main(String[] args) { SpringApplication.run(SpringIntegrationSseDemoApplication.class, args); } @Autowired private ConnectionFactory connectionFactory; @Autowired private JmsTemplate jmsTemplate; @Bean public Publisher<Message<String>> jmsReactiveSource() { return IntegrationFlows .from(Jms.messageDrivenChannelAdapter(this.connectionFactory) .destination("testQueue")) .channel(MessageChannels.queue()) .log(LoggingHandler.Level.DEBUG) .log() .toReactivePublisher(); } @GetMapping(value = "/events", produces = MediaType.TEXT_EVENT_STREAM_VALUE) public Flux<String> getPatientalerts() { return Flux.from(jmsReactiveSource()) .map(Message::getPayload); } @GetMapping(value = "/generate") public void generateJmsMessage() { for (int i = 0; i < 100; i++) { this.jmsTemplate.convertAndSend("testQueue", "testMessage #" + (i + 1)); } }}
在一个终端中,我有
curl http://localhost:8080/events一个等待来自那里的SSE
Flux。
在另一个终端中,我执行
curl http://localhost:8080/generate并在第一个终端中看到:
data:testMessage #1data:testMessage #2data:testMessage #3data:testMessage #4
我使用Spring Boot 2.0.0.BUILD-SNAPSHOT。
另请参阅此处:https : //spring.io/blog/2017/03/08/spring-tips-server-sent-events-
sse
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)