basicjrpc 0.1.25 → 0.1.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/basicjrpc.gemspec +1 -0
- data/lib/basicjrpc/client.rb +16 -2
- data/lib/basicjrpc/server.rb +6 -2
- data/lib/basicjrpc/version.rb +1 -1
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b38c1ce4deae05d276f3e1e8c619c6136bd010d
|
4
|
+
data.tar.gz: a791ccf4dc75856d9e23993e16d704c24309ba98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d09aa5a8d7d70605673cd23f9a9c20e5097b0eccaf75785d922e1cfbdcbca018b458c636975a1959af68a81a9a7b8d72b985035311a028e6bd7752a51069a25c
|
7
|
+
data.tar.gz: 5df95f5a7bcdd674490caafa4de376a84a229ea769d344ef851bea19b5dce4a5e80d5e00d166db6d3a1754c1d3cde5dec6e36a7efcf8c440bf632c9452bcc4e0
|
data/basicjrpc.gemspec
CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.11"
|
23
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
24
|
spec.add_runtime_dependency 'nsq-ruby'
|
25
|
+
spec.add_runtime_dependency 'redis'
|
25
26
|
spec.add_runtime_dependency 'oj'
|
26
27
|
spec.add_runtime_dependency 'require_all'
|
27
28
|
end
|
data/lib/basicjrpc/client.rb
CHANGED
@@ -7,6 +7,8 @@ module BasicJRPC
|
|
7
7
|
@queue = queue
|
8
8
|
@payload = {}
|
9
9
|
@timeout = timeout
|
10
|
+
@instance_id = SecureRandom.uuid
|
11
|
+
@consumer = Nsq::Consumer.new(nsqlookupd: 'dockerlb:4161',topic: "#{@queue}-response", channel: @instance_id)
|
10
12
|
end
|
11
13
|
|
12
14
|
def method_missing(m, *args, &block)
|
@@ -15,11 +17,23 @@ module BasicJRPC
|
|
15
17
|
|
16
18
|
def send_request payload
|
17
19
|
payload[:message_id] = SecureRandom.uuid
|
20
|
+
payload[:instance_id] = @instance_id
|
18
21
|
payload[:response] = true
|
22
|
+
|
23
|
+
my_message = false
|
19
24
|
|
20
25
|
@nsq_producer.write(Oj.dump(payload))
|
21
|
-
|
22
|
-
|
26
|
+
|
27
|
+
# while !my_message
|
28
|
+
# message = @consumer.pop
|
29
|
+
# decoded_message = Oj.load(message.body)
|
30
|
+
# my_message = decoded_message.response if decoded_message.message_id == payload.message_id
|
31
|
+
# end
|
32
|
+
|
33
|
+
# message.finish
|
34
|
+
# return my_message
|
35
|
+
|
36
|
+
Oj.load(Redis.new(host: "redis").blpop(payload[:message_id])[1])
|
23
37
|
end
|
24
38
|
end
|
25
39
|
|
data/lib/basicjrpc/server.rb
CHANGED
@@ -10,14 +10,18 @@ module BasicJRPC
|
|
10
10
|
def listen
|
11
11
|
puts "Listening..."
|
12
12
|
while true
|
13
|
-
|
13
|
+
message = @nsq_consumer.pop
|
14
|
+
payload = Oj.load(message.body)
|
14
15
|
puts "Processing message #{payload.method_name} #{payload.method_arguments}"
|
15
16
|
|
16
17
|
# Should always return a data object
|
17
18
|
response = @injected_class.send(payload.method_name, *payload.method_arguments)
|
18
19
|
|
19
20
|
# Bounce the response back if response is requested
|
20
|
-
|
21
|
+
#response_payload = { message_id: payload.message_id, instance_id: payload.instance_id, response: response}
|
22
|
+
#Nsq::Producer.new(nsqd: 'dockerlb:4150', topic: "#{@queue}-response").write(Oj.dump(response_payload)) if payload.response
|
23
|
+
Redis.new(host: "redis").rpush(payload.message_id, Oj.dump(response))
|
24
|
+
message.finish
|
21
25
|
end
|
22
26
|
end
|
23
27
|
|
data/lib/basicjrpc/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: basicjrpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.26
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Simpson
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: redis
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: oj
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|