Trait/Object

com.spingo.op_rabbit

Directives

Related Docs: object Directives | package op_rabbit

Permalink

trait Directives extends AnyRef

Directives power the declarative DSL of op-rabbit.

In order to define a consumer, you need a channel directive, a consumer directive, and one or more extractor directives. For example:

channel(qos = 3) {
  consume(queue("my.queue.name")) {
    (body(as[MyPayloadType]) & optionalProperty(ReplyTo) & optionalProperty(Priority)) { (myPayload, replyTo, priority) =>
      // work ...
      ack
    }
  }
}

As seen, directives are composable via &. In the end, the directive is applied with a function whose parameters match the output values from the directive(s).

One value of the directives, as opposed to accessing the AMQP properties directly, is that they are type safe, and care was taken to reduce the probability of surprise. Death is swiftly issued to null and Object. Some directives, such as property, will nack the message if the value specified can't be extracted; IE it is null. If you'd prefer to use a default value instead of nacking the message, you can specify alternative values using | provide(...).

(property(ReplyTo) | provide("default-reply-to") { replyTo =>
  // ...
}

Note: the directives themselves don't actually do anything, except when applied / returned. IE:

channel(qos = 3) {
  consume(queue("my.queue.name")) {
    property(ReplyTo) // does absolutely nothing

    body(as[MyPayloadType]) { (myPayload, replyTo, priority) =>
      ack // this ack here does absolutely nothing (not the return value)
      // work ...
      ack
    }
  }
}
Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Directives
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. def ack: Handler

    Permalink
  5. def ack(f: Ackable): Handler

    Permalink

    Ack the message

    Ack the message

    Examples:

    ack()
    
    ack(Future {
      //Some work
    })

    Note that in the case of acking with a Future, if the Future fails, then the message is counted as erroneous, and the RecoveryStrategy is use is applied.

  6. def as[T](implicit um: RabbitUnmarshaller[T]): RabbitUnmarshaller[T]

    Permalink
  7. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  8. def body[T](um: RabbitUnmarshaller[T]): Directive1[T]

    Permalink

    Extract the message body.

    Extract the message body. Uses a RabbitUnmarshaller to deserialize.

    Example:

    body(as[JobDescription])
  9. def channel(qos: Int = 1): ChannelDirective

    Permalink

    Declarative which declares a channel

  10. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  11. def consume(binding: QueueDefinition[Concreteness], args: Seq[Header] = Seq(), consumerTagPrefix: Option[String] = None): BindingDirective

    Permalink

    Declarative which declares a consumer

  12. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  13. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  14. def exchange: Directive1[String]

    Permalink

    Directive which yields the exchange through which the message was published

  15. def extract[T](map: (Delivery) ⇒ T): Directive1[T]

    Permalink

    Extract any arbitrary value from the delivery / Java RabbitMQ objects.

    Extract any arbitrary value from the delivery / Java RabbitMQ objects. Accepts a function which receives a Delivery and returns some value.

  16. def extractEither[T](map: (Delivery) ⇒ Either[Rejection, T]): Directive1[T]

    Permalink

    Like extract, but the provided function should return an Either, with left for a rejection, right for success.

  17. def fail(ex: Throwable): Handler

    Permalink

    Fail the given element

  18. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  19. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  20. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  21. def hprovide[T <: HList](value: T): Directive[T]

    Permalink
  22. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  23. def isRedeliver: Directive1[Boolean]

    Permalink

    Directive which yields whether this message been delivered once before (although, not necessarily received)

  24. def nack(requeue: Boolean = false): Handler

    Permalink

    Nack the message; does NOT trigger the RecoveryStrategy in use.

  25. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  26. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  27. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  28. def optionalProperty[T](extractor: PropertyExtractor[T]): Directive1[Option[T]]

    Permalink

    Given a property, yields Some(value).

    Given a property, yields Some(value). If the underlying value does not exist (is null), then it yields None.

  29. def passive[T <: Exchange.Value](exchange: Exchange[T]): Exchange[T]

    Permalink
  30. def passive[T <: Concreteness](queue: QueueDefinition[T]): QueueDefinition[T]

    Permalink

    Passive topic binding

  31. def pqueue(queue: String): QueueDefinition[Concrete]

    Permalink

    Passive queue binding

  32. def property[T](extractor: PropertyExtractor[T]): Directive1[T]

    Permalink

    Given a property, yields it's value.

    Given a property, yields it's value. If the underlying value does not exist (is null), then it nacks.

  33. def provide[T](value: T): Directive[::[T, HNil]]

    Permalink

  34. def queue(queue: String, durable: Boolean = true, exclusive: Boolean = false, autoDelete: Boolean = false): QueueDefinition[Concrete]

    Permalink

    Provides values for the consume directive.

  35. def routingKey: Directive1[String]

    Permalink

    Directive which yields the routingKey (topic) through which the message was published

  36. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  37. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  38. def topic(queue: QueueDefinition[Concrete], topics: List[String], exchange: Exchange[Topic.type] = ...): Binding

    Permalink
  39. def typeOf[T]: TypeHolder[T]

    Permalink
  40. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  41. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  42. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped