Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@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
You can’t perform that action at this time.