SSE没有调度所有消息

时间:2018-08-06 15:30:26

标签: spring spring-boot spring-webflux reactor-rabbitmq

我正在使用spring boot 2.0.4reactor-nettyreactor-rabbitmq-1.0.0.M2来实现简单的SSE服务器。

由于某种原因,作为客户端,我没有收到所有已调度的消息。

一个实现示例:

@RestController
@RequestMapping("event")
@Slf4j
@CrossOrigin(origins = "*")
public class ExampleController {
    EventsService eventsService
    ...
    @GetMapping(value = "/{id}", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<ExampleEvent> exampleEvent((@PathVariable("id") int id) {

          return eventsService.dispatchEvents().log();
    }
}

EventsService在哪里:

@Service
@Slf4j
public class EventsService {
     //reactor.rabbitmq.Receiver
     private final Receiver receiver;
     private ObjectMapper objectMapper

     public Flux<ExampleEvent> dispatchEvents() {

         return this.receiver.consumeAutoAck(queue)
            .flatMap(msg -> {
                final ExampleEvent event = objectMapper.readValue(msg.getBody(), ExampleEvent.class);

                if(event != null) {
                    return Mono.just(event);
                }
                return Mono.error(new RuntimeException("Null value!"));
           )
    }

Receiver Bean

@Bean
public Receiver receiver(ConnectionFactory connectionFactory){
    ReceiverOptions options = new ReceiverOptions();
    options.connectionFactory(connectionFactory);

    return ReactorRabbitMq.createReceiver(options);
}

ConnectionFactory设置为 useNio()

现在,我的日志中塞满了reactor.Flux.OnAssembly.5 : | onNext个事件对象,但是由于某些原因,在粘贴URL时都在chrome上和在我的客户端(Angular)上都没有,我没有收到大部分消息(但是得到了一些消息)这是很奇怪的部分。

*****更新******

几乎每条消息,我都可以看到日志(即使没有断开连接)

2018-08-06 18:44:33.315信息22420 --- [ctor-http-nio-4]反应堆.Flux.OnAssembly.23:|取消() 2018-08-06 18:44:33.315信息22420-[ctor-http-nio-4] Reactor.rabbitmq.Receiver:取消从frame-update.queue消耗的消费者amq.ctag-lkjfsdfsdlfkdsjlk 2018-08-06 18:44:33.357错误22420 --- [ctor-http-nio-4] oswsadapter.HttpWebHandlerAdapter:无法处理的故障:主机中的软件中止了已建立的连接,已设置响应(状态= null)`

0 个答案:

没有答案