0

I have a Ruby app that acts as producer, something like this:

class PostNotificationService
  class << self
    def call(notification)
      queue = channel.queue('adyen_notifications', auto_delete: false)
      exchanger = channel.default_exchange

      exchanger.publish(notification, routing_key: queue.name)
    end

    private

    def connection
      @connection ||= Bunny.new(AMQP_URL)
      @connection.start
      @connection
    end

    def channel
      @channel ||= connection.create_channel
      @channel.basic_qos 1
      @channel
    end
  end
end

and I also have a consumer app that spawns 2 workers (consumer)

AMQP_URL = ENV['RABBITMQ_URL'] || 'amqp://guest:guest@localhost:5672'
Sneakers.configure  heartbeat: 2,
                    amqp: AMQP_URL,
                    vhost: '/',
                    workers: 2,
                    exchange_type: :direct,
                    timeout_job_after: 1.minute,
                    prefetch: 1

it works quite fine, but I get the same message two times (on both consumers). I thought that by default rabbitmq would send the message to the consumers using round robin fashion but even with the prefetch option I'm getting 2 messages.

Did I missed something?

Luiz E.
  • 6,769
  • 10
  • 58
  • 98
  • almost entirely sure rabbitMQ doesn't send the *SAME* message twice. that's the whole point of having rabbitMQ. make sure your producer doesn't send the same message twice – nafas Jun 30 '17 at 14:32
  • Yes, I just tested and no, I'm not pushing twice the same message – Luiz E. Jun 30 '17 at 14:53
  • can you use one consumer and check if a message gets pulled twice? – nafas Jun 30 '17 at 15:00
  • the message gets pulled twice, but tbh I don't really think it is "pulled twice". My consumer is fine, also my producer...I think that our payment gateway is sending the notification _twice_ – Luiz E. Jun 30 '17 at 15:06
  • 1
    yeah now that makes sense, its something on the producer side (or whatever calling it). – nafas Jun 30 '17 at 15:15

0 Answers0