lib/bunny_mock/channel.rb in bunny-mock-1.6.0 vs lib/bunny_mock/channel.rb in bunny-mock-1.7.0
- old
+ new
@@ -33,11 +33,11 @@
@connection = connection
# initialize exchange and queue storage
@exchanges = {}
@queues = {}
- @acknowledged_state = { pending: {}, acked: {}, nacked: {} }
+ @acknowledged_state = { pending: {}, acked: {}, nacked: {}, rejected: {} }
# set status to opening
@status = :opening
end
@@ -101,10 +101,18 @@
#
def exchange(name, opts = {})
@connection.register_exchange xchg_find_or_create(name, opts)
end
+ # Unique string supposed to be used as a consumer tag.
+ #
+ # @return [String] Unique string.
+ # @api plugin
+ def generate_consumer_tag(name = 'bunny')
+ "#{name}-#{Time.now.to_i * 1000}-#{Kernel.rand(999_999_999_999)}"
+ end
+
##
# Mocks a fanout exchange
#
# @param [String] name Exchange name
# @param [Hash] opts Exchange parameters
@@ -301,16 +309,24 @@
end
nil
end
##
- # Does nothing atm.
+ # Rejects a message. A rejected message can be requeued or
+ # dropped by RabbitMQ.
#
+ # @param [Integer] delivery_tag Delivery tag to reject
+ # @param [Boolean] requeue Should this message be requeued instead of dropping it?
+ #
# @return nil
# @api public
#
- def reject(*)
- # noop
+ def reject(delivery_tag, requeue = false)
+ if @acknowledged_state[:pending].key?(delivery_tag)
+ delivery, header, body = update_acknowledgement_state(delivery_tag, :rejected)
+ delivery.queue.publish(body, header.to_hash) if requeue
+ end
+ nil
end
# @endgroup
#