Named event stream with Play 2.5 and server sent e

2019-08-29 10:34发布

问题:

Default event name/type in server sent event is "message". I am trying to change the event name but it is not working. I am using Play 2.5 and akka streams.

(actorRef,sourcePublisher)=  Source
      .actorRef[T](10, OverflowStrategy.fail)
      .toMat(Sink.asPublisher(true))(Keep.both)
      .run()

backsource = Source.fromPublisher[T](sourcePublisher).named("test1")
Ok.chunked(backsource via EventSource.flow)
      .as(ContentTypes.EVENT_STREAM)

But it is not changing the event name/type. It is still listening to message event rather than test1. Please suggest. Any help is appreciated.

回答1:

I fixed this issue by declaring implicit EventNameExtractor . Below is the code:

implicit def pair[E]: EventNameExtractor[E] = EventNameExtractor[E](p => Some(("test1"))).

It worked.