PageRenderTime 34ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/groovy/akka/akka-http/client_sample/server_sample.groovy

https://github.com/fits/try_samples
Groovy | 40 lines | 32 code | 8 blank | 0 comment | 0 complexity | 4e3f7c9a8a0633a165ae7a15aed49ab0 MD5 | raw file
  1. @Grab('com.typesafe.akka:akka-http_2.12:10.0.10')
  2. import static akka.http.javadsl.server.Directives.*
  3. import akka.actor.ActorSystem
  4. import akka.http.javadsl.Http
  5. import akka.http.javadsl.ConnectHttp
  6. import akka.stream.ActorMaterializer
  7. def system = ActorSystem.create('sample')
  8. def mat = ActorMaterializer.create(system)
  9. def http = Http.get(system)
  10. def createRoute = {
  11. route(
  12. path('data') {
  13. parameter('v') { v ->
  14. println v
  15. complete('ok')
  16. }
  17. }
  18. )
  19. }
  20. def routeFlow = createRoute().flow(system, mat)
  21. def binding = http.bindAndHandle(
  22. routeFlow,
  23. ConnectHttp.toHost('localhost', 8080),
  24. mat
  25. )
  26. println 'start ...'
  27. System.in.read()
  28. binding.thenCompose {
  29. it.unbind()
  30. }.thenAccept {
  31. system.terminate()
  32. }