rabbit_feed 2.4.4 → 3.0.0
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/.gitignore +1 -0
- data/.rubocop.yml +81 -0
- data/README.md +39 -5
- data/Rakefile +3 -19
- data/bin/rabbit_feed +0 -1
- data/example/non_rails_app/Gemfile.lock +29 -32
- data/example/non_rails_app/Rakefile +1 -1
- data/example/non_rails_app/bin/benchmark +3 -3
- data/example/non_rails_app/lib/non_rails_app/event_handler.rb +1 -1
- data/example/non_rails_app/spec/lib/non_rails_app/event_handler_spec.rb +3 -4
- data/example/non_rails_app/spec/lib/non_rails_app/event_routing_spec.rb +3 -3
- data/example/rails_app/Gemfile +4 -16
- data/example/rails_app/Gemfile.lock +131 -137
- data/example/rails_app/app/assets/javascripts/application.js +0 -1
- data/example/rails_app/app/controllers/application_controller.rb +0 -3
- data/example/rails_app/app/controllers/beavers_controller.rb +14 -15
- data/example/rails_app/bin/rails +1 -1
- data/example/rails_app/config/environments/development.rb +1 -1
- data/example/rails_app/config/environments/test.rb +2 -2
- data/example/rails_app/config/initializers/cookies_serializer.rb +1 -1
- data/example/rails_app/config/unicorn.rb +1 -1
- data/example/rails_app/config.ru +1 -1
- data/example/rails_app/db/schema.rb +5 -7
- data/example/rails_app/lib/event_handler.rb +1 -1
- data/example/rails_app/spec/controllers/beavers_controller_spec.rb +9 -10
- data/example/rails_app/spec/event_routing_spec.rb +1 -2
- data/example/rails_app/test/controllers/beavers_controller_test.rb +12 -12
- data/lib/dsl.rb +4 -4
- data/lib/rabbit_feed/client.rb +17 -23
- data/lib/rabbit_feed/configuration.rb +10 -9
- data/lib/rabbit_feed/connection.rb +3 -3
- data/lib/rabbit_feed/console_consumer.rb +22 -24
- data/lib/rabbit_feed/consumer.rb +2 -2
- data/lib/rabbit_feed/consumer_connection.rb +21 -22
- data/lib/rabbit_feed/event.rb +8 -28
- data/lib/rabbit_feed/event_definitions.rb +14 -15
- data/lib/rabbit_feed/event_routing.rb +26 -27
- data/lib/rabbit_feed/json_log_formatter.rb +1 -1
- data/lib/rabbit_feed/producer.rb +13 -13
- data/lib/rabbit_feed/producer_connection.rb +8 -9
- data/lib/rabbit_feed/testing_support/rspec_matchers/publish_event.rb +52 -89
- data/lib/rabbit_feed/testing_support/test_rabbit_feed_consumer.rb +1 -2
- data/lib/rabbit_feed/testing_support/testing_helpers.rb +0 -1
- data/lib/rabbit_feed/testing_support.rb +5 -6
- data/lib/rabbit_feed/version.rb +1 -1
- data/lib/rabbit_feed.rb +12 -13
- data/rabbit_feed.gemspec +16 -14
- data/run_benchmark +4 -3
- data/run_example +1 -1
- data/spec/features/step_definitions/connectivity_steps.rb +6 -9
- data/spec/lib/rabbit_feed/client_spec.rb +8 -9
- data/spec/lib/rabbit_feed/configuration_spec.rb +20 -23
- data/spec/lib/rabbit_feed/console_consumer_spec.rb +11 -13
- data/spec/lib/rabbit_feed/consumer_connection_spec.rb +26 -28
- data/spec/lib/rabbit_feed/event_definitions_spec.rb +31 -31
- data/spec/lib/rabbit_feed/event_routing_spec.rb +35 -62
- data/spec/lib/rabbit_feed/event_spec.rb +40 -87
- data/spec/lib/rabbit_feed/producer_connection_spec.rb +11 -7
- data/spec/lib/rabbit_feed/producer_spec.rb +16 -19
- data/spec/lib/rabbit_feed/testing_support/rspec_matchers/publish_event_spec.rb +82 -87
- data/spec/lib/rabbit_feed/testing_support/testing_helper_spec.rb +2 -2
- data/spec/spec_helper.rb +4 -10
- metadata +67 -45
- data/example/rails_app/README.rdoc +0 -28
@@ -1,6 +1,5 @@
|
|
1
1
|
module RabbitFeed
|
2
2
|
class EventRouting
|
3
|
-
|
4
3
|
class Event
|
5
4
|
include ActiveModel::Validations
|
6
5
|
|
@@ -8,14 +7,14 @@ module RabbitFeed
|
|
8
7
|
validates_presence_of :name, :action
|
9
8
|
validate :action_arity
|
10
9
|
|
11
|
-
def initialize
|
10
|
+
def initialize(name, block)
|
12
11
|
@name = name
|
13
12
|
@action = block
|
14
13
|
|
15
14
|
validate!
|
16
15
|
end
|
17
16
|
|
18
|
-
def handle_event
|
17
|
+
def handle_event(event)
|
19
18
|
action.call event
|
20
19
|
end
|
21
20
|
|
@@ -26,7 +25,7 @@ module RabbitFeed
|
|
26
25
|
end
|
27
26
|
|
28
27
|
def validate!
|
29
|
-
raise ConfigurationError
|
28
|
+
raise ConfigurationError, "Bad event specification for #{name}: #{errors.messages}" if invalid?
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
@@ -36,18 +35,18 @@ module RabbitFeed
|
|
36
35
|
attr_reader :named_events, :catch_all_event, :name
|
37
36
|
validates_presence_of :name
|
38
37
|
|
39
|
-
def initialize
|
38
|
+
def initialize(name)
|
40
39
|
@name = name
|
41
40
|
@named_events = {}
|
42
41
|
|
43
42
|
validate!
|
44
43
|
end
|
45
44
|
|
46
|
-
def event
|
45
|
+
def event(name, &block)
|
47
46
|
if name == :any
|
48
|
-
accept_any_event
|
47
|
+
accept_any_event(&block)
|
49
48
|
else
|
50
|
-
accept_named_event
|
49
|
+
accept_named_event(name, &block)
|
51
50
|
end
|
52
51
|
end
|
53
52
|
|
@@ -57,34 +56,34 @@ module RabbitFeed
|
|
57
56
|
end
|
58
57
|
end
|
59
58
|
|
60
|
-
def handle_event
|
59
|
+
def handle_event(event)
|
61
60
|
event_rule = find_event event
|
62
61
|
event_rule.handle_event event
|
63
62
|
end
|
64
63
|
|
65
|
-
def handles_event?
|
64
|
+
def handles_event?(event)
|
66
65
|
(find_event event).present?
|
67
66
|
end
|
68
67
|
|
69
68
|
private
|
70
69
|
|
71
70
|
def validate!
|
72
|
-
raise ConfigurationError
|
71
|
+
raise ConfigurationError, "Bad application specification for #{name}: #{errors.messages}" if invalid?
|
73
72
|
end
|
74
73
|
|
75
|
-
def accept_named_event
|
76
|
-
raise ConfigurationError
|
74
|
+
def accept_named_event(name, &block)
|
75
|
+
raise ConfigurationError, "Routing has already been defined for the event with name: #{name} in application: #{self.name}" if named_events.key? name
|
77
76
|
event = (Event.new name, block)
|
78
77
|
named_events[event.name] = event
|
79
78
|
end
|
80
79
|
|
81
|
-
def accept_any_event
|
82
|
-
raise ConfigurationError
|
80
|
+
def accept_any_event(&block)
|
81
|
+
raise ConfigurationError, "Routing has already been defined for the event catch-all: :any in application: #{name}" if catch_all_event.present?
|
83
82
|
event = (Event.new '*', block)
|
84
83
|
@catch_all_event = event
|
85
84
|
end
|
86
85
|
|
87
|
-
def find_event
|
86
|
+
def find_event(event)
|
88
87
|
[named_events[event.name], catch_all_event].compact.first
|
89
88
|
end
|
90
89
|
|
@@ -101,43 +100,43 @@ module RabbitFeed
|
|
101
100
|
@named_applications = {}
|
102
101
|
end
|
103
102
|
|
104
|
-
def accept_from
|
103
|
+
def accept_from(name, &block)
|
105
104
|
if name == :any
|
106
|
-
accept_from_any_application
|
105
|
+
accept_from_any_application(&block)
|
107
106
|
else
|
108
|
-
accept_from_named_application
|
107
|
+
accept_from_named_application(name, &block)
|
109
108
|
end
|
110
109
|
end
|
111
110
|
|
112
111
|
def accepted_routes
|
113
|
-
routes = named_applications.values.
|
112
|
+
routes = named_applications.values.flat_map(&:accepted_routes)
|
114
113
|
routes += catch_all_application.accepted_routes if catch_all_application.present?
|
115
114
|
routes
|
116
115
|
end
|
117
116
|
|
118
|
-
def handle_event
|
117
|
+
def handle_event(event)
|
119
118
|
application = find_application event
|
120
|
-
raise RoutingError
|
119
|
+
raise RoutingError, "No routing defined for application with name: #{event.application} for events named: #{event.name}" unless application.present?
|
121
120
|
application.handle_event event
|
122
121
|
end
|
123
122
|
|
124
123
|
private
|
125
124
|
|
126
|
-
def accept_from_named_application
|
127
|
-
raise ConfigurationError
|
125
|
+
def accept_from_named_application(name, &block)
|
126
|
+
raise ConfigurationError, "Routing has already been defined for the application with name: #{name}" if named_applications.key? name
|
128
127
|
application = Application.new name
|
129
128
|
application.instance_eval(&block)
|
130
129
|
named_applications[application.name] = application
|
131
130
|
end
|
132
131
|
|
133
|
-
def accept_from_any_application
|
134
|
-
raise ConfigurationError
|
132
|
+
def accept_from_any_application(&block)
|
133
|
+
raise ConfigurationError, 'Routing has already been defined for the application catch-all: :any' if catch_all_application.present?
|
135
134
|
application = Application.new '*'
|
136
135
|
application.instance_eval(&block)
|
137
136
|
@catch_all_application = application
|
138
137
|
end
|
139
138
|
|
140
|
-
def find_application
|
139
|
+
def find_application(event)
|
141
140
|
candidate_applications = [named_applications[event.application], catch_all_application].compact
|
142
141
|
candidate_applications.detect do |application|
|
143
142
|
application.handles_event? event
|
data/lib/rabbit_feed/producer.rb
CHANGED
@@ -4,21 +4,21 @@ module RabbitFeed
|
|
4
4
|
|
5
5
|
attr_accessor :event_definitions
|
6
6
|
|
7
|
-
def publish_event
|
8
|
-
raise
|
9
|
-
event_definition = event_definitions[name]
|
10
|
-
timestamp
|
11
|
-
metadata
|
12
|
-
event
|
13
|
-
RabbitFeed.log.info {{ event: :publish_start, metadata: event.metadata }}
|
7
|
+
def publish_event(name, payload)
|
8
|
+
raise RabbitFeed::Error, 'Unable to publish event. No event definitions set.' unless event_definitions.present?
|
9
|
+
(event_definition = event_definitions[name]) || (raise RabbitFeed::Error, "definition for event: #{name} not found")
|
10
|
+
timestamp = Time.now.utc
|
11
|
+
metadata = (metadata event_definition.version, name, timestamp)
|
12
|
+
event = Event.new metadata, payload, event_definition.schema, event_definition.sensitive_fields
|
13
|
+
RabbitFeed.log.info { { event: :publish_start, metadata: event.metadata } }
|
14
14
|
ProducerConnection.instance.publish event.serialize, (options name, timestamp)
|
15
|
-
RabbitFeed.log.info {{ event: :publish_end, metadata: event.metadata }}
|
15
|
+
RabbitFeed.log.info { { event: :publish_end, metadata: event.metadata } }
|
16
16
|
event
|
17
17
|
end
|
18
18
|
|
19
19
|
private
|
20
20
|
|
21
|
-
def metadata
|
21
|
+
def metadata(version, name, timestamp)
|
22
22
|
{
|
23
23
|
'application' => RabbitFeed.configuration.application,
|
24
24
|
'host' => Socket.gethostname,
|
@@ -26,20 +26,20 @@ module RabbitFeed
|
|
26
26
|
'created_at_utc' => timestamp.iso8601(6),
|
27
27
|
'version' => version,
|
28
28
|
'name' => name,
|
29
|
-
'schema_version' => Event::SCHEMA_VERSION
|
29
|
+
'schema_version' => Event::SCHEMA_VERSION
|
30
30
|
}
|
31
31
|
end
|
32
32
|
|
33
|
-
def routing_key
|
33
|
+
def routing_key(event_name)
|
34
34
|
"#{RabbitFeed.environment}#{RabbitFeed.configuration.route_prefix_extension}.#{RabbitFeed.configuration.application}.#{event_name}"
|
35
35
|
end
|
36
36
|
|
37
|
-
def options
|
37
|
+
def options(event_name, timestamp)
|
38
38
|
{
|
39
39
|
routing_key: (routing_key event_name),
|
40
40
|
type: event_name,
|
41
41
|
app_id: RabbitFeed.configuration.application,
|
42
|
-
timestamp: timestamp.to_i
|
42
|
+
timestamp: timestamp.to_i
|
43
43
|
}
|
44
44
|
end
|
45
45
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module RabbitFeed
|
2
2
|
class ProducerConnection < RabbitFeed::Connection
|
3
|
-
|
4
3
|
PUBLISH_OPTIONS = {
|
5
4
|
persistent: true, # Persist the message to disk
|
6
5
|
mandatory: true, # Return the message if it can't be routed to a queue
|
@@ -12,24 +11,24 @@ module RabbitFeed
|
|
12
11
|
no_declare: false, # Create the exchange if it does not exist
|
13
12
|
}.freeze
|
14
13
|
|
15
|
-
def self.handle_returned_message
|
16
|
-
RabbitFeed.log.error {{ event: :returned_message, return_info: return_info }}
|
17
|
-
RabbitFeed.exception_notify
|
14
|
+
def self.handle_returned_message(return_info, _content)
|
15
|
+
RabbitFeed.log.error { { event: :returned_message, return_info: return_info } }
|
16
|
+
RabbitFeed.exception_notify(ReturnedMessageError.new(return_info))
|
18
17
|
end
|
19
18
|
|
20
19
|
def initialize
|
21
20
|
super
|
22
21
|
@exchange = channel.exchange RabbitFeed.configuration.exchange, exchange_options
|
23
|
-
RabbitFeed.log.info {{ event: :exchange_declared, exchange: RabbitFeed.configuration.exchange, options: exchange_options }}
|
24
|
-
exchange.on_return do |return_info,
|
22
|
+
RabbitFeed.log.info { { event: :exchange_declared, exchange: RabbitFeed.configuration.exchange, options: exchange_options } }
|
23
|
+
exchange.on_return do |return_info, _properties, content|
|
25
24
|
RabbitFeed::ProducerConnection.handle_returned_message return_info, content
|
26
25
|
end
|
27
26
|
end
|
28
27
|
|
29
|
-
def publish
|
28
|
+
def publish(message, options)
|
30
29
|
synchronized do
|
31
30
|
bunny_options = (options.merge PUBLISH_OPTIONS)
|
32
|
-
RabbitFeed.log.debug {{ event: :publish, options: options, exchange: RabbitFeed.configuration.exchange }}
|
31
|
+
RabbitFeed.log.debug { { event: :publish, options: options, exchange: RabbitFeed.configuration.exchange } }
|
33
32
|
exchange.publish message, bunny_options
|
34
33
|
end
|
35
34
|
end
|
@@ -40,7 +39,7 @@ module RabbitFeed
|
|
40
39
|
|
41
40
|
def exchange_options
|
42
41
|
{
|
43
|
-
auto_delete: RabbitFeed.configuration.auto_delete_exchange
|
42
|
+
auto_delete: RabbitFeed.configuration.auto_delete_exchange
|
44
43
|
}.merge EXCHANGE_OPTIONS
|
45
44
|
end
|
46
45
|
end
|
@@ -1,100 +1,63 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
if received_expected_event && !with_expected_payload
|
22
|
-
with_expected_payload = expected_payload.nil? || actual_event.payload == expected_payload
|
23
|
-
end
|
24
|
-
return received_expected_event && with_expected_payload
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
alias == matches?
|
29
|
-
|
30
|
-
def does_not_match?(given_proc)
|
31
|
-
!matches?(given_proc, :negative_expectation)
|
32
|
-
end
|
33
|
-
|
34
|
-
def failure_message
|
35
|
-
"expected #{expected_event} with #{expected_payload || 'some payload'} but instead received #{received_events_message}"
|
36
|
-
end
|
37
|
-
|
38
|
-
def negative_failure_message
|
39
|
-
"expected no #{expected_event} event, but received one anyways"
|
40
|
-
end
|
41
|
-
|
42
|
-
alias failure_message_when_negated negative_failure_message
|
43
|
-
|
44
|
-
def description
|
45
|
-
"publish_event #{expected_event}"
|
46
|
-
end
|
47
|
-
|
48
|
-
def supports_block_expectations?
|
49
|
-
true
|
50
|
-
end
|
51
|
-
|
52
|
-
def with(expected_payload=nil, &block)
|
53
|
-
if !!@expected_payload
|
54
|
-
::Kernel.warn "`publish_event` was called with an expected payload already, anything in `with` is ignored"
|
55
|
-
else
|
56
|
-
@expected_payload = expected_payload || block
|
57
|
-
end
|
58
|
-
|
59
|
-
self
|
60
|
-
end
|
1
|
+
require 'rspec/expectations'
|
2
|
+
|
3
|
+
module TestingSupport
|
4
|
+
RSpec::Matchers.define :publish_event do |expected_event, expected_payload = nil|
|
5
|
+
match do |given_proc|
|
6
|
+
RabbitFeed::TestingSupport.published_events.clear
|
7
|
+
given_proc.call rescue nil
|
8
|
+
actual_event = first_matching_event(expected_event)
|
9
|
+
if actual_event.nil?
|
10
|
+
false
|
11
|
+
elsif expected_payload
|
12
|
+
actual_event.payload == expected_payload
|
13
|
+
elsif @included_in_payload
|
14
|
+
(@included_in_payload.to_a - actual_event.payload.to_a).empty?
|
15
|
+
elsif @asserting_block
|
16
|
+
@asserting_block.call(actual_event.payload)
|
17
|
+
else
|
18
|
+
true
|
19
|
+
end
|
20
|
+
end
|
61
21
|
|
62
|
-
|
22
|
+
failure_message do |_str|
|
23
|
+
"expected #{expected_event} with #{expected_payload || @included_in_payload || 'some payload'} but instead received #{received_events_message}"
|
24
|
+
end
|
63
25
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
return false
|
68
|
-
end
|
26
|
+
failure_message_when_negated do |_str|
|
27
|
+
"expected no #{expected_event} event, but received one anyways"
|
28
|
+
end
|
69
29
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
30
|
+
chain :including do |included_in_payload|
|
31
|
+
if expected_payload
|
32
|
+
Kernel.warn '`publish_event` was called with an expected payload already, anything in `including` is ignored'
|
33
|
+
else
|
34
|
+
@included_in_payload = included_in_payload
|
35
|
+
end
|
36
|
+
end
|
74
37
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
38
|
+
chain :asserting do |&block|
|
39
|
+
if expected_payload || @included_in_payload
|
40
|
+
Kernel.warn '`publish_event` was called with an expected payload already, anything in `asserting` is ignored'
|
41
|
+
else
|
42
|
+
@asserting_block = block
|
43
|
+
end
|
44
|
+
end
|
80
45
|
|
81
|
-
|
82
|
-
@expected_payload.respond_to?(:call) ? @expected_payload.call : @expected_payload
|
83
|
-
end
|
46
|
+
supports_block_expectations
|
84
47
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
"#{received_event.name} with #{received_event.payload}"
|
89
|
-
end
|
90
|
-
else
|
91
|
-
'no events'
|
92
|
-
end
|
93
|
-
end
|
48
|
+
def first_matching_event(expected_event)
|
49
|
+
RabbitFeed::TestingSupport.published_events.detect do |event|
|
50
|
+
event.name == expected_event
|
94
51
|
end
|
52
|
+
end
|
95
53
|
|
96
|
-
|
97
|
-
|
54
|
+
def received_events_message
|
55
|
+
if RabbitFeed::TestingSupport.published_events.any?
|
56
|
+
RabbitFeed::TestingSupport.published_events.map do |received_event|
|
57
|
+
"#{received_event.name} with #{received_event.payload}"
|
58
|
+
end
|
59
|
+
else
|
60
|
+
'no events'
|
98
61
|
end
|
99
62
|
end
|
100
63
|
end
|
@@ -8,29 +8,28 @@ module RabbitFeed
|
|
8
8
|
|
9
9
|
attr_accessor :published_events
|
10
10
|
|
11
|
-
def setup
|
11
|
+
def setup(rspec_config)
|
12
12
|
RabbitFeed.environment ||= 'test'
|
13
13
|
capture_published_events rspec_config
|
14
14
|
include_support rspec_config
|
15
15
|
end
|
16
16
|
|
17
|
-
def capture_published_events
|
17
|
+
def capture_published_events(rspec_config)
|
18
18
|
rspec_config.before :each do
|
19
19
|
TestingSupport.capture_published_events_in_context(self)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def capture_published_events_in_context
|
23
|
+
def capture_published_events_in_context(context)
|
24
24
|
TestingSupport.published_events = []
|
25
25
|
mock_connection = context.double(:rabbitmq_connection)
|
26
26
|
context.allow(RabbitFeed::ProducerConnection).to context.receive(:instance).and_return(mock_connection)
|
27
|
-
context.allow(mock_connection).to context.receive(:publish) do |serialized_event,
|
27
|
+
context.allow(mock_connection).to context.receive(:publish) do |serialized_event, _routing_key|
|
28
28
|
TestingSupport.published_events << (Event.deserialize serialized_event)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
def include_support
|
33
|
-
rspec_config.include(RabbitFeed::TestingSupport::RSpecMatchers)
|
32
|
+
def include_support(rspec_config)
|
34
33
|
rspec_config.include(RabbitFeed::TestingSupport::TestingHelpers)
|
35
34
|
end
|
36
35
|
end
|
data/lib/rabbit_feed/version.rb
CHANGED
data/lib/rabbit_feed.rb
CHANGED
@@ -32,19 +32,18 @@ module RabbitFeed
|
|
32
32
|
@configuration ||= (Configuration.load configuration_file_path, environment, application)
|
33
33
|
end
|
34
34
|
|
35
|
-
def exception_notify
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
35
|
+
def exception_notify(exception)
|
36
|
+
return unless defined?(Airbrake)
|
37
|
+
if defined?(Airbrake::VERSION) && Airbrake::VERSION.to_i < 5
|
38
|
+
(Airbrake.notify_or_ignore exception) if Airbrake.configuration.public?
|
39
|
+
elsif defined?(Airbrake::AIRBRAKE_VERSION) && Airbrake::AIRBRAKE_VERSION.to_i >= 5
|
40
|
+
if RabbitFeed.configuration.consumer_exit_after_fail
|
41
|
+
# Will need to send the notification right away, otherwise the `exit` would kill the
|
42
|
+
# Airbrake before the notification is sent out
|
43
|
+
Airbrake.notify_sync exception
|
44
|
+
else
|
45
|
+
# Airbrake notify default to sending notification asynchronously
|
46
|
+
Airbrake.notify exception
|
48
47
|
end
|
49
48
|
end
|
50
49
|
end
|
data/rabbit_feed.gemspec
CHANGED
@@ -8,31 +8,33 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = RabbitFeed::VERSION
|
9
9
|
spec.authors = ['Simply Business']
|
10
10
|
spec.email = ['tech@simplybusiness.co.uk']
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
11
|
+
spec.description = 'A gem providing asynchronous event publish and subscribe capabilities with RabbitMQ.'
|
12
|
+
spec.summary = 'Enables your Ruby applications to perform centralized event logging with RabbitMq'
|
13
13
|
spec.homepage = 'https://github.com/simplybusiness/rabbit_feed'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
|
-
spec.files = `git ls-files`.split(
|
16
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
21
|
# Gem for interfacing with RabbitMq
|
22
|
-
spec.add_dependency 'bunny', '>= 2.0.0', '< 2.
|
22
|
+
spec.add_dependency 'bunny', '>= 2.0.0', '< 2.7.0'
|
23
23
|
# We use some helpers from ActiveSupport
|
24
|
-
spec.add_dependency 'activesupport', '>= 3.2.0', '<
|
24
|
+
spec.add_dependency 'activesupport', '>= 3.2.0', '< 6.0.0'
|
25
25
|
# We use validations from ActiveModel
|
26
|
-
spec.add_dependency 'activemodel', '>= 3.2.0', '<
|
26
|
+
spec.add_dependency 'activemodel', '>= 3.2.0', '< 6.0.0'
|
27
27
|
# Manages process pidfile
|
28
|
-
spec.add_dependency 'pidfile'
|
28
|
+
spec.add_dependency 'pidfile', '~> 0.3'
|
29
29
|
# Schema definitions and serialization for events
|
30
|
-
spec.add_dependency 'avro', '>= 1.5.4', '< 1.
|
30
|
+
spec.add_dependency 'avro', '>= 1.5.4', '< 1.9.0'
|
31
31
|
|
32
|
-
spec.add_development_dependency 'codeclimate-test-reporter'
|
33
|
-
spec.add_development_dependency 'rake'
|
34
|
-
spec.add_development_dependency 'rspec', '
|
35
|
-
spec.add_development_dependency 'rspec-its'
|
36
|
-
spec.add_development_dependency '
|
37
|
-
spec.add_development_dependency '
|
32
|
+
spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0'
|
33
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
34
|
+
spec.add_development_dependency 'rspec', '~> 3.5'
|
35
|
+
spec.add_development_dependency 'rspec-its', '~> 1.2'
|
36
|
+
spec.add_development_dependency 'rubocop', '~> 0.46'
|
37
|
+
spec.add_development_dependency 'rutabaga', '~> 2.1'
|
38
|
+
spec.add_development_dependency 'simplecov', '~> 0.12'
|
39
|
+
spec.add_development_dependency 'timecop', '~> 0.8'
|
38
40
|
end
|
data/run_benchmark
CHANGED
@@ -6,15 +6,16 @@ echo 'Starting test of rails application...'
|
|
6
6
|
# Start the rails application
|
7
7
|
echo 'Starting rails application...'
|
8
8
|
pushd example/rails_app >/dev/null
|
9
|
-
|
10
|
-
|
9
|
+
bundle >/dev/null
|
10
|
+
bin/rails db:environment:set RAILS_ENV=development
|
11
|
+
bundle exec rake db:reset
|
11
12
|
bundle exec unicorn -c config/unicorn.rb -E development -D
|
12
13
|
sleep 1
|
13
14
|
popd >/dev/null
|
14
15
|
echo 'Rails application started'
|
15
16
|
|
16
17
|
# Test publishing via the rails application
|
17
|
-
siege -c 10 -r 10 -
|
18
|
+
siege -c 10 -r 10 -b "http://localhost:8080/beavers POST beaver[name]=`date '+%m/%d/%y %H:%M:%S'`"
|
18
19
|
sleep 4
|
19
20
|
|
20
21
|
# Stop the rails application
|
data/run_example
CHANGED
@@ -16,8 +16,8 @@ echo 'Non rails application consumer started'
|
|
16
16
|
echo 'Starting rails application consumer...'
|
17
17
|
pushd example/rails_app >/dev/null
|
18
18
|
bundle >/dev/null
|
19
|
+
bin/rails db:environment:set RAILS_ENV=development
|
19
20
|
bundle exec rake db:reset
|
20
|
-
bundle exec rake db:reset RAILS_ENV=test
|
21
21
|
bundle exec rake
|
22
22
|
bundle exec rabbit_feed consume --environment development --daemon --verbose
|
23
23
|
sleep 1
|
@@ -4,7 +4,7 @@ step 'I am consuming' do
|
|
4
4
|
set_event_routing
|
5
5
|
set_event_definitions
|
6
6
|
RabbitFeed::ConsumerConnection.instance # Bind the queue
|
7
|
-
@consumer_thread = Thread.new{ RabbitFeed::Consumer.run }
|
7
|
+
@consumer_thread = Thread.new { RabbitFeed::Consumer.run }
|
8
8
|
end
|
9
9
|
|
10
10
|
step 'I publish an event' do
|
@@ -27,23 +27,20 @@ step 'the event remains on the queue' do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
module Turnip::Steps
|
30
|
-
|
31
|
-
def publish event_name
|
30
|
+
def publish(event_name)
|
32
31
|
@event_text = "#{event_name}_#{Time.now.iso8601(6)}"
|
33
|
-
RabbitFeed::Producer.publish_event event_name,
|
32
|
+
RabbitFeed::Producer.publish_event event_name, 'field' => @event_text
|
34
33
|
end
|
35
34
|
|
36
|
-
def assert_event_presence
|
35
|
+
def assert_event_presence(event)
|
37
36
|
expect(event).to_not be_nil
|
38
37
|
expect(event.payload[:field]).to eq @event_text
|
39
38
|
end
|
40
39
|
|
41
40
|
def wait_for_event
|
42
41
|
begin
|
43
|
-
Timeout
|
44
|
-
until @consumed_events.any?
|
45
|
-
sleep 0.1
|
46
|
-
end
|
42
|
+
Timeout.timeout(2.0) do
|
43
|
+
sleep 0.1 until @consumed_events.any?
|
47
44
|
end
|
48
45
|
rescue Timeout::Error
|
49
46
|
end
|