问题描述
服务器发送的事件中的默认事件名称/类型为消息。我正在尝试更改事件名称,但是它不起作用。我正在使用Play 2.5和Akka流。
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)
但它没有更改事件名称/类型。它仍在监听消息事件,而不是 test1 。请提出建议。
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.
推荐答案
我通过声明隐式EventNameExtractor来解决此问题。下面是代码:
I fixed this issue by declaring implicit EventNameExtractor . Below is the code:
隐式定义对[E]:EventNameExtractor [E] = EventNameExtractor [E](p => Some(( test1))))。
implicit def pair[E]: EventNameExtractor[E] = EventNameExtractor[E](p => Some(("test1"))).
有效。
这篇关于使用Play 2.5和服务器发送的事件命名事件流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!