spray-websocket 是 Spray 的扩展,实现对 WebSocket 的支持。
示例代码:
package spray.can.websocket.examples import akka.actor.{ ActorSystem, Actor, Props, ActorLogging, ActorRef, ActorRefFactory } import akka.io.IO import spray.can.Http import spray.can.server.UHttp import spray.can.websocket import spray.can.websocket.frame.{ BinaryFrame, TextFrame } import spray.http.HttpRequest import spray.can.websocket.FrameCommandFailed import spray.routing.HttpServiceActor object SimpleServer extends App with MySslConfiguration { final case class Push(msg: String) object WebSocketServer { def props() = Props(classOf[WebSocketServer]) } class WebSocketServer extends Actor with ActorLogging { def receive = { // when a new connection comes in we register a WebSocketConnection actor as the per connection handler case Http.Connected(remoteAddress, localAddress) => val serverConnection = sender() val conn = context.actorOf(WebSocketWorker.props(serverConnection)) serverConnection ! Http.Register(conn) } } object WebSocketWorker { def props(serverConnection: ActorRef) = Props(classOf[WebSocketWorker], serverConnection) } class WebSocketWorker(val serverConnection: ActorRef) extends HttpServiceActor with websocket.WebSocketServerWorker { override def receive = handshaking orElse businessLogicNoUpgrade orElse closeLogic def businessLogic: Receive = { // just bounce frames back for Autobahn testsuite case x @ (_: BinaryFrame | _: TextFrame) => sender() ! x case Push(msg) => send(TextFrame(msg)) case x: FrameCommandFailed => log.error("frame command failed", x) case x: HttpRequest => // do something } def businessLogicNoUpgrade: Receive = { implicit val refFactory: ActorRefFactory = context runRoute { getFromResourceDirectory("webapp") } } } def doMain() { implicit val system = ActorSystem() import system.dispatcher val server = system.actorOf(WebSocketServer.props(), "websocket") IO(UHttp) ! Http.Bind(server, "localhost", 8080) readLine("Hit ENTER to exit ...\n") system.shutdown() system.awaitTermination() } // because otherwise we get an ambiguous implicit if doMain is inlined doMain() }
精尽 Dubbo 原理与源码 69 篇 精尽 Netty 原理与源码 61 篇 中文详细注释的开源项目 Java 并发源码合集 RocketMQ 源码合集 Sharding-JDBC 源码解析合集 Spring MVC 和 Security 源码合集 MyCAT 源码解析合集 来源:http://t.cn/R94WxA1 1. 测试环境2. 测试结果2.1 Netty2.2 Vert.x2.3 U
原文地址:http://colobu.com/2015/05/22/implement-C1000K-servers-by-spray-netty-undertow-and-node-js/#Netty服务器 目录 [−] 事实上,最近我又增加了几个框架,现在包括 Netty, Undertow, Jetty, Spray, Vert.x, Grizzly 和 Node.js七种框架。 测试数
Spray 是一个开源的 REST/HTTP 工具包和底层网络 IO 包,基于 Scala 和 Akka 构建。轻量级、异步、非堵塞、基于 actor 模式、模块化和可测试是 spray 的特点。 示例代码: val responses: Future[Seq[HttpResponse]] = HttpDialog(host = "img.example.com", port = 888
spray-socketio 是 spray 的扩展,实现对 Socket.io 的支持。
GitHub Spray A CLI to generate sprays for your GitHub contribution history graph Installation npm i -g github-spray Requirements Git Recent NodeJS Usage Create a new GitHub repository and copy its url
我正在Akka、Spray和Log4j2中构建一个新应用程序。我的大多数主要系统都在“hello world”类型的模式下工作,但我很难让日志正常工作,我无法判断这是log4j2问题、Akka/Spray问题还是我的迟钝问题。 首先,我的Akka配置文件 现在,如果我把loggers行注释掉,在IntelliJ中运行这个应用程序,它在控制台中是完美的。我得到我想要的一切,我得到非常详细和有用的日志
我可以找到许多例子,说明如何让akka-http服务器轻松封送由case类表示的响应实体,只需混合使用SprayJSONSupport/DefaultJSONProtocol,在隐式作用域中提供jsonFormat并在路由DSL中使用complete指令。整齐!
我有一个类似于Pairs的类。我有一个特性,可以将这个类转换成Json格式。 当我使用这个特性时,我得到了以下错误,即对于