0

Right now i am subscribing to single exchange using

AmqpSource.atMostOnceSource(
    NamedQueueSourceSettings(..))

I want to be able to subscribe to multiple exchange. Can anyone help me with this?

nocturnal
  • 395
  • 2
  • 6
  • 15

1 Answers1

1

If there's nothing specific for this for a particular alpakka source you can use either a Merge or MerbeHub.

If you know all of the sources up front you can combine multiple Sources into one using a Merge

If you don't know all of the sources up front you can use a MergeHub e.g.

// A simple consumer that will print to the console for now  
val consumer = Sink.foreach(println)

// Attach a MergeHub Source to the consumer. This will materialize to a
// corresponding Sink.
val runnableGraph: RunnableGraph[Sink[String, NotUsed]] =
  MergeHub.source[String](perProducerBufferSize = 16).to(consumer)

// By running/materializing the consumer we get back a Sink, and hence
// now have access to feed elements into it. This Sink can be materialized
// any number of times, and every element that enters the Sink will
// be consumed by our consumer.
val toConsumer: Sink[String, NotUsed] = runnableGraph.run()

// Feeding two independent sources into the hub.
AmqpSource.atMostOnceSource(
   NamedQueueSourceSettings(..)).runWith(toConsumer)
AmqpSource.atMostOnceSource(
   NamedQueueSourceSettings(..)).runWith(toConsumer)