"KRAKOW! KRAKOW! Two direct hits!"
require 'krakow'
producer = Krakow::Producer.new(
:host => 'HOST',
:port => 'PORT',
:topic => 'target'
)
producer.write('KRAKOW!', 'KRAKOW!')
require 'krakow'
consumer = Krakow::Consumer.new(
:nsqlookupd => 'http://HOST:PORT',
:topic => 'target',
:channel => 'ship'
)
consumer.queue.size # => 2
2.times do
msg = consumer.queue.pop
puts "Received: #{msg}"
consumer.confirm(msg.message_id)
end
It's a Ruby library for NSQ using Celluloid under the hood.
Yep, that's right. Just one lowly message at a time. And that's probably not what you want, so adjust it when you create your consumer instance.
require 'krakow'
consumer = Krakow::Consumer.new(
:nsqlookupd => 'http://HOST:PORT',
:topic => 'target',
:channel => 'ship',
:max_in_flight => 30
)
Since Celluloid is in use under the hood, and the main interaction points are
Actors (Consumer
and Producer
) you'll need to be sure you clean up. This simply
means terminating the instance (since falling out of scope will not cause it to be
garbage collected).
consumer = Krakow::Consumer.new(
:nsqlookupd => 'http://HOST:PORT',
:topic => 'target',
:channel => 'ship',
:max_in_flight => 30
)
# do stuff
consumer.terminate
Sure:
Krakow::Utils::Logging.level = :warn # :debug / :info / :warn / :error / :fatal
Because forcing starvation is mean.
Fine!
consumer = Krakow::Consumer.new(
:host => 'HOST',
:port => 'PORT',
:topic => 'target',
:channel => 'ship',
:max_in_flight => 30
)
Great for testing, but you really should use the lookup service in the "real world"
NSQ has this backoff notion. It's pretty swell. Basically, if messages from a specific producer get re-queued (fail), then message consumption from that producer is halted, and slowly ramped back up. It gives time for downstream issues to work themselves out, if possible, instead of just keeping the firehose of gasoline on. Neat.
By default backoff support is disabled. It can be enabled by setting the :backoff_interval
when constructing the Consumer
. The interval is in seconds (and yes, floats are allowed
for sub-second intervals):
consumer = Krakow::Consumer.new(
:nsqlookupd => 'http://HOST:PORT',
:topic => 'target',
:channel => 'ship',
:max_in_flight => 30,
:backoff_interval => 1
)
OK!
consumer = Krakow::Consumer.new(
:nsqlookupd => 'http://HOST:PORT',
:topic => 'target',
:channel => 'ship',
:connection_features => {
:tls_v1 => true
}
)
OK!
consumer = Krakow::Consumer.new(
:nsqlookupd => 'http://HOST:PORT',
:topic => 'target',
:channel => 'ship',
:connection_features => {
:snappy => true
}
)
OK!
consumer = Krakow::Consumer.new(
:nsqlookupd => 'http://HOST:PORT',
:topic => 'target',
:channel => 'ship',
:connection_features => {
:deflate => true
}
)
Create an issue on the github repository.
Create an issue, or even better, send a PR. Just base it off the develop
branch.
- Repo: https://github.com/chrisroberts/krakow
- IRC: Freenode @ spox