celluloid_pubsub 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +1 -1
- data/examples/simple_test.rb +38 -0
- data/lib/celluloid_pubsub/client_pubsub.rb +12 -4
- data/lib/celluloid_pubsub/version.rb +1 -1
- data/lib/celluloid_pubsub/web_server.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cadbce82ae6b66ea77ba768fe90ec8fbc761bb1
|
4
|
+
data.tar.gz: ac2d82051f17463fe80dc83950dede59c4e38efa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2b707bfc85a7abc10ec2705dbf56dfa971fb44b33616e060520cc989a48fb492062c5ec4979d0b0c07333908e3b8ea81e369c8c5eabfddbc7c43f7e3dd859a3
|
7
|
+
data.tar.gz: 547377d28faf751328c4304dad0a644fed6239d3ffcb45b083cbbc1d4005bdf395b1957b59c017255100f2a622727db153dd810627dc62b3270fac0dafeca4c5
|
data/README.rdoc
CHANGED
@@ -17,7 +17,7 @@ CelluloidPubsub is a simple ruby implementation of publish subscribe design patt
|
|
17
17
|
3. {Celluloid-IO >= 0.16.2}[https://github.com/celluloid/celluloid-io]
|
18
18
|
4. {Reel >= 0.5.0}[https://github.com/celluloid/reel]
|
19
19
|
5. {Celluloid-websocket-client = 0.0.1}[https://github.com/jeremyd/celluloid-websocket-client]
|
20
|
-
6. {ActiveSuport
|
20
|
+
6. {ActiveSuport >= 4.2.0}[https://rubygems.org/gems/activesupport]
|
21
21
|
|
22
22
|
= Compatibility
|
23
23
|
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'celluloid_pubsub'
|
3
|
+
|
4
|
+
class Subscriber
|
5
|
+
include Celluloid
|
6
|
+
include Celluloid::Logger
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
CelluloidPubsub::Client.connect(actor: Actor.current) do |ws|
|
10
|
+
ws.subscribe('test_channel') # this will execute after the connection is opened
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def on_message(message)
|
15
|
+
puts "got #{message.inspect}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def on_close(code, reason)
|
19
|
+
puts "websocket connection closed: #{code.inspect}, #{reason.inspect}"
|
20
|
+
terminate
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Publisher
|
25
|
+
include Celluloid
|
26
|
+
include Celluloid::Logger
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
CelluloidPubsub::Client.connect(actor: Actor.current) do |ws|
|
30
|
+
ws.publish('test_channel', 'data' => 'my_message') # the message needs to be a Hash
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
CelluloidPubsub::WebServer.supervise_as(:web_server)
|
36
|
+
Subscriber.supervise_as(:subscriber)
|
37
|
+
Publisher.supervise_as(:publisher)
|
38
|
+
sleep
|
@@ -3,14 +3,22 @@ module CelluloidPubsub
|
|
3
3
|
class PubSubWorker
|
4
4
|
include Celluloid
|
5
5
|
include Celluloid::Logger
|
6
|
-
attr_accessor :actor, :connect_blk, :
|
6
|
+
attr_accessor :actor, :connect_blk, :client, :options, :hostname, :port, :path
|
7
7
|
|
8
8
|
def initialize(options, &connect_blk)
|
9
|
-
options
|
10
|
-
@actor = options['actor'].present? ? options['actor'] : nil
|
9
|
+
parse_options(options)
|
11
10
|
raise "#{self}: Please provide an actor in the options list!!!" if @actor.blank?
|
12
11
|
@connect_blk = connect_blk
|
13
|
-
@client = Celluloid::WebSocket::Client.new("ws://#{
|
12
|
+
@client = Celluloid::WebSocket::Client.new("ws://#{@hostname}:#{@port}#{@path}", Actor.current)
|
13
|
+
end
|
14
|
+
|
15
|
+
def parse_options(options)
|
16
|
+
raise 'Options is not a hash' unless options.is_a?(Hash)
|
17
|
+
@options = options.stringify_keys!
|
18
|
+
@actor = @options.fetch('actor', nil)
|
19
|
+
@hostname = @options.fetch('hostname', CelluloidPubsub::WebServer::HOST)
|
20
|
+
@port = @options.fetch('port', CelluloidPubsub::WebServer::PORT)
|
21
|
+
@path = @options.fetch('path', CelluloidPubsub::WebServer::PATH)
|
14
22
|
end
|
15
23
|
|
16
24
|
def debug_enabled?
|
@@ -17,7 +17,7 @@ module CelluloidPubsub
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def parse_options(options)
|
20
|
-
raise 'Options is not a hash
|
20
|
+
raise 'Options is not a hash ' unless options.is_a?(Hash)
|
21
21
|
@options = options.stringify_keys
|
22
22
|
@backlog = @options.fetch(:backlog, 1024)
|
23
23
|
@hostname = @options.fetch(:hostname, CelluloidPubsub::WebServer::HOST)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: celluloid_pubsub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bogdanRada
|
@@ -413,6 +413,7 @@ files:
|
|
413
413
|
- bin/yardstick
|
414
414
|
- bin/yri
|
415
415
|
- celluloid_pubsub.gemspec
|
416
|
+
- examples/simple_test.rb
|
416
417
|
- init.rb
|
417
418
|
- lib/celluloid_pubsub.rb
|
418
419
|
- lib/celluloid_pubsub/client_pubsub.rb
|