Named event stream with Play 2.5 and server sent e

2019-08-29 10:38发布

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条回答
放我归山
2楼-- · 2019-08-29 11:17

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.

查看更多
登录 后发表回答