Skip to content

Instantly share code, notes, and snippets.

@shivam-880
Created December 26, 2018 10:14
Show Gist options
  • Save shivam-880/cf19adbd08558773fbd37c49d0b532d9 to your computer and use it in GitHub Desktop.
Save shivam-880/cf19adbd08558773fbd37c49d0b532d9 to your computer and use it in GitHub Desktop.
@EnableServiceDiscovery
object MyService extends App {
implicit val system = ActorSystem("myservice-actor-system")
implicit val materializer = ActorMaterializer()
implicit val executionContext: ExecutionContext = system.dispatcher
val interface = RuntimeEnvironment.appConfig.getString("myservice.http.interface")
val port = RuntimeEnvironment.appConfig.getString("myservice.http.port").toInt
val serverBinding =
Http().bindAndHandle(
pathSingleSlash {
get {
complete(StatusCodes.OK, "Microservices can use @EnableServiceDiscovery macro-annotation to register themselves to Consul out of the box.")
}
},
interface,
port
)
serverBinding.onComplete {
case Success(bound) =>
println(s"MyService started @ http://$interface:$port")
case Failure(e) =>
Console.err.println(s"MyService could not start!")
e.printStackTrace()
system.terminate()
}
Await.result(system.whenTerminated, Duration.Inf)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment