-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
1,236 additions
and
586 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
engines: | ||
bundler-audit: | ||
enabled: false | ||
csslint: | ||
enabled: false | ||
eslint: | ||
enabled: false | ||
fixme: | ||
enabled: true | ||
rubocop: | ||
enabled: true | ||
ratings: | ||
paths: | ||
- Gemfile.lock | ||
- "**.css" | ||
- "**.js" | ||
- "**.jsx" | ||
- "**.rb" | ||
exclude_paths: | ||
- spec/**/* | ||
- examples/**/* | ||
- test/**/* | ||
- vendor/**/* | ||
- bin/**/* | ||
- .codeclimate.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
Attribute: | ||
enabled: false | ||
TooManyInstanceVariables: | ||
enabled: false | ||
TooManyMethods: | ||
enabled: false | ||
UtilityFunction: | ||
enabled: false | ||
exclude_paths: | ||
- examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,9 @@ AllCops: | |
- vendor/**/** | ||
- examples/**/** | ||
|
||
ClassLength: | ||
Max: 500 | ||
|
||
Documentation: | ||
Enabled: true | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ENV['USE_REDIS'] = 'true' | ||
require_relative './shared_classes' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
require 'bundler/setup' | ||
require 'celluloid_pubsub' | ||
require 'logger' | ||
|
||
debug_enabled = ENV['DEBUG'].present? && ENV['DEBUG'].to_s == 'true' | ||
use_redis = ENV['USE_REDIS'].present? && ENV['USE_REDIS'].to_s == 'true' | ||
log_file_path = File.join(File.expand_path(File.dirname(__FILE__)), 'log', 'celluloid_pubsub.log') | ||
|
||
# actor that subscribes to a channel | ||
class Subscriber | ||
include CelluloidPubsub::BaseActor | ||
|
||
def initialize(options = {}) | ||
@client = CelluloidPubsub::Client.new({ actor: Actor.current, channel: 'test_channel' }.merge(options)) | ||
end | ||
|
||
def on_message(message) | ||
if @client.succesfull_subscription?(message) | ||
puts "subscriber got successful subscription #{message.inspect}" | ||
@client.publish('test_channel2', 'data' => ' subscriber got successfull subscription') # the message needs to be a Hash | ||
else | ||
puts "subscriber got message #{message.inspect}" | ||
end | ||
end | ||
|
||
def on_close(code, reason) | ||
puts "websocket connection closed: #{code.inspect}, #{reason.inspect}" | ||
terminate | ||
end | ||
|
||
|
||
end | ||
|
||
# actor that publishes a message in a channel | ||
class Publisher | ||
include CelluloidPubsub::BaseActor | ||
|
||
def initialize(options = {}) | ||
@client = CelluloidPubsub::Client.new({ actor: Actor.current, channel: 'test_channel2' }.merge(options)) | ||
end | ||
|
||
def on_message(message) | ||
if @client.succesfull_subscription?(message) | ||
puts "publisher got successful subscription #{message.inspect}" | ||
@client.publish('test_channel', 'data' => ' my_message') # the message needs to be a Hash | ||
else | ||
puts "publisher got message #{message.inspect}" | ||
end | ||
end | ||
|
||
def on_close(code, reason) | ||
puts "websocket connection closed: #{code.inspect}, #{reason.inspect}" | ||
terminate | ||
end | ||
|
||
end | ||
|
||
|
||
CelluloidPubsub::BaseActor.setup_actor_supervision(CelluloidPubsub::WebServer, actor_name: :web_server, args: {enable_debug: debug_enabled, use_redis: use_redis,log_file_path: log_file_path }) | ||
CelluloidPubsub::BaseActor.setup_actor_supervision(Subscriber, actor_name: :subscriber, args: {enable_debug: debug_enabled }) | ||
CelluloidPubsub::BaseActor.setup_actor_supervision(Publisher, actor_name: :publisher, args: {enable_debug: debug_enabled }) | ||
|
||
|
||
signal_received = false | ||
|
||
Signal.trap('INT') do | ||
puts "\nAn interrupt signal has been triggered!" | ||
signal_received = true | ||
end | ||
|
||
sleep 0.1 until signal_received | ||
puts 'Exited succesfully! =)' |
Oops, something went wrong.