【发布时间】:2016-03-10 22:28:48
【问题描述】:
我正在尝试将 http 客户端连接到服务器公开的 http 服务,源应该每 1 秒发送一次请求,因为我已经按照部分图表进行了包装:
def httpSourceGraph() = {
Source.fromGraph(GraphDSL.create() { implicit builder =>
val sourceOutLet = builder.add(Source.tick(FiniteDuration(0, TimeUnit.SECONDS), FiniteDuration(1,
TimeUnit.SECONDS),
HttpRequest(uri ="/test", method = HttpMethods.GET))).out
// expose outlet
SourceShape(sourceOutLet)
})
}
def httpConnFlow() = {
Flow.fromGraph(GraphDSL.create() { implicit builder =>
val httpSourceFlow = builder.add(Http(system).outgoingConnection(host = "localhost", port = 8080))
FlowShape(httpSourceFlow.in, httpSourceFlow.out)
})
}
图表组成为
val response= httpSourceGraph.via(httpConnFlow()).runForeach(println)
如果 http 服务器 (localhost:8080/test) 启动并运行,一切正常,每 1 秒我可以看到从服务器返回的响应。如果任一服务器关闭或稍后关闭,我将无法做出任何响应。
我认为它应该给我以下错误:
akka.stream.StreamTcpException: Tcp 命令 [Connect(localhost/127.0.0.1:8080,None,List(),Some(10 seconds),true)] 失败
这也可以用一些错误的 url 进行测试。 (域名stackoverflow1.com和错误的url“/test”)
感谢您的帮助。
-阿伦
【问题讨论】:
标签: akka akka-stream akka-http