बंद करें मेरे पास एक एक्का HTTP एप्लिकेशन चल रहा है और मैं इसे बंद करना चाहता हूं।अक्का HTTP ऐप
मेरे लिए एसबीटी does not work में Ctrl +सी दबाने (मेरी खोल वर्तमान में Windows के लिए Git बैश है)।
अक्का ऐप को बंद करने का अनुशंसित तरीका क्या है?
बंद करें मेरे पास एक एक्का HTTP एप्लिकेशन चल रहा है और मैं इसे बंद करना चाहता हूं।अक्का HTTP ऐप
मेरे लिए एसबीटी does not work में Ctrl +सी दबाने (मेरी खोल वर्तमान में Windows के लिए Git बैश है)।
अक्का ऐप को बंद करने का अनुशंसित तरीका क्या है?
this thread से प्रेरणा ले रहा है, मैं अपने आवेदन के लिए एक मार्ग है कि नीचे आवेदन बन्द हो जाता है कहा:
def shutdownRoute: Route = path("shutdown") {
Http().shutdownAllConnectionPools() andThen { case _ => system.terminate() }
complete("Shutting down app")
}
जहां system
है एप्लिकेशन की ActorSystem।
इस मार्ग को देखते हुए, मैं अब नीचे अपने आवेदन
curl http://localhost:5000/shutdown
संपादित साथ बंद कर सकते हैं:
दूर से एक सर्वर बंद करने में सक्षम होने के नाते उत्पादन कोड के लिए एक अच्छा विचार नहीं है । टिप्पणी में, Henrik एक अलग तरह से है कि मार एसबीटी कंसोल में दर्ज करके सर्वर बंद हो जाता है की ओर इशारा किया:
StdIn.readLine()
// Unbind from the port and shut down when done
bindingFuture
.flatMap(_.unbind())
.onComplete(_ => system.terminate())
संदर्भ के लिए, मैं सर्वर प्रारंभ के अंत में इसके बाद के संस्करण कोड डाल:
// Gets the host and a port from the configuration
val host = system.settings.config.getString("http.host")
val port = system.settings.config.getInt("http.port")
implicit val materializer = ActorMaterializer()
// bindAndHandle requires an implicit ExecutionContext
implicit val ec = system.dispatcher
import akka.http.scaladsl.server.Directives._
val route = path("hi") {
complete("How's it going?")
}
// Starts the HTTP server
val bindingFuture: Future[ServerBinding] = Http().bindAndHandle(route, host, port)
val log = Logging(system.eventStream, "my-application")
bindingFuture.onComplete {
case Success(serverBinding) =>
log.info(s"Server bound to ${serverBinding.localAddress}")
case Failure(ex) =>
log.error(ex, "Failed to bind to {}:{}!", host, port)
system.terminate()
}
log.info("Press enter key to stop...")
// Let the application run until we press the enter key
StdIn.readLine()
// Unbind from the port and shut down when done
bindingFuture
.flatMap(_.unbind())
.onComplete(_ => system.terminate())
इस उदाहरण में वे एक ही विधि कॉल का उपयोग करके बाहर निकलने के लिए एक समान तरीका दिखाते हैं, लेकिन कनेक्शन खोलने के बजाय रिटर्न दबाकर। यदि आपके पास चल रही मशीन पर आसान भौतिक पहुंच है तो बेहतर हो सकता है। http://doc.akka.io/docs/akka-http/current/scala/http/routing-dsl/index.html#minimal-example – Henrik