Comments (12)
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.
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.
Woops, didn't mean to close it.
from bunny.
Gotcha, thank you.
from bunny.
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.
In other words: bunny is OK for publishing, but for writing subscribers you're much better off using the amq gem.
from bunny.
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.
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.
Yes, you do need ack=true otherwise qos will not work.
from bunny.
I would only use Bunny subscription if your needs are pretty basic. Otherwise, I would go with the amqp gem.
from bunny.
And if you choose to go with the amqp gem, please check out amqp gem documentation.
from bunny.
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)
- losing published messages HOT 2
- Gem includes test certificates HOT 3
- Cannot subscribe to existing queue with no configure permission HOT 2
- Redeliver publisher confirms acks again and again from 0 till current tag HOT 4
- Binding a queue to same exchange twice but using different routing keys not working as expected HOT 1
- any plans to support the new rabbitMQ stream plugin with RabbitMQ 3.9? HOT 4
- Queue subscribe: Calling thread is no longer blocked after connection failure HOT 2
- TLS 1.3 support HOT 2
- QueueDeclare / Timeout issue
- Bunny does not recover from Rabbitmq Broker restart but reconnects on manual restart of service
- Confusion of parameters
- NameError: uninitialized constant OpenSSL::SSL::TLS1_3_VERSION (bunny-2.20.0, ruby 2.6) HOT 4
- Bunny::Channel#quorum_queue does not result in a QQ declaration
- Conditionally alias constants for TLSv1.3 to support older OpenSSL releases
- OpenSSL error is causing unrecoverable issue HOT 1
- Bunny::Channel#default_exchange returns a new object each time
- Missing client notification when recovery fails (after specified recovery attempts) HOT 1
- Reader Loop: undefined method handle_frameset for nil:NilClass
- Heartbeat sender uses Time.now which is unreliable HOT 6
- Channel callback from delivery acknowledgement timeout.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bunny.