Start a simple, stateless service
Start a simple, stateless service
Unlike Service.serve
, there is no room for per-worker or per-connection
initialization. Useful when starting simple services or testing
the type of codec this service uses
Name of this Service
Port on which this Server will accept connections
The IOSystem to which this Server will belong
CodecProvider
Quick-start a service, using default settings
Quick-start a service, using default settings
The name of the service
The port to bind the server to
Start a service with worker and connection initialization
Start a service with worker and connection initialization
The basic structure of a service using this method is:
Service.serve[Http]{ workerContext => //worker initialization workerContext.handle { connectionContext => //connection initialization connection.become { case ... } } }
The codec to use, eg Http, Redis
Settings to provide the underlying server
Config for the service
The worker initializer to use for the service
A ServerRef for the server.
The Service object is an entry point into the the Service DSL which provide some convenience functions for quickly creating a Server serving responses to requests utilizing a Codec(ie: memcached, http, redis, etc).
One thing to always keep in mind is that code inside the Service.serve is placed inside a Delegator and ConnectionHandler, which means that it directly runs inside of a Worker and its SelectLoop. Be VERY mindful of the code that you place in here, as if there is any blocking code it will block the Worker. Not good.
An example with full typing in place to illustrate :