Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
akka http,singleRequest(java),未发送请求_Java_Akka_Akka Http - Fatal编程技术网

akka http,singleRequest(java),未发送请求

akka http,singleRequest(java),未发送请求,java,akka,akka-http,Java,Akka,Akka Http,我或多或少是akka和akka http的新手,在发送演员的http请求时遇到问题 我正在努力实现的目标: 参与者在收到计算命令时计算值 一旦计算完成,就会调用另一个参与者(让我们称他为ReplyActor)向另一个系统发送一个“完成”的http请求 消息正在排队,在我的设置中,始终只有一个ReplyActor处于活动状态 如果我只发送一个计算订单,一切正常。如果在某一点上有10个计算命令,则根据调试消息使系统减慢的程度,不会发送请求。没有例外,没有超时,注意 我的actor设置的设计类似于

我或多或少是akka和akka http的新手,在发送演员的http请求时遇到问题

我正在努力实现的目标:

  • 参与者在收到计算命令时计算值
  • 一旦计算完成,就会调用另一个参与者(让我们称他为ReplyActor)向另一个系统发送一个“完成”的http请求
  • 消息正在排队,在我的设置中,始终只有一个ReplyActor处于活动状态
如果我只发送一个计算订单,一切正常。如果在某一点上有10个计算命令,则根据调试消息使系统减慢的程度,不会发送请求。没有例外,没有超时,注意

我的actor设置的设计类似于akka示例中的分布式主工作者示例。在试图找出问题所在的同时,我只运行了一个worker(CalculationActor和ReplyActor)

好吧,我有更多的细节要告诉你

首先,如果请求端点是用akka http编写的,那么一切都可以正常工作。遗憾的是,它是用sparkjava编写的,sparkjava依赖于jetty。但据我所知,这不是终点站的错。请求未被发送

在akka.http.impl.engine.client.PoolConductor#apply上有一个命令流图:

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)); 非常感谢,这为我指明了正确的方向