Giter Club home page Giter Club logo

Comments (12)

michaelklishin avatar michaelklishin commented on August 28, 2024

One thing I don't see in your code is where you cancel your consumer (unsubscribe). Another thing I need you to provide is RabbitMQ version you use. Thanks.

from bunny.

MikeEmery avatar MikeEmery commented on August 28, 2024

Oh sorry, I'm using RabbitMQ 2.6.1.

 q.subscribe( :timeout => 5, :message_max => 1 ) do |msg|

:message_max has the call to subscribe unsubscribe after it receives arg number of messages (in this case 1).

From lib/qrack/subscription.rb

def start(blk&)

...

     # If block present, pass the message info to the block for processing
    blk.call({:header => header, :payload => msg, :delivery_details => method.arguments}) if !blk.nil?

    # Exit loop if message_max condition met
    if (!message_max.nil? and message_count == message_max)
      # Stop consuming messages
      queue.unsubscribe()
      # Acknowledge receipt of the final message
      queue.ack() if @ack
      # Quit the loop
      break
    end
end

from bunny.

MikeEmery avatar MikeEmery commented on August 28, 2024

Woops, didn't mean to close it.

from bunny.

michaelklishin avatar michaelklishin commented on August 28, 2024

Gotcha, thank you.

from bunny.

skaes avatar skaes commented on August 28, 2024

The whole bunny logic regarding message_max and unsubscribing from queues seems to be inherently flawed.

As I see it, there is no guarantee that the response from the broker on sending a Cancel frame will be a CancelOK frame.

It could also be the next message already queued up for the client, which seems to be what's happening here.

The broker will eventually stop sending messages, but not immediately.

Which means major refactoring of the bunny code is required.

from bunny.

skaes avatar skaes commented on August 28, 2024

In other words: bunny is OK for publishing, but for writing subscribers you're much better off using the amq gem.

from bunny.

celldee avatar celldee commented on August 28, 2024

The subscription stuff only works if you use the qos method so that you receive messages in the necessary order. This gist has some examples that I think still work. https://gist.github.com/185144

from bunny.

skaes avatar skaes commented on August 28, 2024

I have already tried using prefetch_count=1. But it did not work for me.

It might be that you also need to use ack=true.

from bunny.

celldee avatar celldee commented on August 28, 2024

Yes, you do need ack=true otherwise qos will not work.

from bunny.

celldee avatar celldee commented on August 28, 2024

I would only use Bunny subscription if your needs are pretty basic. Otherwise, I would go with the amqp gem.

from bunny.

michaelklishin avatar michaelklishin commented on August 28, 2024

And if you choose to go with the amqp gem, please check out amqp gem documentation.

from bunny.

skaes avatar skaes commented on August 28, 2024

Indeed, if you set :prefetch_count to 1 and pass :ack => true, then everything is OK:

require 'rubygems'
require 'bunny'

b = Bunny.new(:host => '127.0.0.1', :logging => false)
b.start
b.qos(:prefetch_count => 1)

exchange = b.exchange('')

q = b.queue(nil, :exclusive => false)

exchange.publish('abc', :key => q.name)
exchange.publish('def', :key => q.name)


puts '.'

q.subscribe( :timeout => 5, :message_max => 1, :ack => true ) do |msg|
  puts msg[:payload]
end


puts '.'

from bunny.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.