celluloid_pubsub 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 504c5b5283795d2b2d0024075b948e9fdc1e33b5
4
- data.tar.gz: a804f7569d91763c96d7c99143cf47bf03172056
3
+ metadata.gz: 7488182bb374aeba0db2f121fc0fb17b2c41560b
4
+ data.tar.gz: 38a24ef56d63549d013f51c76da3a17b3e56edd0
5
5
  SHA512:
6
- metadata.gz: a91dab82e9dfcd1adc0301b97382fa9a128b0f923a68d41050f2cde6d2d6b7a80504ae154b53b23ed64df7bf90ecb24418b6cf2994fa1f37d03a9a45981d542d
7
- data.tar.gz: d37314b65d6d1f86e71807f904d830c37b00395acb988c585335fb13e6718accf4583d8041b5f6e89d6930fe07f1b073addab63ea5c570fc652a4505dc827b5c
6
+ metadata.gz: 3f1875bd87ce12992e24b04c68a3316a70f582d24426e37d029d0f8e1a003b8b05a5571228df7e87c1ab1d9c2b68fed6f75dc8071290aafb676c39d3357d81d7
7
+ data.tar.gz: 0d4832b40b51b555d55b49253002b9f9d155eb1662c257142ecdd1f30cefb2595a15fd6f24a6b4858bf160047be57fec88154dd3f6f501bd98a675b0a83d05ef
data/README.md CHANGED
@@ -8,15 +8,20 @@ Description
8
8
 
9
9
  CelluloidPubsub is a simple ruby implementation of publish subscribe design patterns using celluloid actors and websockets, using Celluloid::Reel server
10
10
 
11
+ Starting with version 0.4.0, Redis support was added [courtesy of em-hiredis](https://github.com/mloughran/em-hiredis)
12
+
11
13
  Requirements
12
14
  ------------
13
15
 
14
16
  1. [Ruby 1.9.x or Ruby 2.x.x](http://www.ruby-lang.org)
15
17
  2. [Celluloid >= 0.16.0](https://github.com/celluloid/celluloid)
16
18
  3. [Celluloid-IO >= 0.16.2](https://github.com/celluloid/celluloid-io)
17
- 4. [Reel >= 0.5.0](https://github.com/celluloid/reel)
18
- 5. [Celluloid-websocket-client = 0.0.1](https://github.com/jeremyd/celluloid-websocket-client)
19
- 6. [ActiveSuport >= 4.2.0](https://rubygems.org/gems/activesupport)
19
+ 4. [Reel >= 0.6.0](https://github.com/celluloid/reel)
20
+ 5. [http >= 1.0.2](https://github.com/httprb/http)
21
+ 6. [Celluloid-websocket-client = 0.0.1](https://github.com/jeremyd/celluloid-websocket-client)
22
+ 7. [ActiveSuport >= 4.2.0](https://rubygems.org/gems/activesupport)
23
+ 8. [em-hiredis >= 0.3.0](https://github.com/mloughran/em-hiredis)
24
+ 9. [json >= 1.8.3](https://github.com/flori/json)
20
25
 
21
26
  Compatibility
22
27
  -------------
@@ -38,6 +43,71 @@ Add the following to your Gemfile:
38
43
 
39
44
  Please read [Release Details](https://github.com/bogdanRada/celluloid_pubsub/releases) if you are upgrading. We break backward compatibility between large ticks but you can expect it to be specified at release notes.
40
45
 
46
+ Usage
47
+ -----
48
+
49
+ Creating a websocket server is simple as doing this. This are all the options available with their default values.
50
+
51
+ ```ruby
52
+ CelluloidPubsub::WebServer.supervise_as(:web_server,
53
+ enable_debug: true, # if debug messages should be logged
54
+ use_redis: false , # if set to true, will instantiate a RedisReactor class to handle each connection, which requires Redis to be available. Otherwise will use a simple Reactor to handle the connections which has no dependencies .
55
+ log_file_path: "path/to/log_file.log", # The log file where all debugging information will be printed
56
+ hostname: "0.0.0.0", # the hostname of the server.
57
+ port: 1234, # the port on which the server will listen for connections
58
+ path: '/ws', # the relative path used in the URL where connections are allowed to connect
59
+ spy: false, # whether to spy all internal Websocket connections in order to get more debugging information
60
+ backlog: 1024 # the number of connections allowed to be connected to the server at a certain time
61
+ )
62
+ ```
63
+
64
+ Creating a client is simple as doing this. If you provide the channel when you initialize the **CelluloidPubsub::Client** it will automatically start the subscription to that channel. But sometimes, you might want to subscribe at a later time, so you can just omit the channel when you initialize the client, and use instead **@client.subscribe('test_channel')**. After the subscription has started, the client must implement the method **on_message** and the **on_close** method (called when client disconnects from the channel). The method **on_message** will receive all incoming messages from the server. You can test if the subscription was successful by doing this **@client.succesfull_subscription?(message)**.
65
+
66
+ ```ruby
67
+ class MyAwesomeClient
68
+ include Celluloid
69
+ include Celluloid::Logger
70
+
71
+ def initialize(options = {})
72
+ @client = CelluloidPubsub::Client.new({
73
+ actor: Actor.current,
74
+ channel: 'test_channel', # the channel to which this client will subscribe to.
75
+ log_file_path: "path/to/log_file.log", # The log file where all debugging information will be printed
76
+ hostname: "0.0.0.0", # the hostname of the server.
77
+ port: 1234,# the port on which the connection will be made to
78
+ path: '/ws', # the relative path used in the URL where the connection will be connecting to
79
+ enable_debug: false # if debug messages should be logged
80
+ }.merge(options))
81
+ end
82
+
83
+ def on_message(message)
84
+ if @client.succesfull_subscription?(message)
85
+ puts "subscriber got successful subscription #{message.inspect}"
86
+ @client.publish('test_channel2', 'data' => ' subscriber got successfull subscription') # the message needs to be a Hash
87
+ else
88
+ puts "subscriber got message #{message.inspect}"
89
+ end
90
+ end
91
+
92
+ def on_close(code, reason)
93
+ puts "websocket connection closed: #{code.inspect}, #{reason.inspect}"
94
+ terminate
95
+ end
96
+
97
+
98
+ end
99
+
100
+ ```
101
+
102
+ The methods available that the **CelluloidPubsub::Client** instance can execute are:
103
+
104
+ - subscribe -- subscribe - accepts a string as a channel name
105
+ - publish - accepts a string as a channel name, and a Hash object
106
+ - unsubscribe - accepts a string as a channel_name from which the client will unsubscribe from
107
+ - unsubscribe_clients - accepts a string as a channel_name . This will disconnect all clients that are subscribed to that channel.
108
+ - unsubscribe_all - This does not have any parameters. Will unsubscribe all clients from all channnels
109
+ - on_close - This accepts a code and a reason as parameters. This method will be called when the client disconnects from the channel.
110
+
41
111
  Examples
42
112
  --------
43
113
 
@@ -0,0 +1,15 @@
1
+ require 'reel/spy'
2
+ Reel::Spy::Colors.class_eval do
3
+ alias_method :original_colorize, :colorize
4
+
5
+ def colorize(n, str)
6
+ force_utf8_encoding(str)
7
+ end
8
+
9
+ # Returns utf8 encoding of the msg
10
+ # @param [String] msg
11
+ # @return [String] ReturnsReturns utf8 encoding of the msg
12
+ def force_utf8_encoding(msg)
13
+ msg.respond_to?(:force_encoding) && msg.encoding.name != 'UTF-8' ? msg.force_encoding('UTF-8') : msg
14
+ end
15
+ end
@@ -17,7 +17,7 @@ module CelluloidPubsub
17
17
  # minor release version
18
18
  MINOR = 5
19
19
  # tiny release version
20
- TINY = 0
20
+ TINY = 1
21
21
  # prelease version ( set this only if it is a prelease)
22
22
  PRE = nil
23
23
 
@@ -48,6 +48,11 @@ module CelluloidPubsub
48
48
  super(hostname, port, { spy: spy, backlog: backlog }, &method(:on_connection))
49
49
  end
50
50
 
51
+ def run
52
+ @spy = Celluloid.logger
53
+ loop { async.handle_connection @server.accept }
54
+ end
55
+
51
56
  # the method will return true if redis can be used otherwise false
52
57
  #
53
58
  #
@@ -4,4 +4,5 @@ require 'reel'
4
4
  require 'celluloid/websocket/client'
5
5
  require 'active_support/all'
6
6
  require 'json'
7
+ Gem.find_files('celluloid_pubsub/initializers/**/*.rb').each { |path| require path }
7
8
  Gem.find_files('celluloid_pubsub/**/*.rb').each { |path| require path }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: celluloid_pubsub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - bogdanRada
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-15 00:00:00.000000000 Z
11
+ date: 2016-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: celluloid
@@ -398,6 +398,7 @@ files:
398
398
  - lib/celluloid_pubsub.rb
399
399
  - lib/celluloid_pubsub/client.rb
400
400
  - lib/celluloid_pubsub/helper.rb
401
+ - lib/celluloid_pubsub/initializers/reel_colors.rb
401
402
  - lib/celluloid_pubsub/reactor.rb
402
403
  - lib/celluloid_pubsub/redis_reactor.rb
403
404
  - lib/celluloid_pubsub/registry.rb