Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for delayed message exchange #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/bunny-mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/bunny_mock/exchange.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions lib/bunny_mock/exchanges/x_delayed_message.rb
Original file line number Diff line number Diff line change
@@ -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