Skip to content

Commit

Permalink
Fixes to RDY and go away from Rails dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphaB committed Jun 9, 2014
1 parent 70974a8 commit 9074819
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
5 changes: 3 additions & 2 deletions lib/nsqrb.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# encoding: utf-8

require 'nsqrb'
require 'nsqrb/command'
require 'nsqrb/frame'
require 'nsqrb/frame/error'
Expand All @@ -9,6 +7,9 @@
require 'nsqrb/parser'
require 'nsqrb/consumer'
require 'nsqrb/producer'
require 'nsqrb/version'

require 'json'

Dir[File.dirname(__FILE__) + '/nsqrb/command/*.rb'].each {|file| require file }

Expand Down
2 changes: 1 addition & 1 deletion lib/nsqrb/command/identify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def to_line
hash[key] = @args[key] if @args[key].nil?
hash
end
payload = MultiJson.dump(filtered)
payload = JSON.dump(filtered)
[name, "\n", payload.length, payload].pack('a*a*l>a*')
end

Expand Down
12 changes: 11 additions & 1 deletion lib/nsqrb/consumer.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
require 'socket'

module Nsqrb
class Consumer
attr_reader :options, :messages, :errors, :responses

TCP_BUFFER = 64.kilobytes
TCP_BUFFER = 64 * 1024
PROTOCOL_VERSION = "v2"

def initialize(options = {})
Expand All @@ -27,14 +29,17 @@ def receive

def confirm(message)
@socket.write Command::Fin.new(message_id: message.id).to_line
update_rdy
end

def requeue(message, timeout = 0)
@socket.write Command::Req.new(message_id: message.id, timeout: timeout).to_line
update_rdy
end

def touch(message)
@socket.write Command::Touch.new(message_id: message.id).to_line
update_rdy
end

def close!
Expand All @@ -56,6 +61,11 @@ def connect!

private


def update_rdy
@socket.write Command::Rdy.new(count: 1).to_line
end

def identify_defaults
return @identify_defaults if @identify_defaults
@identify_defaults = {
Expand Down
2 changes: 2 additions & 0 deletions lib/nsqrb/frame.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'ostruct'

module Nsqrb
class Frame < OpenStruct
end
Expand Down
2 changes: 2 additions & 0 deletions lib/nsqrb/producer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'net/http'

module Nsqrb
class Producer
def initialize(host, port, topic)
Expand Down
2 changes: 1 addition & 1 deletion lib/nsqrb/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Nsqrb
VERSION = "0.0.1"
VERSION = "0.0.2"
end

0 comments on commit 9074819

Please sign in to comment.