diff --git a/lib/bunny-mock.rb b/lib/bunny-mock.rb index 580d8e0..f9e8e78 100644 --- a/lib/bunny-mock.rb +++ b/lib/bunny-mock.rb @@ -17,6 +17,7 @@ require 'bunny_mock/exchanges/topic' require 'bunny_mock/exchanges/fanout' require 'bunny_mock/exchanges/headers' +require 'bunny_mock/exchanges/x_delayed_message' ## # A mock RabbitMQ client based on Bunny diff --git a/lib/bunny_mock/exchange.rb b/lib/bunny_mock/exchange.rb index 009b649..17416f4 100644 --- a/lib/bunny_mock/exchange.rb +++ b/lib/bunny_mock/exchange.rb @@ -22,7 +22,7 @@ def declare(channel, name = '', opts = {}) type = opts.fetch :type, :direct # get needed class type - klazz = BunnyMock::Exchanges.const_get type.to_s.capitalize + klazz = BunnyMock::Exchanges.const_get type.to_s.gsub('-', '_').camelize(:upper) # create exchange of desired type klazz.new channel, name, type, opts diff --git a/lib/bunny_mock/exchanges/x_delayed_message.rb b/lib/bunny_mock/exchanges/x_delayed_message.rb new file mode 100644 index 0000000..1e98c9d --- /dev/null +++ b/lib/bunny_mock/exchanges/x_delayed_message.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true +module BunnyMock + module Exchanges + class XDelayedMessage < BunnyMock::Exchange + # + # API + # + + ## + # Deliver a message to route with direct key match + # + # @param [Object] payload Message content + # @param [Hash] opts Message properties + # @param [String] key Routing key + # + # @api public + # + def deliver(payload, opts, key) + @routes[key].each { |route| route.publish payload, opts } if @routes[key] + end + end + end +end