SpinGo / op-rabbit

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

Boolean header reader #133

Closed AlejandroME closed 6 years ago

AlejandroME commented 6 years ago

We've faced a case in where we needed to read a Boolean header from RabbitMQ. When you try to read a Boolean header like this:

Subscription {
      channel(qos){
        consume(queue(
          queueID,
          durable = true,
          exclusive = false,
          autoDelete = false
        )) {
          (body(as[String]) & routingKey & property(TypedHeader[String]("prop1")) & property(TypedHeader[Boolean]("prop2"))){...}

You get this error:

could not find implicit value for parameter conversion: com.spingo.op_rabbit.properties.FromHeaderValue[Boolean]

Because op-rabbit doesn't have an implementation for reading this type. We've written this solution for our problem and it works great.

The only thing that I don't like (but I think that there's no other way, and if there's actually a different method to do it, please point it out for me) is the usage of asInstanceOf, but, being the value of the HeaderValue an Any, I can't find another way of doing this.

I hope that this could useful for someone else @DStranger :)

Thank you!

AlejandroME commented 6 years ago

Thanks @timcharper!