我或多或少是akka和akka-http的新手,并且遇到了从演员发送http singleRequest的问题。
我正在努力实现的目标:
如果我发送一个计算订单,一切正常。如果有10个计算订单,在某些时候,根据系统使用调试消息减慢的速度,请求不会被发送。没有例外,没有超时,注意到。
我的actor设置的设计类似于akka示例中的分布式主工作者示例。在尝试弄清楚什么是错误的时候,我只运行一个工作人员( CalculationActor 和 ReplyActor )。
嗯,我已经为你提供了更多细节。
首先,如果请求端点是用akka http编写的,那么一切正常。可悲的是,它是用sparkjava编写的,它依赖于码头。但据我所知,这不是终点的错。请求未发送。
在 akka.http.impl.engine.client.PoolConductor #application 是命令流图:
Request- +-----------+ +-----------+ Switch- +-------------+ +-----------+ Command
Context | retry | | slot- | Command | doubler | | route +-------------->
+--------->| Merge +---->| Selector +-------------->| (MapConcat) +---->| (Flexi +-------------->
| | | | | | | Route) +-------------->
+----+------+ +-----+-----+ +-------------+ +-----------+ to slots
^ ^
| | SlotEvent
| +----+----+
| | flatten | mapAsync
| +----+----+
| | RawSlotEvent
| Request- |
| Context +---------+
+-------------+ retry |<-------- RawSlotEvent (from slotEventMerge)
| Split |
+---------+
未发送的请求缺少slot-Selector命令。不知道为什么。我已经花了一些时间调试。也许以下是一些帮助:
成功发送请求的命令链:
akka.stream.actor.ActorPublisher#onNext
element: RequestContext(HttpRequest(HttpMethod(POST),/example/reply/uri,List(Host: localhost:4567),HttpEntity.Strict(application/json,"acbacca1-11e1-4f14-a4a6-4b14b53598a4"),HttpProtocol(HTTP/1.1)),List(scala.concurrent.impl.CallbackRunnable@1c81ab77),0)
threadId: 51
akka.stream.actor.ActorPublisher#onNext
element: RequestContext(HttpRequest(HttpMethod(POST),/example/reply/uri,List(Host: localhost:4567),HttpEntity.Strict(application/json,"acbacca1-11e1-4f14-a4a6-4b14b53598a4"),HttpProtocol(HTTP/1.1)),List(scala.concurrent.impl.CallbackRunnable@1c81ab77),0)
threadId: 51
akka.stream.stage.GraphStageLogic#grab (fast path)
element: RequestContext(HttpRequest(HttpMethod(POST),/example/reply/uri,List(Host: localhost:4567),HttpEntity.Strict(application/json,"acbacca1-11e1-4f14-a4a6-4b14b53598a4"),HttpProtocol(HTTP/1.1)),List(scala.concurrent.impl.CallbackRunnable@1c81ab77),0)
threadId: 49
akka.stream.stage.GraphStageLogic#emit (isAvailable(out)) => push
out (class): akka.stream.Outlet
element (class): akka.http.impl.engine.client.PoolFlow$RequestContext
threadId: 49
akka.stream.stage.GraphStageLogic#grab (fast path)
element: RequestContext(HttpRequest(HttpMethod(POST),/example/reply/uri,List(Host: localhost:4567),HttpEntity.Strict(application/json,"acbacca1-11e1-4f14-a4a6-4b14b53598a4"),HttpProtocol(HTTP/1.1)),List(scala.concurrent.impl.CallbackRunnable@1c81ab77),0)
threadId: 49
akka.stream.stage.GraphStageLogic#emit (isAvailable(out)) => push
out (cass): akka.stream.Outlet
element (class): akka.http.impl.engine.client.PoolConductor$SwitchSlotCommand)
threadId: 49
akka.stream.stage.GraphStageLogic#emit (isAvailable(out)) => push
out (class): akka.stream.Outlet
element (class): akka.http.impl.engine.client.PoolConductor$DispatchCommand
threadId: 49
akka.stream.actor.ActorPublisher#onNext
HttpRequest(HttpMethod(POST),/example/reply/uri,List(Host: localhost:4567),HttpEntity.Strict(application/json,"acbacca1-11e1-4f14-a4a6-4b14b53598a4"),HttpProtocol(HTTP/1.1))
threadId: 78
akka.stream.actor.ActorPublisher#onNext
HttpRequest(HttpMethod(POST),/example/reply/uri,List(Host: localhost:4567),HttpEntity.Strict(application/json,"acbacca1-11e1-4f14-a4a6-4b14b53598a4"),HttpProtocol(HTTP/1.1))
threadId: 78
akka.stream.stage.GraphStageLogic#emit (isAvailable(out)) => push
out (class): akka.stream.Outlet
element (class): akka.http.impl.engine.rendering.RequestRenderingContext
threadId: 78
akka.stream.stage.GraphStageLogic#emit (isAvailable(out)) => push
out (class): akka.stream.Outlet
element (class): scala.collection.immutable.$colon$colon
threadId: 78
akka.stream.actor.ActorPublisher#onNext
List(ResponseDelivery(ResponseContext(RequestContext(HttpRequest(HttpMethod(POST),/example/reply/uri,List(Host: localhost:4567), ...
threadId: 78
未发送请求的命令链(同一次运行):
akka.stream.actor.ActorPublisher#onNext
RequestContext(HttpRequest(HttpMethod(POST),/example/reply/uri,List(Host: localhost:4567),HttpEntity.Strict(application/json,"47bc9378-5166-4a14-920a-8eab53717263"),HttpProtocol(HTTP/1.1)),List(scala.concurrent.impl.CallbackRunnable@29ee365f),0)
threadId: 116
akka.stream.actor.ActorPublisher#onNext
element: RequestContext(HttpRequest(HttpMethod(POST),/example/reply/uri,List(Host: localhost:4567),HttpEntity.Strict(application/json,"47bc9378-5166-4a14-920a-8eab53717263"),HttpProtocol(HTTP/1.1)),List(scala.concurrent.impl.CallbackRunnable@29ee365f),0)
threadId: 116
akka.stream.stage.GraphStageLogic#grab (fast path)
element: RequestContext(HttpRequest(HttpMethod(POST),/example/reply/uri,List(Host: localhost:4567),HttpEntity.Strict(application/json,"47bc9378-5166-4a14-920a-8eab53717263"),HttpProtocol(HTTP/1.1)),List(scala.concurrent.impl.CallbackRunnable@29ee365f),0)
threadId: 78
akka.stream.stage.GraphStageLogic#emit (NOT isAvailable(out)) => setOrAddEmitting
out (class): akka.stream.Outlet
element (class): akka.http.impl.engine.client.PoolFlow$RequestContext
threadId: 78
akka.stream.stage.GraphStageLogic#emit (NOT isAvailable(out)) => setOrAddEmitting
out (class): akka.stream.Outlet
element (class): akka.http.impl.engine.client.PoolFlow$RequestContext
threadId: 78
akka.stream.stage.GraphStageLogic#setOrAddEmitting case e
handler: akka.stream.stage.GraphStageLogic$EagerTerminateOutput$@546413bd
out: MergePreferred.out,
next: akka.stream.stage.GraphStageLogic$EmittingSingle@69621de0
threadId: 78
akka.stream.stage.GraphStageLogic#setOrAddEmitting case e
handler: akka.stream.stage.GraphStageLogic$EagerTerminateOutput$@546413bd
out: MergePreferred.out,
next: akka.stream.stage.GraphStageLogic$EmittingSingle@69621de0
threadId: 78
akka.stream.stage.GraphStageLogic#setOrAddEmitting case _
handler: akka.stream.stage.GraphStageLogic$EagerTerminateOutput$@546413bd
out: MergePreferred.out
next: akka.stream.stage.GraphStageLogic$EmittingSingle@69621de0
threadId: 78
akka.stream.actor.ActorPublisher#onNext
element: List(Disconnected(0,0))
threadId: 117
akka.stream.actor.ActorPublisher#onNext
element: List(Disconnected(0,0))
threadId: 117
akka.stream.actor.ActorPublisher#onNext
element: List(Disconnected(1,0))
threadId: 49
我感谢任何帮助。谢谢!
版本是2.4.8(2.11)(akka-actor,akka-http-core,akka-http-experimental,akka-stream)
答案 0 :(得分:0)
知道了!看起来我正在做我的要求&#34;错误&#34;。
在4次请求后失败:
Http http = Http.get(context().system());
ActorMaterializer materializer = ActorMaterializer.create(context().system());
HttpRequest request = HttpRequestPOST("http://localhost:8091").withEntity(ContentTypes.APPLICATION_JSON, message);
http.singleRequest(request, materializer).whenComplete((r, t) -> log.info("httpResponse: {}, throwable: {}", r, t));
使用:
Http http = Http.get(context().system());
ActorMaterializer materializer = ActorMaterializer.create(context().system());
Flow<HttpRequest, HttpResponse, CompletionStage<OutgoingConnection>> flow = http.outgoingConnection(ConnectHttp.toHost("localhost", 8091));
HttpRequest request = HttpRequest.POST("http://localhost:8091").withEntity(ContentTypes.APPLICATION_JSON, message);
Source.single(request).via(flow).runWith(Sink.head(), materializer).whenComplete((r, t) -> log.info("httpResponse: {}, throwable: {}", r, t));
非常感谢this question (and answer),它指出了我正确的方向。