rcom 0.0.3 → 0.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4a59231e2507f9f5010d142bfeb28efeba2e8e6
4
- data.tar.gz: a141a111f2e29d337ddcad3a60626885e88430bb
3
+ metadata.gz: 961e69a1d381ea475b48b4e32d832cd2681d3f26
4
+ data.tar.gz: e2b0f139d952fd0cb9f18058f58362fa4c89f925
5
5
  SHA512:
6
- metadata.gz: b7c512e707d70fb3520bcfab86146053b14949d9d28fb3ed3a73268d1ed5df04c337f7a4766d38d5d4b7480d7e68535ac31870868fd5bc42dff2548fc5288d28
7
- data.tar.gz: cf8fe056685e4024d07f5e0829c9f5c911303e75ce5b1f7254796c3a755660041fd4971a60ea353e6c3a7c5b865a0e566d15e0fedeb70831133c091323927ed3
6
+ metadata.gz: adbc997033ab5010d3ce09a0fadc1d47b0675e51a5fdde33df92b67a4a6d15a0452a2bff34e0c06cfd928373d1ec9e879bb5fd40bd3072bbd2a92b969fa6ef0c
7
+ data.tar.gz: 6c3768301c0079b53bf41fae0495f81222d38c9fcef354933b3ef2121082b43c8a6ef1cd972b6f0272466b33f579817655e42b9f215b6cbee1d2da853e997668
data/README.md CHANGED
@@ -18,7 +18,7 @@ gem 'rcom'
18
18
 
19
19
  ## Usage.
20
20
 
21
- Rcom supports the request-response, publish-subscribe and task queues patterns for inter-service messaging. Publishers are non-blocking, subscribers/consumers are blocking and should be run as independent processes. Processes communicate using MessagePack internally.
21
+ Rcom supports the request-response, publish-subscribe and task queue patterns for inter-service messaging. Publishers are non-blocking, subscribers/consumers are blocking and should be run as independent processes. Processes communicate using MessagePack internally.
22
22
 
23
23
  ### Node.
24
24
 
@@ -35,7 +35,7 @@ node = Rcom::Node.new('local').connect
35
35
 
36
36
  ### Topics.
37
37
 
38
- One service might need to update many different services about an event, following the publish-subscribe pattern. You can publish and subscribe to topics on a node, specifying a key.
38
+ One service might need to update many different services about an event, following the publish-subscribe pattern. You can publish and subscribe to topics on a node, specifying a channel.
39
39
 
40
40
  - Publisher.
41
41
 
@@ -46,7 +46,7 @@ message = {
46
46
  }
47
47
 
48
48
  node = Rcom::Node.new('local').connect
49
- topic = Rcom::Topic.new(node: node, key: 'users')
49
+ topic = Rcom::Topic.new(node: node, channel: 'users')
50
50
 
51
51
  topic.publish(message)
52
52
  ```
@@ -55,7 +55,7 @@ topic.publish(message)
55
55
 
56
56
  ```ruby
57
57
  node = Rcom::Node.new('local').connect
58
- topic = Rcom::Topic.new(node: node, key: 'users')
58
+ topic = Rcom::Topic.new(node: node, channel: 'users')
59
59
 
60
60
  topic.subscribe do |message|
61
61
  p message
@@ -64,7 +64,7 @@ end
64
64
 
65
65
  ## Tasks.
66
66
 
67
- A service might need to push expensive tasks into a queue and forget about them. Tasks will be processed by consumers listening to the queue.
67
+ A service might need to push consuming tasks into a queue and forget about them. Tasks will be processed by consumers listening to the queue.
68
68
 
69
69
  - Publisher.
70
70
 
@@ -75,7 +75,7 @@ message = {
75
75
  }
76
76
 
77
77
  node = Rcom::Node.new('local').connect
78
- messages = Rcom::Task.new(node: node, queue: 'messages')
78
+ messages = Rcom::Task.new(node: node, channel: 'messages')
79
79
 
80
80
  messages.publish(message)
81
81
  ```
@@ -84,7 +84,7 @@ messages.publish(message)
84
84
 
85
85
  ```ruby
86
86
  node = Rcom::Node.new('local').connect
87
- messages = Rcom::Task.new(node: node, queue: 'messages')
87
+ messages = Rcom::Task.new(node: node, channel: 'messages')
88
88
 
89
89
  messages.subscribe do |message|
90
90
  sleep 1
@@ -94,37 +94,37 @@ end
94
94
 
95
95
  ## RPC, requests and responses.
96
96
 
97
- In some cases services need real time informations from other services that can't be asynchronously processed. A service can create a request on a route. The other service listening on the same route will reply to the request.
97
+ In some cases services need real time informations from other services that can't be asynchronously processed. A service can request informations on a channel. The other service listening on the same route will reply to the request.
98
98
 
99
- - Publisher.
99
+ - Request.
100
100
 
101
101
  ```ruby
102
- message = {
103
- route: 'user.key',
104
- args: 1
105
- }
106
-
107
102
  node = Rcom::Node.new('local').connect
108
- auth = Rcom::Rpc.new(node: node, service: 'auth')
103
+ service = Rcom::Request.new(node: node, channel: 'auth')
109
104
 
110
- auth.request(message)
105
+ service.get_key(user: 1)
111
106
  ```
112
107
 
113
- - Consumer.
108
+ - Response.
114
109
 
115
110
  ```ruby
116
111
  node = Rcom::Node.new('local').connect
117
- auth = Rcom::Rpc.new(node: node, service: 'auth')
118
112
 
119
- auth.subscribe do |request|
120
- request.on('user.key') do |params|
121
- request.reply = 'xxxccc'
122
- end
123
-
124
- request.on('user.password') do |params|
125
- request.reply = 'not authorized'
113
+ class Server
114
+ def get_key(params)
115
+ user = params[:user]
116
+ return nil unless user == 1
117
+ return 'xxxccc'
126
118
  end
127
119
  end
120
+
121
+ service = Rcom::Response.new(
122
+ node: node,
123
+ channel: 'auth',
124
+ server: Server.new
125
+ )
126
+
127
+ service.serve
128
128
  ```
129
129
 
130
130
  ## Test.
data/lib/rcom/node.rb CHANGED
@@ -1,18 +1,12 @@
1
1
  module Rcom
2
- # A node represents a Redis server and has an uri.
3
2
  class Node
4
- # @return [String]
5
3
  attr_reader :uri
6
4
 
7
- # @param uri [String] Example: 'local'
8
- # @raise [ArgumentError] uri is not in .env.
9
5
  def initialize(uri)
10
6
  raise ArgumentError unless ENV[uri.upcase]
11
7
  @uri = ENV[uri.upcase]
12
8
  end
13
9
 
14
- # Connects to Redis.
15
- # @return [Redis]
16
10
  def connect
17
11
  Redis.new(url: uri)
18
12
  end
data/lib/rcom/rpc.rb CHANGED
@@ -1,79 +1,68 @@
1
1
  module Rcom
2
- # Rpc implements the request/response pattern.
3
- class Rpc
4
- # @return [Rcom::Node]
5
- attr_reader :node
6
- # @return [String]
7
- attr_reader :service
2
+ class Request
3
+ attr_reader :node, :channel
8
4
 
9
- # @param params [Hash]
10
- # @option params :node [Rcom::Node] Example: Rcom::Node.new('local').connect
11
- # @option params :service [String] Example: 'auth'
12
5
  def initialize(params)
13
6
  @node = params[:node]
14
- @service = params[:service]
7
+ @channel = params[:channel]
15
8
  end
16
9
 
17
- # @param params [Hash]
18
- # @option params :route [String] Example: 'users.key'
19
- # @option params :args Example: 1
20
- # @return [reply, nil] Returns the reply or nil if the
21
- # request can't be processed.
22
- def request(params)
10
+ def method_missing(name, args)
23
11
  begin
24
12
  request = {
25
13
  id: SecureRandom.hex,
26
- route: params[:route],
27
- args: params[:args] || ''
14
+ method: name,
15
+ args: args || ''
28
16
  }
29
17
 
30
- node.rpush(service, request.to_msgpack)
18
+ node.rpush(channel, request.to_msgpack)
31
19
  ch, response = node.brpop(request[:id], timeout=10)
32
20
 
33
- MessagePack.unpack(
34
- response,
35
- symbolize_keys: true
36
- )
21
+ MessagePack.unpack(response, symbolize_keys: true)
37
22
  rescue
38
23
  return nil
39
24
  end
40
25
  end
26
+ end
27
+
28
+ class Response
29
+ attr_reader :node, :channel, :server
41
30
 
42
- # Subscribe to the service and listen to requests.
43
- # @yieldparam router [Rcom::Router] A router to match the request.
44
- def subscribe
31
+ def initialize(params)
32
+ @node = params[:node]
33
+ @channel = params[:channel]
34
+ @server = params[:server]
35
+ end
36
+
37
+ def serve
45
38
  begin
46
39
  loop do
47
- ch, request = node.brpop(service)
40
+ ch, request = node.brpop(channel)
48
41
 
49
42
  message = MessagePack.unpack(
50
43
  request,
51
44
  symbolize_keys: true
52
45
  )
53
- router = Rcom::Router.new(message)
54
-
55
- yield router
46
+ response = send_method(
47
+ message[:method],
48
+ message[:args]
49
+ )
56
50
 
57
- node.rpush(message[:id], router.reply.to_msgpack)
51
+ node.rpush(message[:id], response.to_msgpack)
58
52
  end
53
+ rescue
54
+ sleep 1
55
+ retry
59
56
  rescue Interrupt => _
60
57
  end
61
58
  end
62
- end
63
-
64
- # A router can match on a particular route.
65
- class Router
66
- attr_accessor :message, :reply
67
-
68
- # @param message [Hash] The message received with the request.
69
- def initialize(message)
70
- @message = message
71
- end
72
59
 
73
- # @yieldparam args
74
- def on(route)
75
- return nil unless message[:route] == route
76
- yield message[:args]
60
+ def send_method(method, args)
61
+ begin
62
+ server.send(method, args)
63
+ rescue
64
+ return nil
65
+ end
77
66
  end
78
67
  end
79
68
  end
data/lib/rcom/task.rb CHANGED
@@ -1,32 +1,25 @@
1
1
  module Rcom
2
- # Implements tasks and queues.
3
2
  class Task
4
- attr_reader :node, :queue
3
+ attr_reader :node, :channel
5
4
 
6
- # @param params [Hash]
7
- # @option params :node [Rcom::Node]
8
- # @option params :queue [String] Example: 'messages'
9
5
  def initialize(params)
10
6
  @node = params[:node]
11
- @queue = params[:queue]
7
+ @channel = params[:channel]
12
8
  end
13
9
 
14
- # @param message [Hash]
15
- # @return [true, nil] True if the message can be queued, otherwise nil.
16
10
  def publish(message)
17
11
  begin
18
- node.lpush(queue, message.to_msgpack)
12
+ node.lpush(channel, message.to_msgpack)
19
13
  return true
20
14
  rescue
21
15
  return nil
22
16
  end
23
17
  end
24
18
 
25
- # @yieldparam message [Hash] the message received.
26
19
  def subscribe
27
20
  begin
28
21
  loop do
29
- ch, request = node.brpop(queue)
22
+ ch, request = node.brpop(channel)
30
23
  message = MessagePack.unpack(
31
24
  request,
32
25
  symbolize_keys: true
data/lib/rcom/topic.rb CHANGED
@@ -1,31 +1,24 @@
1
1
  module Rcom
2
- # Implements pub/sub over topics.
3
2
  class Topic
4
- attr_reader :node, :key
3
+ attr_reader :node, :channel
5
4
 
6
- # @param params [Hash]
7
- # @option params :node [Rcom::Node]
8
- # @option params :key [String] Example: 'services'
9
5
  def initialize(params)
10
6
  @node = params[:node]
11
- @key = params[:key]
7
+ @key = params[:channel]
12
8
  end
13
9
 
14
- # @param message [Hash]
15
- # @return [true, nil] true if it can be published, otherwise nil.
16
10
  def publish(message)
17
11
  begin
18
- node.publish(key, message.to_msgpack)
12
+ node.publish(channel, message.to_msgpack)
19
13
  return true
20
14
  rescue
21
15
  return nil
22
16
  end
23
17
  end
24
18
 
25
- # @yieldparam message [Hash] the message received.
26
19
  def subscribe
27
20
  begin
28
- node.subscribe(key) do |on|
21
+ node.subscribe(channel) do |on|
29
22
  on.message do |channel, message|
30
23
  message = MessagePack.unpack(
31
24
  message,
@@ -34,6 +27,9 @@ module Rcom
34
27
  yield message
35
28
  end
36
29
  end
30
+ rescue
31
+ sleep 1
32
+ retry
37
33
  rescue Interrupt => _
38
34
  end
39
35
  end
data/lib/rcom/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rcom
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/rcom.gemspec CHANGED
@@ -20,7 +20,6 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.6"
22
22
  spec.add_development_dependency "rake"
23
- spec.add_development_dependency "yard"
24
23
 
25
24
  spec.add_dependency "redis", "~> 3.1.0"
26
25
  spec.add_dependency "msgpack", "~> 0.5.9"
@@ -1,38 +1,70 @@
1
1
  require_relative './_init'
2
2
 
3
- describe 'Rpc' do
3
+ describe 'Request' do
4
4
  before do
5
5
  ENV['LOCAL'] = 'redis://localhost'
6
6
  @node = Rcom::Node.new('local').connect
7
- @service = Rcom::Rpc.new(node: @node, service: 'auth')
7
+ @request = Rcom::Request.new(node: @node, channel: 'auth')
8
8
  end
9
9
 
10
- it 'represents a remote procedure call' do
11
- @service.must_be_instance_of Rcom::Rpc
10
+ it 'represents a request' do
11
+ @request.must_be_instance_of Rcom::Request
12
12
  end
13
+ end
13
14
 
14
- it 'returns nil if the request cannot be processed' do
15
- @service.request(route: 'nonexistent').must_equal nil
15
+ describe 'Response' do
16
+ before do
17
+ ENV['LOCAL'] = 'redis://localhost'
18
+ @node = Rcom::Node.new('local').connect
19
+ @response = Rcom::Response.new(
20
+ node: @node,
21
+ channel: 'auth',
22
+ server: nil
23
+ )
16
24
  end
17
25
 
18
- it 'works in a request/response scenario' do
19
- user_key = 'xxxccc'
20
- response = ''
21
- publisher = 'bundle exec ruby test/bin/rpc_publisher.rb'
22
- consumer = 'bundle exec ruby test/bin/rpc_consumer.rb'
26
+ it 'represents a response' do
27
+ @response.must_be_instance_of Rcom::Response
28
+ end
29
+ end
23
30
 
24
- # Spawn consumer and wait for requests.
25
- consumer_pid = spawn(consumer)
31
+ describe 'Request-Response' do
32
+ before do
33
+ ENV['LOCAL'] = 'redis://localhost'
34
+ @node = Rcom::Node.new('local').connect
35
+
36
+ @service = Rcom::Request.new(node: @node, channel: 'auth')
37
+
38
+ @rpc_server = fork {
39
+ class Server
40
+ def get_key(params)
41
+ user = params[:user]
42
+ return nil unless user == 1
43
+ return 'xxxccc'
44
+ end
45
+ end
46
+ auth = Rcom::Response.new(
47
+ node: @node,
48
+ channel: 'auth',
49
+ server: Server.new
50
+ )
51
+ auth.serve
52
+ }
53
+
54
+ Process.detach @rpc_server
26
55
  sleep 1
56
+ end
57
+
58
+ it 'cannot request method that does not exists' do
59
+ @service.get_nonexistent(1).must_equal nil
60
+ end
61
+
62
+ it 'can request a method with the correct hash param' do
63
+ @service.get_key(user: 1).must_equal 'xxxccc'
64
+ end
27
65
 
28
- # Spawn a request and record stdout,
29
- # then kill both consumer and publisher.
30
- Open3.popen3(publisher) do |stdin, stdout, stderr, thr|
31
- response = stdout.gets
32
- Process.kill('INT', thr.pid)
33
- end
34
- Process.kill('INT', consumer_pid)
35
66
 
36
- eval(response.chomp).must_equal user_key
67
+ after do
68
+ Process.kill('INT', @rpc_server)
37
69
  end
38
70
  end
@@ -4,41 +4,35 @@ describe 'Task' do
4
4
  before do
5
5
  ENV['LOCAL'] = 'redis://localhost'
6
6
  @node = Rcom::Node.new('local').connect
7
- @task = Rcom::Task.new(node: @node, queue: 'messages')
7
+ @task = Rcom::Task.new(node: @node, channel: 'messages')
8
8
  end
9
9
 
10
10
  it 'represents a Task' do
11
11
  @task.must_be_instance_of Rcom::Task
12
12
  end
13
13
 
14
- it 'can pubish a task' do
15
- message = {
14
+ it 'can publishe a task and subscribe to receive it' do
15
+ original_message = {
16
16
  id: 1,
17
17
  key: 'xxxccc'
18
18
  }
19
- @task.publish(message).must_equal true
20
- end
19
+ reader, writer = IO.pipe
21
20
 
22
- it 'works in a pub/consumer scenario' do
23
- message = {
24
- id: 1,
25
- key: 'xxxccc'
21
+ @subscriber = fork {
22
+ @task.subscribe do |message|
23
+ writer.write message
24
+ end
26
25
  }
27
- completed_job = ''
28
- publisher = 'bundle exec ruby test/bin/task_publisher.rb'
29
- consumer = 'bundle exec ruby test/bin/task_consumer.rb'
26
+ Process.detach @subscriber
27
+ sleep 1
28
+
29
+ @task.publish(original_message)
30
+ sleep 1
30
31
 
31
- # Start the consumer, wait for it to be up,
32
- # start the publisher and wait for the message
33
- # on the consumer side. Process, then kill
34
- # the long-running consumer.
35
- Open3.popen3(consumer) do |stdin, stdout, stderr, wait_thr|
36
- sleep 1
37
- spawn(publisher)
38
- completed_job = stdout.gets
39
- Process.kill('INT', wait_thr.pid)
40
- end
32
+ Process.kill('INT', @subscriber)
41
33
 
42
- eval(completed_job.chomp).must_equal message
34
+ writer.close
35
+ eval(reader.read).must_equal original_message
36
+ reader.close
43
37
  end
44
38
  end
@@ -4,7 +4,7 @@ describe 'Topic' do
4
4
  before do
5
5
  ENV['LOCAL'] = 'redis://localhost'
6
6
  @node = Rcom::Node.new('local').connect
7
- @topic = Rcom::Topic.new(node: @node, key: 'users')
7
+ @topic = Rcom::Topic.new(node: @node, channel: 'users')
8
8
  end
9
9
 
10
10
  it 'represents a Topic' do
@@ -19,27 +19,28 @@ describe 'Topic' do
19
19
  @topic.publish(message).must_equal true
20
20
  end
21
21
 
22
- it 'works in a pub/sub scenario' do
23
- message = {
22
+ it 'can subscribe to a channel and receive a message' do
23
+ original_message = {
24
24
  id: 1,
25
25
  key: 'xxxccc'
26
26
  }
27
- read_message = ''
28
- publisher = 'bundle exec ruby test/bin/topic_publisher.rb'
29
- subscriber = 'bundle exec ruby test/bin/topic_subscriber.rb'
30
-
31
- # Start the subscriber, wait for it to be up,
32
- # start the publisher and wait for the message
33
- # on the subscriber side. Then kill
34
- # the long-running subscriber.
35
- Open3.popen3(subscriber) do |stdin, stdout, stderr, wait_thr|
36
- sleep 2
37
- spawn(publisher)
38
- read_message = stdout.gets
39
- Process.kill('INT', wait_thr.pid)
40
- end
41
-
42
- output = eval(read_message.chomp)
43
- output.must_equal message
27
+ reader, writer = IO.pipe
28
+
29
+ @subscriber = fork {
30
+ @topic.subscribe do |message|
31
+ writer.write message
32
+ end
33
+ }
34
+ Process.detach @subscriber
35
+ sleep 1
36
+
37
+ @topic.publish(original_message)
38
+ sleep 1
39
+
40
+ Process.kill('INT', @subscriber)
41
+
42
+ writer.close
43
+ eval(reader.read).must_equal original_message
44
+ reader.close
44
45
  end
45
46
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rcom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Lisci
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-10 00:00:00.000000000 Z
11
+ date: 2014-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: yard
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: redis
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -100,12 +86,6 @@ files:
100
86
  - lib/rcom/topic.rb
101
87
  - lib/rcom/version.rb
102
88
  - rcom.gemspec
103
- - test/bin/rpc_consumer.rb
104
- - test/bin/rpc_publisher.rb
105
- - test/bin/task_consumer.rb
106
- - test/bin/task_publisher.rb
107
- - test/bin/topic_publisher.rb
108
- - test/bin/topic_subscriber.rb
109
89
  - test/spec/_init.rb
110
90
  - test/spec/node_spec.rb
111
91
  - test/spec/rpc_spec.rb
@@ -136,15 +116,8 @@ signing_key:
136
116
  specification_version: 4
137
117
  summary: Redis inter-service messaging.
138
118
  test_files:
139
- - test/bin/rpc_consumer.rb
140
- - test/bin/rpc_publisher.rb
141
- - test/bin/task_consumer.rb
142
- - test/bin/task_publisher.rb
143
- - test/bin/topic_publisher.rb
144
- - test/bin/topic_subscriber.rb
145
119
  - test/spec/_init.rb
146
120
  - test/spec/node_spec.rb
147
121
  - test/spec/rpc_spec.rb
148
122
  - test/spec/task_spec.rb
149
123
  - test/spec/topic_spec.rb
150
- has_rdoc:
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env ruby
2
- ENV['LOCAL'] = 'redis://localhost'
3
-
4
- require 'rcom'
5
-
6
- node = Rcom::Node.new('local').connect
7
- auth = Rcom::Rpc.new(node: node, service: 'auth')
8
-
9
- auth.subscribe do |request|
10
- request.on('user.key') do |params|
11
- request.reply = 'xxxccc'
12
- end
13
- end
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env ruby
2
- ENV['LOCAL'] = 'redis://localhost'
3
-
4
- require 'rcom'
5
-
6
- message = {
7
- route: 'user.key',
8
- args: 1
9
- }
10
- node = Rcom::Node.new('local').connect
11
- auth = Rcom::Rpc.new(node: node, service: 'auth')
12
- p auth.request(message)
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env ruby
2
- ENV['LOCAL'] = 'redis://localhost'
3
-
4
- require 'rcom'
5
-
6
- node = Rcom::Node.new('local').connect
7
- messages = Rcom::Task.new(node: node, queue: 'messages')
8
-
9
- messages.subscribe do |message|
10
- sleep 1
11
- p message
12
- end
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env ruby
2
- ENV['LOCAL'] = 'redis://localhost'
3
-
4
- require 'rcom'
5
-
6
- message = {
7
- id: 1,
8
- key: 'xxxccc'
9
- }
10
- node = Rcom::Node.new('local').connect
11
- messages = Rcom::Task.new(node: node, queue: 'messages')
12
- messages.publish(message)
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env ruby
2
- ENV['LOCAL'] = 'redis://localhost'
3
-
4
- require 'rcom'
5
-
6
- message = {
7
- id: 1,
8
- key: 'xxxccc'
9
- }
10
- node = Rcom::Node.new('local').connect
11
- users = Rcom::Topic.new(node: node, key: 'users')
12
-
13
- users.publish(message)
@@ -1,11 +0,0 @@
1
- #!/usr/bin/env ruby
2
- ENV['LOCAL'] = 'redis://localhost'
3
-
4
- require 'rcom'
5
-
6
- node = Rcom::Node.new('local').connect
7
- users = Rcom::Topic.new(node: node, key: 'users')
8
-
9
- users.subscribe do |message|
10
- p message
11
- end