Akka流/ HTTP:从响应中获取原始请求

编程入门 行业动态 更新时间:2024-10-25 02:23:04
本文介绍了Akka流/ HTTP:从响应中获取原始请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个Akka Streams源,它流经流程并发布HTTP请求:

I have an Akka Streams source that goes through a flow and posts an HTTP request:

source.map(toRequest) .via(Http().outgoingConnection(host)) .map(toMessage)

假设 toRequest 方法将一个字符串映射到 HttpRequest 和 toMessage 方法将 HttpResponse 映射到处理下游所需的消息类。假设消息类需要包含一些原始信息。

Suppose that the toRequest method maps a string to an HttpRequest, and the toMessage method maps the HttpResponse to a message class that is needed to process downstream. Suppose that the message class needs to contain some of the original information.

是否可以获得原始的 HttpRequest 来自 HttpResponse ?如果没有,有什么办法可以保留一些原始信息?

Is it possible to get the original HttpRequest from the HttpResponse? If not, is there any way to keep some of the original information?

推荐答案

一种方法是使用 客户端API的基于将来的变体和自定义案例类,其中包含您要向下游传播的信息。例如:

One approach is to use a Future-based variant of the client API and a custom case class that holds the information you want to propagate downstream. For example:

case class Message(request: HttpRequest, response: HttpResponse) source .map(toRequest) .mapAsync(parallelism = 3) { request => // adjust the level of parallelism as needed Http().singleRequest(request).map(response => Message(request, response)) } // continue processing; at this point you have a Source[Message, _]

更多推荐

Akka流/ HTTP:从响应中获取原始请求

本文发布于:2023-11-25 05:48:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628563.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:原始   Akka   HTTP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!