SpinGo / op-rabbit

The Opinionated RabbitMQ Library for Scala and Akka
Other
232 stars 73 forks source link

Consume from multiple queues #97

Open NotBobTheBuilder opened 7 years ago

NotBobTheBuilder commented 7 years ago

Is it possible to consume from multiple queues in op-rabbit?

I've tried various permutations of this, but I can only seem to get the last-defined subscription to take effect, the others don't act. Here's what I was hoping would work:

  Subscription.run(rabbitControl) {
    import Directives._
    channel() {
      consume(queue("abc")) {
        body(as[ABC]) { abc => ack }
      }
      consume(queue("def")) {
        body(as[DEF]) { def => ack(Future.successful("Business Logic") }
      }
      consume(queue("xyz")) {
        body(as[XYZ]) { xyz => ack }
      }
    }
  }

Or even potentially chaining the consumers together with ~, as is done in the akka-http routing tool.

I've tried 3 channel blocks inside one Subscription.run, 3 consume blocks inside one channel, and 3 separate Subscription.runs, none of which seem to work. Could you give an example of how to consume 3 different queues?

timcharper commented 7 years ago

Hey @NotBobTheBuilder - the DSL has been designed to eventually support this, but it hasn't been implemented yet. Can you define three separate subscriptions? I realize this creates more channels than you might prefer.

Since 1.0 I've been carving the code towards support for this, removing another barrier with a recent refactoring of SubscriptionActor. It shouldn't be difficult to implement this feature at this point. Help is certainly welcome!