Backend running under play framework(v. 2.6.5 scala) must communicate with Apple Push Notificaton Service (APNs) . APNs requires using HTTP/2, and so i tried to find any way to implement such communication, but to my surprise i didn`t find any http scala clients, supporting http v 2.0.
Is there any way to realize such communication without going out of the framework?
Thanks!
Play Framework with a version prior to 2.6 does not support HTTP 2.0, but, Play Framework 2.6 is based on Akka-Http and has experimental support for HTTP 2.0. This feature is labeled "experimental" because the API may change in the future, and it has not been thoroughly tested in the wild.
To add support for HTTP/2, add the PlayAkkaHttp2Support plugin. You can do this in an enablePlugins:
lazy val root = (project in file("."))
.enablePlugins(PlayScala, PlayAkkaHttp2Support)
If you consider alternatives take a look at:
Jetty has a capability to use HTTP 2.0
Netty also supports HTTP 2.0
Check this list of known implementations of HTTP 2.0.
In Akka HTTP, which underlies Play! Framework, HTTP/2 support is experimental on the server side and not yet available on the client side, as far as I can tell. Work is in progress and is tracked on Github. Unless you're inclined to write HTTP/2 client support yourself and optionally donate it to the project (which would probably be a very satisfying experience), going outside of the framework is probably going to be a necessity for now, I'm afraid.
If you're in a position to use Java 9 (hey, it's been gold for two days!), you might consider its HTTP/2 client.
Vert.x is originally a Java framework inspired by NodeJS, but in its current incarnation it includes an HTTP/2 client with a Scala API: http://vertx.io/docs/vertx-web-client/scala/ - I've never used it in production so YMMV...
Edit: you might also consider sttp with the OkHttp backend, which supports HTTP/2.
Related
Now that neo4j has dropped http:// support in favor of bolt://, my Unity projects can’t execute. The message is
Curl error 1: Protocol "bolt" not supported or disabled in libcurl
The question is: how to get Unity to support bolt:// This means it would have to be a C# solution. If it won’t, how to revert to an earlier version of neo4j that still has http:// support.
There’s nothing in the neo4j or Unity developer forums about this.
Either you connect with the Bolt protocol (URI schemes are bolt:// or neo4j:// or variants thereof), in which case you need the official .NET driver for Neo4j, or you connect to the HTTP API in which case libcurl works fine.
But you cannot use libcurl to communicate to a Neo4j instance with the Bolt protocol.
At the time I write this post, Play Framework is at v2.6.0-M4. The v2.5 version of the framework had difficulties to work with gRPC because of Netty conflicts (see this stackoverflow answer).
I'm starting to look into gRPC and protobufs. Already ported a project from Play Framework 2.5 > 2.6.0-M4 in anticipation of the actual release. Currently I have some questions regarding integration of gRPC. I'm wondering how to let the gRPC server work along nicely with Play Framework. I know that v2.6 switched to Akka HTTP server instead of Netty, while I use the grpc-netty dependency in sbt so maybe I'll have to switch the project to Netty again (here's how).
For testing purposes, I created a quick and dirty GrpcServer.scala class that starts up a thread with the GrpcServer listening. I managed to add ScalaPB with gRPC and generate/compile my protobufs. It works perfectly to communicate with a small testing NodeJS app but I have to startup this server app independently from the main project:
private def start(): Unit = {
server = ServerBuilder.forPort(GrpcServer.port).addService(GreeterGrpc.bindService(new GreeterImpl, executionContext)).build.start
GrpcServer.logger.info("Server started, listening on " + GrpcServer.port)
sys.addShutdownHook {
System.err.println("*** shutting down gRPC server")
self.stop()
System.err.println("*** server shut down")
}
}
Possible solutions to integrate gRPC in Play Framework
Now for the real integration in Play Framework v2.6, I'm looking for suggestions. Here's some things I can do:
Create a module and start the gRPC server when Play Framework starts up, like described in this stackoverflow answer. This would mean that we run the gRPC server on a different port next to the existing server (Akka HTTP server from Play Framework 2.6)
Create a Scala Command and make it long-running. So we always make sure we start a command that runs the gRPC server when we start our application on a server.
Switch from Akka HTTP to Netty in Play Framework v2.6 and tightly integrate gRPC with the existing Netty server so it hooks into the existing Netty server instead of creating a server on our own. I would like this solution but not sure how to deal with it. It certainly would avoid having two separate http stacks running.
Any tips/ideas for a clean integration are helpful as there's not much information about Play Framework and gRPC available, except that there were issues in the previous 2.5 version...
There's a sample application that comes with Play Framework 2.0. The application uses Play's WebSocket implementation on the server side. I am wondering can I use socket.io on the client side to connect with Play's WebSocket implementation on the server side?
In theory, yes, you can make Socket.io connect to your websocket server wia the corresponding ws url.
In practice, I tried and I had some issues, so it might require you to adapt Socket.io for it to work properly. Granted I tried on 2.0.1 or similar, so it may be working currently with no issues.
How do I find out if my request was made over HTTP or HTTPS in Play 2.0?
Is there a way to find out from the request?
def myControllerMethod = Action { request =>
// this is where I would like to know
}
Play 1.X had a solution, it was request.secure. Please let me know if you know.
Play! Framework 2.0 doesn't currently support HTTPS (the master branch does seem to have support, but that will probably be rolled into Play 2.1). A great way to deploy Play! (in general, and also to support HTTPS) is to use a front proxy web server, like nginx or lighttpd.
Here's a guide on setting up a front-end web server. Then, you can just add a special header for HTTPS requests. Additionally, you'll be able to deploy several Play! applications at once, and use the front-end web server to load balance and fail over automatically.
Are there any websocket plugins for nodejs; I would like to develop some application that uses websockets.
Checkout Socket.IO - it's a widely used and powerful Node module for socket connections.
WebSocket-Node is a pure WebSocket implementation in node.js that supports the latest version of the WebSocket spec (version 8), and is still being actively maintained.
Otherwise Socket.io has broader browser support because it can fall back to things such as Flash Sockets, long lived iframes etc.
Like cmpolis mentioned, Socket.IO is excellent. Just upgraded to 0.8 too.
nowjs also provides a higher-level api if you like more abstraction.
Similar to nowjs, dnode allows you to call remote functions between the client and server and vice versa.
Here is a great SO answer delineating the differences between them.