RabbitMQ Steps

  • create a queue createRabbitmqQueue

  • delete a queue deleteRabbitmqQueue

  • publish a message on a queue publishRabbitmqMessage

  • read a message from a queue givenMessageFromRabbitmqQueue

  • read multiple messages from a queue givenMessagesFromRabbitmqQueue

  • count number of messages in a queue `givenNumberOfMessagesInRabbitmqQueue

Create a queue on RabbitMQ

This step may seem useless, consider it as a helper to build scenarios

Parameters to provide on step

  • name: String? // optional, give a name to your step to make scenario execution more readable

  • retry: String // optional, give a chance for step to fail several times before passing

  • builder: RabbitMQQueueCreationExecutionBuilder.() → Unit // mandatory, configure execution of step
    builder parameters are:

    • message: QueueAndBinding // mandatory, configuration of queue to create

      • queue: String // mandatory, queue to create

      • exchange: String? // optional, if not set no binding will be created to any exchange

      • routingKey: String // optional, routing key to bind on exchange

        // QueueAndBinding is built by a combination if three functions written as follows:
        createQueue { "world" } andBindItToExchange "universe" withRoutingKey "galaxy"
    • connection: String // optional, connection string to rabbitmq, defaults to amqp://guest:guest@localhost:5672

    • vhost: String // optional, defaults to /

      connection and vhost can be set globally on kest configuration file:

      kest.yml
      rabbitmq:
        connection: amqp://mylogin:mypwd@myhost:4567
        vhost: /myvhost

Sample

createRabbitmqQueue("Obi-Wan Kenobi should be born before he can receive a message") {
    createQueue { "obi-wan_kenobi" } andBindItToExchange "StarWars" withRoutingKey "Force"
}

Delete a queue on RabbitMQ

This step may seem useless, consider it as a helper to build scenarios

Parameters to provide on step

  • name: String? // optional, give a name to your step to make scenario execution more readable

  • retry: String // optional, give a chance for step to fail several times before passing

  • builder: RabbitMQQueueDeletionExecutionBuilder.() → Unit // mandatory, configure execution of step
    builder parameters are:

    • queue: String // mandatory, queue to create

    • connection: String // optional, connection string to rabbitmq, defaults to amqp://guest:guest@localhost:5672

    • vhost: String // optional, defaults to /

      connection and vhost can be set globally on kest configuration file:

      kest.yml
      rabbitmq:
        connection: amqp://mylogin:mypwd@myhost:4567
        vhost: /myvhost

Sample

deleteRabbitmqQueue("Obi-Wan Kenobi no longer wants to use his powers") {
    queue = "obi-wan_kenobi"
}

Read one message from rabbitMQ queue

This step comes as a parameterized function, the parameterized type is the expected return type for the message to read.
Default return type is ByteArray

Parameters to provide on step

  • name: String? // optional, give a name to your step to make scenario execution more readable

  • retry: String // optional, give a chance for step to fail several times before passing

  • builder: RabbitMQMessageExecutionBuilder.() → Unit // mandatory, configure execution of step
    builder parameters are:

    • queue: String // queue from which read message

    • messageTransformer: String // transformer from ByteArray to expected return type, mandatory if other than ByteArray

    • deleteQueue: Boolean // Should queue be deleted after reading, defaults to false

    • connection: String // optional, connection string to rabbitmq, defaults to amqp://guest:guest@localhost:5672

    • vhost: String // optional, defaults to /

      connection and vhost can be set globally on kest configuration file:

      kest.yml
      rabbitmq:
        connection: amqp://mylogin:mypwd@myhost:4567
        vhost: /myvhost

Sample

givenMessageFromRabbitmqQueue<String> {
        queue = "kest"
        messageTransformer = { toString(Charsets.UTF_8) }
}

N.B: For messages with Json format you may use toJson function, which maps ByteArray to a JsonMap.
See Kest JSON documentation for more details.

Read multiple messages from rabbitMQ

This step comes as a parameterized function, the parameterized type is the expected return type for the message to read.
Default return type is ByteArray

Parameters to provide on step

  • name: String? // optional, give a name to your step to make scenario execution more readable

  • retry: String // optional, give a chance for step to fail several times before passing

  • builder: RabbitMQMessagesExecutionBuilder.() → Unit // mandatory, configure execution of step
    builder parameters are:

    • queue: String // queue from which read message

    • messageTransformer: String // transformer from ByteArray to expected return type, mandatory if other than ByteArray

    • nbMessages: Int // optional number of messages to retrieve, defaults to 1

    • deleteQueue: Boolean // Should queue be deleted after reading, defaults to false

    • connection: String // optional, connection string to rabbitmq, defaults to amqp://guest:guest@localhost:5672

    • vhost: String // optional, defaults to /

      connection and vhost can be set globally on kest configuration file:

      kest.yml
      rabbitmq:
        connection: amqp://mylogin:mypwd@myhost:4567
        vhost: /myvhost

Sample

givenMessagesFromRabbitmqQueue<String> {
        queue = "kest"
        messageTransformer = { toString(Charsets.UTF_8) }
        nbMessages = 2
}

N.B: For messages with Json format you may use toJson function, which maps ByteArray to a JsonMap.
See Kest JSON documentation for more details.

Publish a message on RabbitMQ

Parameters to provide on step

  • name: String? // optional, give a name to your step to make scenario execution more readable

  • retry: String // optional, give a chance for step to fail several times before passing

  • builder: RabbitMQMessageExecutionBuilder.() → Unit // mandatory, configure execution of step
    builder parameters are:

    • message: RabbitMQMessage // mandatory, configuration of message to deliver

      • message: String // mandatory, message to deliver

      • exchange: String? // optional, exchange on which deliver message, defaults to ""

      • routingKey: String // mandatory, routing key for message

      • headers: Map<String, Any> // optional

      • properties: RabbitMQPublicationProperties // optional

        • contentType: String // optional

        • contentEncoding: String // optional

        • deliveryMode: Int // optional

        • priority: Int // optional

        • correlationId: String // optional

        • replyTo: String // optional

        • type: String // optional

        • messageId: String // optional

        • expiration: String // optional time in millis when message will expire

        • timestamp: Date // optional

        • userId: String // optional

        • appId: String // optional

          // RabbitMQMessage may be built by a combination of functions written as follows:
          publish { "message_to_publish" } toExchange "target_exchange" withRoutingKey "routing_key" withHeaders mapOf(
              "header" to "headerValue"
          ) withProperties {
              messageId = "my id"
              expiration = "10000"
          }
    • connection: String // optional, connection string to rabbitmq, defaults to amqp://guest:guest@localhost:5672

    • vhost: String // optional, defaults to /

      connection, vhost and exchange can be set globally on kest configuration file:

      kest.yml
      rabbitmq:
        connection: amqp://mylogin:mypwd@myhost:4567
        vhost: /myvhost
        exchange: my_exchange

Sample

publishRabbitmqMessage("say hello world through universe") {
    publish { """ { "hello": "world" } """ } toExchange "" withRoutingKey "universe"
}

count number of messages in a queue

This step uses RabbitMQ management api, results are not instantaneous, this step should be used carefully regarding of that.

Parameters to provide on step

  • name: String? // optional, give a name to your step to make scenario execution more readable

  • retry: String // optional, give a chance for step to fail several times before passing

  • builder: RabbitMQCountMessagesExecutionBuilder.() → Unit // mandatory, configure execution of step
    builder parameters are:

    • queue: String // queue from which count messages

    • connection: String // optional, connection string to rabbitmq management api, defaults to http://localhost:15672

    • user: String // optional, user to connect to management api, defaults to guest

    • password: String // optional, password to connect to management api, defaults to guest

    • vhost: String // optional, defaults to /

      connection, user, password and vhost can be set globally on kest configuration file:

      kest.yml
      rabbitmq:
        managementapi:
          connection: http://my_host:15672
          user: my_user
          password: my_password
        vhost: /myvhost

Sample

givenNumberOfMessagesInRabbitmqQueue {
    queue = "kest"
}