akka http,singleRequest(java),未发送请求
我或多或少是akka和akka http的新手,在发送演员的http请求时遇到问题 我正在努力实现的目标:akka http,singleRequest(java),未发送请求,java,akka,akka-http,Java,Akka,Akka Http,我或多或少是akka和akka http的新手,在发送演员的http请求时遇到问题 我正在努力实现的目标: 参与者在收到计算命令时计算值 一旦计算完成,就会调用另一个参与者(让我们称他为ReplyActor)向另一个系统发送一个“完成”的http请求 消息正在排队,在我的设置中,始终只有一个ReplyActor处于活动状态 如果我只发送一个计算订单,一切正常。如果在某一点上有10个计算命令,则根据调试消息使系统减慢的程度,不会发送请求。没有例外,没有超时,注意 我的actor设置的设计类似于
- 参与者在收到计算命令时计算值
- 一旦计算完成,就会调用另一个参与者(让我们称他为ReplyActor)向另一个系统发送一个“完成”的http请求
- 消息正在排队,在我的设置中,始终只有一个ReplyActor处于活动状态
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 |
+---------+
未发送请求的命令链(相同运行):
谢谢你的帮助。谢谢
版本是2.4.8(2.11)(akka演员,akka http核心,akka http实验,akka流)明白了!看来我的请求“做错了” 4次请求后失败:
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
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));
Http=Http.get(context().system());
ActorMaterializer materializer=ActorMaterializer.create(context().system());
Flow=http.outgoingConnection(ConnectHttp.toHost(“localhost”,8091));
HttpRequest请求=HttpRequest.POST(“http://localhost:8091withEntity(ContentTypes.APPLICATION_JSON,message);
single(request).via(flow).runWith(Sink.head(),materialer).whenComplete((r,t)->log.info(“httpResponse:{},throwable:{}),r,t));
非常感谢,它为我指明了正确的方向。明白了!看来我的请求“做错了” 4次请求后失败:
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
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));
Http=Http.get(context().system());
ActorMaterializer materializer=ActorMaterializer.create(context().system());
Flow=http.outgoingConnection(ConnectHttp.toHost(“localhost”,8091));
HttpRequest请求=HttpRequest.POST(“http://localhost:8091withEntity(ContentTypes.APPLICATION_JSON,message);
single(request).via(flow).runWith(Sink.head(),materialer).whenComplete((r,t)->log.info(“httpResponse:{},throwable:{}),r,t));
非常感谢,这为我指明了正确的方向