Created
December 26, 2018 10:14
-
-
Save shivam-880/cf19adbd08558773fbd37c49d0b532d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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