blastbeat 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Blastbeat
2
2
 
3
- TODO: Write a gem description
3
+ This is a tiny module for easy integration with the BlastBeat server
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,7 +18,16 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ ```ruby
22
+ # connect to a BlastBeat server
23
+ blastbeat = BlastBeat::Node.new('tcp://192.168.173.5:5000', 'FOOBAR1')
24
+
25
+ # send a message to it
26
+ blastbeat.send('', 'pong')
27
+
28
+ # receive a message
29
+ sid, msg_type, msg_body = blastbeat.recv
30
+ ```
22
31
 
23
32
  ## Contributing
24
33
 
data/blastbeat.gemspec CHANGED
@@ -15,5 +15,5 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Blastbeat::VERSION
17
17
 
18
- gem.add_dependency("zmq")
18
+ gem.add_dependency("ffi-rzmq")
19
19
  end
data/lib/blastbeat.rb CHANGED
@@ -1,32 +1,23 @@
1
1
  require "blastbeat/version"
2
- require 'zmq'
2
+ require 'ffi-rzmq'
3
3
 
4
4
  module BlastBeat
5
5
  class Node
6
- def initialize(server, nodename)
7
- context = ZMQ::Context.new()
8
- @socket = context.socket(ZMQ::DEALER)
6
+ def initialize(server, nodename, threads=1)
7
+ @context = ZMQ::Context.create(threads)
8
+ @socket = @context.socket(ZMQ::DEALER)
9
9
  @socket.setsockopt(ZMQ::IDENTITY, nodename)
10
10
  @socket.connect(server)
11
11
  end
12
12
 
13
13
  def recv
14
- parts = []
15
- parts << @socket.recv
16
- if not @socket.getsockopt(ZMQ::RCVMORE)
17
- return nil
18
- end
19
- parts << @socket.recv
20
- if not @socket.getsockopt(ZMQ::RCVMORE)
21
- return nil
22
- end
23
- parts << @socket.recv
14
+ parts = []
15
+ @socket.recv_strings(parts)
16
+ parts
24
17
  end
25
18
 
26
19
  def send(sid, msg_type, msg_body='')
27
- @socket.send(sid, ZMQ::SNDMORE)
28
- @socket.send(msg_type, ZMQ::SNDMORE)
29
- @socket.send(msg_body)
20
+ @socket.send_strings([sid, msg_type, msg_body])
30
21
  end
31
22
 
32
23
  def uwsgi(pkt)
@@ -1,3 +1,3 @@
1
1
  module Blastbeat
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blastbeat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ cert_chain: []
12
12
  date: 2012-08-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: zmq
15
+ name: ffi-rzmq
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements: