liebre 0.1.21 → 0.2.1
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/.rspec +2 -0
- data/Gemfile.lock +9 -7
- data/{LICENSE → LICENSE.txt} +1 -1
- data/README.md +492 -195
- data/Rakefile +2 -0
- data/lib/liebre.rb +27 -16
- data/lib/liebre/actor.rb +11 -0
- data/lib/liebre/actor/consumer.rb +80 -0
- data/lib/liebre/actor/consumer/callback.rb +34 -0
- data/lib/liebre/actor/consumer/core.rb +80 -0
- data/lib/liebre/actor/consumer/reporter.rb +84 -0
- data/lib/liebre/actor/consumer/resources.rb +47 -0
- data/lib/liebre/actor/consumer/resources/config.rb +65 -0
- data/lib/liebre/actor/context.rb +40 -0
- data/lib/liebre/actor/context/declare.rb +44 -0
- data/lib/liebre/actor/context/handler.rb +44 -0
- data/lib/liebre/actor/publisher.rb +58 -0
- data/lib/liebre/actor/publisher/core.rb +42 -0
- data/lib/liebre/actor/publisher/reporter.rb +55 -0
- data/lib/liebre/actor/publisher/resources.rb +33 -0
- data/lib/liebre/actor/rpc/client.rb +88 -0
- data/lib/liebre/actor/rpc/client/core.rb +75 -0
- data/lib/liebre/actor/rpc/client/pending.rb +65 -0
- data/lib/liebre/actor/rpc/client/reporter.rb +71 -0
- data/lib/liebre/actor/rpc/client/resources.rb +62 -0
- data/lib/liebre/actor/rpc/client/task.rb +33 -0
- data/lib/liebre/actor/rpc/server.rb +74 -0
- data/lib/liebre/actor/rpc/server/callback.rb +28 -0
- data/lib/liebre/actor/rpc/server/core.rb +75 -0
- data/lib/liebre/actor/rpc/server/reporter.rb +72 -0
- data/lib/liebre/actor/rpc/server/resources.rb +53 -0
- data/lib/liebre/adapter.rb +8 -0
- data/lib/liebre/adapter/bunny.rb +23 -0
- data/lib/liebre/adapter/bunny/chan.rb +38 -0
- data/lib/liebre/adapter/bunny/conn.rb +32 -0
- data/lib/liebre/adapter/bunny/exchange.rb +20 -0
- data/lib/liebre/adapter/bunny/queue.rb +59 -0
- data/lib/liebre/adapter/interface.rb +26 -0
- data/lib/liebre/adapter/interface/chan.rb +29 -0
- data/lib/liebre/adapter/interface/conn.rb +21 -0
- data/lib/liebre/adapter/interface/exchange.rb +13 -0
- data/lib/liebre/adapter/interface/queue.rb +37 -0
- data/lib/liebre/bridge.rb +72 -0
- data/lib/liebre/bridge/channel_builder.rb +36 -0
- data/lib/liebre/config.rb +8 -38
- data/lib/liebre/engine.rb +61 -0
- data/lib/liebre/engine/builder.rb +48 -0
- data/lib/liebre/engine/repository.rb +56 -0
- data/lib/liebre/engine/state.rb +49 -0
- data/lib/liebre/runner.rb +15 -47
- data/lib/liebre/version.rb +1 -1
- data/liebre.gemspec +9 -7
- data/spec/integration/publish_and_consume_spec.rb +71 -0
- data/spec/integration/rpc_communication_spec.rb +81 -0
- data/spec/integration/start_twice_spec.rb +63 -0
- data/spec/liebre/actor/consumer_spec.rb +169 -0
- data/spec/liebre/actor/context/declare_spec.rb +69 -0
- data/spec/liebre/actor/context/handler_spec.rb +65 -0
- data/spec/liebre/actor/publisher_spec.rb +58 -0
- data/spec/liebre/actor/rpc/client_spec.rb +126 -0
- data/spec/liebre/actor/rpc/server_spec.rb +141 -0
- data/spec/liebre/adapter/bunny_spec.rb +66 -0
- data/spec/liebre/bridge_spec.rb +54 -0
- data/spec/liebre/engine/builder_spec.rb +42 -0
- data/spec/liebre/engine_spec.rb +90 -0
- data/spec/liebre/version_spec.rb +10 -0
- data/spec/spec_helper.rb +2 -9
- metadata +97 -58
- data/lib/liebre/common.rb +0 -7
- data/lib/liebre/common/utils.rb +0 -37
- data/lib/liebre/connection_manager.rb +0 -85
- data/lib/liebre/publisher.rb +0 -113
- data/lib/liebre/runner/consumers.rb +0 -46
- data/lib/liebre/runner/starter.rb +0 -44
- data/lib/liebre/runner/starter/consumer.rb +0 -129
- data/lib/liebre/runner/starter/consumer/handler.rb +0 -35
- data/lib/liebre/runner/starter/resources.rb +0 -45
- data/lib/liebre/runner/starter/resources/queue_builder.rb +0 -63
- data/lib/liebre/runner/starter/rpc.rb +0 -59
- data/lib/liebre/tasks.rb +0 -12
- data/spec/config/liebre.yml +0 -48
- data/spec/config/rabbitmq.yml +0 -35
- data/spec/integration_spec.rb +0 -76
- data/spec/liebre/config_spec.rb +0 -63
- data/spec/liebre/connection_manager_spec.rb +0 -44
- data/spec/liebre/publisher_spec.rb +0 -92
- data/spec/liebre/runner/consumers_spec.rb +0 -59
- data/spec/liebre/runner/starter/consumer_spec.rb +0 -145
- data/spec/liebre/runner/starter/resources/queue_builder_spec.rb +0 -69
- data/spec/liebre/runner/starter/resources_spec.rb +0 -38
- data/spec/liebre/runner/starter/rpc_spec.rb +0 -100
- data/spec/liebre/runner/starter_spec.rb +0 -70
- data/spec/liebre/runner_spec.rb +0 -54
@@ -0,0 +1,53 @@
|
|
1
|
+
module Liebre
|
2
|
+
module Actor
|
3
|
+
module RPC
|
4
|
+
class Server
|
5
|
+
class Resources
|
6
|
+
|
7
|
+
def initialize context
|
8
|
+
@context = context
|
9
|
+
end
|
10
|
+
|
11
|
+
def response_exchange
|
12
|
+
@response_exchange ||= declare.default_exchange
|
13
|
+
end
|
14
|
+
|
15
|
+
def request_queue
|
16
|
+
@request_queue ||= declare.queue(queue_config).tap do |queue|
|
17
|
+
declare.bind(queue, request_exchange, bind_config)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def request_exchange
|
22
|
+
@request_exchange ||= declare.exchange(exchange_config)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def queue_config
|
28
|
+
spec.fetch(:queue)
|
29
|
+
end
|
30
|
+
|
31
|
+
def exchange_config
|
32
|
+
spec.fetch(:exchange)
|
33
|
+
end
|
34
|
+
|
35
|
+
def bind_config
|
36
|
+
spec.fetch(:bind, {})
|
37
|
+
end
|
38
|
+
|
39
|
+
def spec
|
40
|
+
context.spec
|
41
|
+
end
|
42
|
+
|
43
|
+
def declare
|
44
|
+
context.declare
|
45
|
+
end
|
46
|
+
|
47
|
+
attr_reader :context
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
begin
|
2
|
+
require "bunny"
|
3
|
+
rescue
|
4
|
+
# bunny not present
|
5
|
+
end
|
6
|
+
|
7
|
+
require "liebre/adapter/bunny/conn"
|
8
|
+
require "liebre/adapter/bunny/chan"
|
9
|
+
require "liebre/adapter/bunny/exchange"
|
10
|
+
require "liebre/adapter/bunny/queue"
|
11
|
+
|
12
|
+
module Liebre
|
13
|
+
module Adapter
|
14
|
+
class Bunny
|
15
|
+
include Interface
|
16
|
+
|
17
|
+
def connection opts
|
18
|
+
Conn.new(opts)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Liebre
|
2
|
+
module Adapter
|
3
|
+
class Bunny
|
4
|
+
class Chan
|
5
|
+
include Interface::Chan
|
6
|
+
|
7
|
+
attr_reader :channel
|
8
|
+
|
9
|
+
def initialize channel
|
10
|
+
@channel = channel
|
11
|
+
end
|
12
|
+
|
13
|
+
def default_exchange
|
14
|
+
Exchange.new(channel.default_exchange)
|
15
|
+
end
|
16
|
+
|
17
|
+
def exchange name, type, opts
|
18
|
+
opts = opts.merge(:type => type)
|
19
|
+
|
20
|
+
Exchange.new(channel.exchange(name, opts))
|
21
|
+
end
|
22
|
+
|
23
|
+
def queue name, opts
|
24
|
+
Queue.new(channel.queue(name, opts))
|
25
|
+
end
|
26
|
+
|
27
|
+
def set_prefetch count
|
28
|
+
channel.basic_qos(count, false)
|
29
|
+
end
|
30
|
+
|
31
|
+
def close
|
32
|
+
channel.close
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Liebre
|
2
|
+
module Adapter
|
3
|
+
class Bunny
|
4
|
+
class Conn
|
5
|
+
include Interface::Conn
|
6
|
+
|
7
|
+
attr_reader :opts
|
8
|
+
|
9
|
+
def initialize opts
|
10
|
+
@opts = opts
|
11
|
+
end
|
12
|
+
|
13
|
+
def start
|
14
|
+
session.start
|
15
|
+
end
|
16
|
+
|
17
|
+
def open_channel
|
18
|
+
Chan.new(session.create_channel)
|
19
|
+
end
|
20
|
+
|
21
|
+
def stop
|
22
|
+
session.stop
|
23
|
+
end
|
24
|
+
|
25
|
+
def session
|
26
|
+
@session ||= ::Bunny.new(opts)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Liebre
|
2
|
+
module Adapter
|
3
|
+
class Bunny
|
4
|
+
class Exchange
|
5
|
+
include Interface::Exchange
|
6
|
+
|
7
|
+
attr_reader :exchange
|
8
|
+
|
9
|
+
def initialize exchange
|
10
|
+
@exchange = exchange
|
11
|
+
end
|
12
|
+
|
13
|
+
def publish payload, opts = {}
|
14
|
+
exchange.publish(payload, opts)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Liebre
|
2
|
+
module Adapter
|
3
|
+
class Bunny
|
4
|
+
class Queue
|
5
|
+
include Interface::Queue
|
6
|
+
|
7
|
+
attr_reader :queue
|
8
|
+
|
9
|
+
def initialize queue
|
10
|
+
@queue = queue
|
11
|
+
end
|
12
|
+
|
13
|
+
def name
|
14
|
+
queue.name
|
15
|
+
end
|
16
|
+
|
17
|
+
def bind exchange, opts = {}
|
18
|
+
bunny_exchange = exchange.exchange
|
19
|
+
|
20
|
+
queue.bind(bunny_exchange, opts)
|
21
|
+
end
|
22
|
+
|
23
|
+
def ack info, opts = {}
|
24
|
+
multiple = opts.fetch(:multiple, false)
|
25
|
+
|
26
|
+
channel.ack(info.delivery_tag, multiple)
|
27
|
+
end
|
28
|
+
|
29
|
+
def nack info, opts = {}
|
30
|
+
multiple = opts.fetch(:multiple, false)
|
31
|
+
requeue = opts.fetch(:requeue, false)
|
32
|
+
|
33
|
+
channel.nack(info.delivery_tag, multiple, requeue)
|
34
|
+
end
|
35
|
+
|
36
|
+
def reject info, opts = {}
|
37
|
+
requeue = opts.fetch(:requeue, false)
|
38
|
+
|
39
|
+
channel.reject(info.delivery_tag, requeue)
|
40
|
+
end
|
41
|
+
|
42
|
+
def get opts = {}, &block
|
43
|
+
queue.get(opts, &block)
|
44
|
+
end
|
45
|
+
|
46
|
+
def subscribe opts = {}, &block
|
47
|
+
queue.subscribe(opts, &block)
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def channel
|
53
|
+
queue.channel
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "liebre/adapter/interface/conn"
|
2
|
+
require "liebre/adapter/interface/chan"
|
3
|
+
require "liebre/adapter/interface/exchange"
|
4
|
+
require "liebre/adapter/interface/queue"
|
5
|
+
|
6
|
+
module Liebre
|
7
|
+
module Adapter
|
8
|
+
module Interface
|
9
|
+
|
10
|
+
def self.included base
|
11
|
+
base.extend(ClassMethods)
|
12
|
+
end
|
13
|
+
|
14
|
+
def connection _config
|
15
|
+
raise NotImplementedError, "All adapters must implement connection(config) to build a new connection"
|
16
|
+
end
|
17
|
+
|
18
|
+
module ClassMethods
|
19
|
+
def connection config
|
20
|
+
new.connection(config)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Liebre
|
2
|
+
module Adapter
|
3
|
+
module Interface
|
4
|
+
module Chan
|
5
|
+
|
6
|
+
def default_exchange
|
7
|
+
raise NotImplementedError, "All adapters must implement channel default_exchange() to build the default exchange"
|
8
|
+
end
|
9
|
+
|
10
|
+
def exchange name, type, opts
|
11
|
+
raise NotImplementedError, "All adapters must implement channel exchange(name, type, opts) to declare and build exchanges"
|
12
|
+
end
|
13
|
+
|
14
|
+
def queue name, opts
|
15
|
+
raise NotImplementedError, "All adapters must implement channel queue(name, opts) to declare and build queues"
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_prefetch count
|
19
|
+
raise NotImplementedError, "All adapters must implement channel set_prefetch(count) to set the prefetch count for this channel"
|
20
|
+
end
|
21
|
+
|
22
|
+
def close
|
23
|
+
raise NotImplementedError, "All adapters must implement channel close() to close a channel"
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Liebre
|
2
|
+
module Adapter
|
3
|
+
module Interface
|
4
|
+
module Conn
|
5
|
+
|
6
|
+
def start
|
7
|
+
raise NotImplementedError, "All adapters must implement connection start() to establish connection"
|
8
|
+
end
|
9
|
+
|
10
|
+
def open_channel
|
11
|
+
raise NotImplementedError, "All adapters must implement connection open_channel() to start new channels"
|
12
|
+
end
|
13
|
+
|
14
|
+
def stop
|
15
|
+
raise NotImplementedError, "All adapters must implement connection stop() to disconnect from the server"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Liebre
|
2
|
+
module Adapter
|
3
|
+
module Interface
|
4
|
+
module Queue
|
5
|
+
|
6
|
+
def name
|
7
|
+
raise NotImplementedError, "All adapters must implement queue name() to get the name of the queue"
|
8
|
+
end
|
9
|
+
|
10
|
+
def bind exchange, opts = {}
|
11
|
+
raise NotImplementedError, "All adapters must implement queue bind(exchange, opts) to bind the queue to an exchange"
|
12
|
+
end
|
13
|
+
|
14
|
+
def get opts = {}, &block
|
15
|
+
raise NotImplementedError, "All adapters must implement queue get(opts, &block) to get messages"
|
16
|
+
end
|
17
|
+
|
18
|
+
def subscribe opts = {}, &block
|
19
|
+
raise NotImplementedError, "All adapters must implement queue subscribe(opts, block) consume messajes constantly"
|
20
|
+
end
|
21
|
+
|
22
|
+
def ack info, opts = {}
|
23
|
+
raise NotImplementedError, "All adapters must implement queue ack(info, opts) to ack messages"
|
24
|
+
end
|
25
|
+
|
26
|
+
def nack info, opts = {}
|
27
|
+
raise NotImplementedError, "All adapters must implement queue nack(info, opts) to nack messages"
|
28
|
+
end
|
29
|
+
|
30
|
+
def reject info, opts = {}
|
31
|
+
raise NotImplementedError, "All adapters must implement queue reject(info, opts) to reject messages"
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'concurrent'
|
2
|
+
|
3
|
+
require 'liebre/bridge/channel_builder'
|
4
|
+
|
5
|
+
module Liebre
|
6
|
+
class Bridge
|
7
|
+
NotStarted = Class.new(StandardError)
|
8
|
+
|
9
|
+
def initialize config
|
10
|
+
@config = config
|
11
|
+
@started = false
|
12
|
+
end
|
13
|
+
|
14
|
+
def started?
|
15
|
+
@started
|
16
|
+
end
|
17
|
+
|
18
|
+
def start
|
19
|
+
if not started?
|
20
|
+
connections.each do |name, conn|
|
21
|
+
conn.start
|
22
|
+
logger.info("Connection started: #{name.inspect}")
|
23
|
+
end
|
24
|
+
|
25
|
+
self.started = true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def open_channel opts
|
30
|
+
if started?
|
31
|
+
builder = ChannelBuilder.new(connections, opts)
|
32
|
+
builder.call
|
33
|
+
else
|
34
|
+
raise NotStarted
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def stop
|
39
|
+
if started?
|
40
|
+
connections.each { |_name, conn| conn.stop }
|
41
|
+
|
42
|
+
self.started = false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def connections
|
49
|
+
@connections ||= conn_configs.reduce({}) do |all, (name, opts)|
|
50
|
+
connection = adapter.connection(opts)
|
51
|
+
|
52
|
+
all.merge!(name => connection)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def logger
|
57
|
+
config.logger
|
58
|
+
end
|
59
|
+
|
60
|
+
def adapter
|
61
|
+
config.adapter
|
62
|
+
end
|
63
|
+
|
64
|
+
def conn_configs
|
65
|
+
config.connections
|
66
|
+
end
|
67
|
+
|
68
|
+
attr_reader :config
|
69
|
+
attr_writer :started
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|