gkatzioura
gkatzioura

Reputation: 2820

Akka Streams: Add a flow which executes and http request

I have an Akka stream source from a Message queue, for example RabbitMq. For each message I want to execute an http request, map the http request to an object and proceed downward.

Is this possible by using a flow from the akka http (Http().outgoingConnection) or should the request be executed inside a map operation?

Upvotes: 1

Views: 105

Answers (1)

This is exactly what Http().outgoingConnection is used for (as mentioned in the question):

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) 

Upvotes: 3

Related Questions