Scala:接收服务器发送事件 [英] Scala: Receiving Server-Sent-Events
问题描述
设置:
我正在处理的项目有一个带有HTTP接口的pub / sub服务器。订阅通过接受服务器发送事件来工作。
A project I am working on has a pub/sub server with an HTTP interface. Subscription works by accepting server-sent-events.
curl -X GET server:port/topics/news
每当邮件发布到给定主题网址时都会被推送
which will be pushed whenever a message is published to the given topic URL
curl -X PUT server:port/topics/news -d "Politician Lies!"
问题:
我有一个需要订阅此pub / sub服务器的scala项目。表演!框架能够通过使用带有Enumeratee + Iteratee的PlayWS来处理这个问题。不幸的是,PlayWS库要求播放!应用程序在范围内,我不使用Play。是否有一个库(具有最小的依赖性)我可以使用它允许我接受服务器发送事件?我需要至少一个工作示例才能开始。
I have a scala project which needs to subscribe to this pub/sub server. The Play! framework is able to handle this by using PlayWS with Enumeratee + Iteratee. Unfortunately, the PlayWS library requires that a Play! Application is in scope and I am not using Play. Is there a library (with minimal dependancies) I can use which allows me to accept server-sent-events? I'll need at least one working example in order to get started.
我偏爱scala库但我愿意接受Java解决方案,如果我有to。
I have a preference for scala libraries but I'm willing to accept a Java solution if I have to.
推荐答案
你有几种可能性:
在Play 2.3中, WS库现在是一个单独的库,所以这应该有所帮助。 RC2已经可用
In Play 2.3, the WS library is now a separate library, so that should help. RC2 is already available
或者,您可以依赖于Play 2.x并使用 StaticApplication
,如下所示:
Alternatively, you could depend on Play 2.x and use a StaticApplication
like so:
val application = new StaticApplication(new java.io.File("."))
这实际上是引导Play应用程序,从那里你可以使用 WS
图书馆照常
This will essentially bootstrap a Play application, and from there on you can use the WS
library as usual
这篇关于Scala:接收服务器发送事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!