Akka Streams:添加一个执行和http请求的流程

时间:2018-05-13 12:57:06

标签: akka-stream akka-http

我有来自Message队列的Akka流源,例如RabbitMq。对于我想要执行http请求的每条消息,将http请求映射到一个对象并继续向下。

这可以通过使用来自akka http(Http(。。outgoingConnection)的流来实现,还是应该在map操作中执行?

1 个答案:

答案 0 :(得分:3)

这正是Http().outgoingConnection用于(如问题中所述):

type MQMessage = ???

val messageToRequest : (MQMessage) => HttpRequest = ???

type ObjectType = ???

val responseToObjectType = (HttpResponse) => ObjectType = ???

val httpHost : String = ???

val messageFlow : Flow[MQMessage, ObjectType, _] = 
  Flow.map(messageToRequest)
      .via(Http().outgoingConnection(httpHost))
      .map(responseToObjectType)