SpinGo / op-rabbit

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

feat: make exchange types extensible for plugins #130

Closed synhaptein closed 6 years ago

synhaptein commented 6 years ago

Add an abstract class ExchangeType to replace Exchange Enumeration values and let library users extend exchange type for plugins like rabbitmq-consistent-hash-exchange.

It then makes it easy to create specific binding outside of the library like this for different plugins

case object ConsistentHash extends ExchangeType("x-consistent-hash")

def consistentHash(queue: QueueDefinition[Concrete],
                   hashSpacePoints: Int,
                   exchange: ExchangeDefinition[Concrete] with Exchange[ConsistentHash.type]): Binding = new Binding {
    val exchangeName = exchange.exchangeName
    val queueName = queue.queueName
    def declare(c: Channel): Unit = {
      exchange.declare(c)
      queue.declare(c)
      c.queueBind(queueName, exchange.exchangeName, hashSpacePoints.toString, null)
    }
}

and use it seamlessly with the existing DSL

consume(consistentHash(queue("queue.name"), 20, Exchange.plugin(ConsistentHash, "exchange.name")))
bgparkerdev commented 6 years ago

We would love this enhancement as well.

DStranger commented 6 years ago

Thanks @synhaptein, sorry for the delay!

timcharper commented 6 years ago

We will need to make sure that the compatibility breakages documented? Should we create a type alias for Exchange.Value? (Perhaps, deprecated?)

DStranger commented 6 years ago

@timcharper good point, I suppose, something like this 7964cfb45ecb8d5e2b53a4767afb06385c656c14 should be enough?

timcharper commented 6 years ago

Yeah, that's it :)

On Sat, Feb 17, 2018 at 3:35 AM Dmitrii Kostianoi notifications@github.com wrote:

@timcharper https://github.com/timcharper good point, I suppose, something like this 7964cfb https://github.com/SpinGo/op-rabbit/commit/7964cfb45ecb8d5e2b53a4767afb06385c656c14 should be enough?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/SpinGo/op-rabbit/pull/130#issuecomment-366432305, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAAt0xcJN3T7Pm1VEpbHnuSq_oXCob3ks5tVqt_gaJpZM4RVFvx .

synhaptein commented 6 years ago

Sorry guys for the missing deprecation and thanks for fixing behind me @DStranger!