Logo: Relish

  1. Sign in

Project: Message-driver 0.7

Middleware Parameters

  • @bunny
  • @in_memory

You can provide parameters to your middleware by passing them as additional
paremeters to the append and prepend calls.

Background
Given
I am connected to the broker
And
I have a destination :middleware_queue with no messages on it
And
I have a middleware class
class ParameterizedMiddleware < MessageDriver::Middleware::Base

  attr_reader :prefix, :seperator

  def initialize(destination, prefix, seperator)
    super(destination)
    @prefix = prefix
    @seperator = seperator
  end

  def on_publish(body, headers, properties)
    ["#{prefix}#{seperator}#{body}", headers, properties]
  end
end
Scenarios
Adding a parameterized middleware to the stack
When
I execute the following code
destination = MessageDriver::Client.find_destination(:middleware_queue)
destination.middleware.append ParameterizedMiddleware, 'pub_pre', ':'
And
I send the following messages to :middleware_queue
body
Test Message 1
Test Message 2
Then
I expect to find the following 2 messages on :middleware_queue
raw_body
pub_pre:Test Message 1
pub_pre:Test Message 2

Last published over 3 years ago by soupmatt.