remote_service 0.1.1 → 0.1.2
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +3 -4
- data/examples/client.rb +14 -2
- data/lib/remote_service/connector/nats.rb +7 -2
- data/lib/remote_service/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c226f8df24c6410e5934902d642e0ad3ee29e9c
|
4
|
+
data.tar.gz: dbb5f3bacf9e706496e361125f65328cff94c22b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73b90473f2c9c22511ccb0580f6e7162d0eff2806e3440846d21fa4ebeac6c55d8e0f3d426ba856b1511220171b3cb2c82140281981016b81703a3736fbfa117
|
7
|
+
data.tar.gz: d8a1b2039b5f1c1787a4e096403e641628b04b03e8fd0dcd88ebadda8df76cbeca4af88bc5b452c3654e0385ed1dc7cbad9c9b7f86e3034234e4cf5d124b5299
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
# RemoteService 
|
2
|
-
|
1
|
+
# RemoteService  [](https://badge.fury.io/rb/remote_service)
|
3
2
|
Remote services made easy. This gem is basically RPC client/server implemented on top of awesome [NATS](http://nats.io/) project. Every service you want to use is exposed through class that extends `RemoteService::Proxy`. Service itself extends `RemoteService::Service` and should define all methods that you want to call from clients.
|
4
3
|
|
5
4
|
## Installation
|
@@ -24,7 +23,7 @@ First you need to start NATS cluster. This can be either single broker or n-node
|
|
24
23
|
docker-compose up
|
25
24
|
```
|
26
25
|
|
27
|
-
|
26
|
+
Then you need to define and run your service. Minimal service can be run with a following script where return value of each method will be sent back as a response.
|
28
27
|
```ruby
|
29
28
|
require "remote_service"
|
30
29
|
|
@@ -39,7 +38,7 @@ end
|
|
39
38
|
ServiceA.start(brokers: ['nats://127.0.0.1:4222', 'nats://127.0.0.1:5222'])
|
40
39
|
```
|
41
40
|
|
42
|
-
|
41
|
+
Last thing is to call the service defined previously. All you need to do is define a service proxy, connect to NATS cluster and call a remote method as if it was local.
|
43
42
|
```ruby
|
44
43
|
require "remote_service"
|
45
44
|
|
data/examples/client.rb
CHANGED
@@ -14,6 +14,18 @@ end
|
|
14
14
|
RemoteService.logger.level = Logger::DEBUG
|
15
15
|
RemoteService.connect(brokers: ['nats://127.0.0.1:4222', 'nats://127.0.0.1:5222', 'nats://127.0.0.1:6222'])
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
clients = []
|
18
|
+
4.times do
|
19
|
+
clients << Thread.new do
|
20
|
+
loop do
|
21
|
+
ServiceA.all(123, keyword: 'value')
|
22
|
+
ServiceB.users
|
23
|
+
sleep(0.01)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
clients.each do |client|
|
29
|
+
client.join
|
30
|
+
end
|
19
31
|
|
@@ -7,6 +7,7 @@ module RemoteService
|
|
7
7
|
|
8
8
|
def initialize(brokers:)
|
9
9
|
@brokers = brokers
|
10
|
+
@mutex = Mutex.new
|
10
11
|
end
|
11
12
|
|
12
13
|
def start(&block)
|
@@ -19,11 +20,15 @@ module RemoteService
|
|
19
20
|
end
|
20
21
|
|
21
22
|
def publish(to_queue, message)
|
22
|
-
|
23
|
+
@mutex.synchronize do
|
24
|
+
NATS.publish(to_queue, message)
|
25
|
+
end
|
23
26
|
end
|
24
27
|
|
25
28
|
def request(to_queue, message, &block)
|
26
|
-
|
29
|
+
@mutex.synchronize do
|
30
|
+
NATS.request(to_queue, message, &block)
|
31
|
+
end
|
27
32
|
end
|
28
33
|
|
29
34
|
def subscribe(service_queue, &block)
|