rabbitmq_client 0.0.0.pre → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/.reek.yml +21 -0
- data/.travis.yml +12 -1
- data/README.md +129 -17
- data/bin/setup +4 -0
- data/lib/rabbitmq_client/callback.rb +47 -0
- data/lib/rabbitmq_client/exchange.rb +25 -0
- data/lib/rabbitmq_client/exchange_registry.rb +33 -0
- data/lib/rabbitmq_client/json_formatter.rb +29 -0
- data/lib/rabbitmq_client/json_log_subscriber.rb +90 -0
- data/lib/rabbitmq_client/lifecycle.rb +53 -0
- data/lib/rabbitmq_client/log_subscriber_base.rb +16 -0
- data/lib/rabbitmq_client/logger_builder.rb +35 -0
- data/lib/rabbitmq_client/message_publisher.rb +57 -0
- data/lib/rabbitmq_client/plain_log_subscriber.rb +64 -0
- data/lib/rabbitmq_client/plugin.rb +31 -0
- data/lib/rabbitmq_client/publisher.rb +79 -0
- data/lib/rabbitmq_client/tags_filter.rb +16 -0
- data/lib/rabbitmq_client/text_formatter.rb +42 -0
- data/lib/rabbitmq_client/version.rb +2 -1
- data/lib/rabbitmq_client.rb +99 -2
- data/rabbitmq_client.gemspec +1 -0
- data/script/travis.sh +2 -0
- data/spec/callback_spec.rb +31 -0
- data/spec/exchange_registry_spec.rb +32 -0
- data/spec/json_formatter_spec.rb +43 -0
- data/spec/json_log_subscriber_spec.rb +145 -0
- data/spec/lifecycle_spec.rb +78 -0
- data/spec/plain_log_subscriber_spec.rb +115 -0
- data/spec/plugin_spec.rb +12 -0
- data/spec/publisher_spec.rb +150 -0
- data/spec/rabbitmq_client_spec.rb +83 -0
- data/spec/support/dummy_rabbitmq_client_plugin.rb +13 -0
- data/spec/tags_filter_spec.rb +37 -0
- data/spec/text_formatter_spec.rb +45 -0
- metadata +57 -5
- data/Gemfile.lock +0 -156
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require_relative 'support/dummy_rabbitmq_client_plugin'
|
5
|
+
|
6
|
+
describe RabbitmqClient::Lifecycle do
|
7
|
+
subject { described_class.new }
|
8
|
+
|
9
|
+
let(:callback) { ->(*_args) {} }
|
10
|
+
let(:arguments) { [1, 2] }
|
11
|
+
let(:behavior) { double(Object, before!: nil, after!: nil, inside!: nil) }
|
12
|
+
let(:wrapped_block) { proc { behavior.inside! } }
|
13
|
+
|
14
|
+
describe 'before callbacks' do
|
15
|
+
before do
|
16
|
+
subject.before(:publish, &callback)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'executes before wrapped block' do
|
20
|
+
expect(callback).to receive(:call).with(*arguments).ordered
|
21
|
+
expect(behavior).to receive(:inside!).ordered
|
22
|
+
subject.run_callbacks :publish, *arguments, &wrapped_block
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'after callbacks' do
|
27
|
+
before do
|
28
|
+
subject.after(:publish, &callback)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'executes after wrapped block' do
|
32
|
+
expect(behavior).to receive(:inside!).ordered
|
33
|
+
expect(callback).to receive(:call).with(*arguments).ordered
|
34
|
+
subject.run_callbacks :publish, *arguments, &wrapped_block
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'raises if callback is executed with wrong number of parameters' do
|
39
|
+
subject.before(:publish, &callback)
|
40
|
+
expect do
|
41
|
+
subject.run_callbacks(:publish, 1, 2, 3)
|
42
|
+
end.to raise_error(ArgumentError, /2 parameter/)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'raises for unsupported events' do
|
46
|
+
expect do
|
47
|
+
subject.before(:execute, &callback)
|
48
|
+
end.to raise_error(
|
49
|
+
RabbitmqClient::InvalidCallback,
|
50
|
+
/Unknown callback/
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#callbacks' do
|
55
|
+
before do
|
56
|
+
RabbitmqClient.instance_variable_set(:@lifecycle, nil)
|
57
|
+
RabbitmqClient.configure { |x| x[:plugins] << DummyRabbitmqClientPlugin }
|
58
|
+
end
|
59
|
+
|
60
|
+
after do
|
61
|
+
RabbitmqClient.configure { |x| x[:plugins] = [] }
|
62
|
+
RabbitmqClient.instance_variable_set(:@lifecycle, nil)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'load plugin callbacks' do
|
66
|
+
callbacks = RabbitmqClient.lifecycle.callbacks
|
67
|
+
first_callback = callbacks.values.first
|
68
|
+
last_callback = callbacks.values.last
|
69
|
+
|
70
|
+
expect(callbacks.keys).to eq [:publish]
|
71
|
+
expect(first_callback).to be_kind_of(RabbitmqClient::Callback)
|
72
|
+
expect(first_callback.instance_variable_get(:@before).count).to eq 1
|
73
|
+
expect(first_callback.instance_variable_get(:@after).count).to eq 1
|
74
|
+
expect(last_callback.instance_variable_get(:@before).count).to eq 1
|
75
|
+
expect(last_callback.instance_variable_get(:@after).count).to eq 1
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe RabbitmqClient::PlainLogSubscriber do
|
6
|
+
class DummyEvent < ActiveSupport::Notifications::Event
|
7
|
+
def initialize(event_type, payload = {})
|
8
|
+
super(event_type, Time.now, Time.now, 1, payload)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:error) { double('error') }
|
13
|
+
|
14
|
+
before do
|
15
|
+
allow(error).to receive(:message).and_return('error')
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#publisher_created' do
|
19
|
+
it 'send logger a debug message' do
|
20
|
+
msg = 'The RabbitmqClient publisher is '\
|
21
|
+
'created with the follwong configs {}'
|
22
|
+
expect(subject.logger).to receive(:debug).with(msg)
|
23
|
+
subject.publisher_created(DummyEvent.new(
|
24
|
+
'publisher_created.rabbitmq_client',
|
25
|
+
{}
|
26
|
+
))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#network_error' do
|
31
|
+
let(:payload) { { error: error, options: { exchange_name: 'exchange' } } }
|
32
|
+
it 'send logger a error message' do
|
33
|
+
expect(subject.logger).to receive(:error)
|
34
|
+
.with('Failed to publish a message (error) to exchange (exchange)')
|
35
|
+
subject.network_error(DummyEvent.new(
|
36
|
+
'network_error.rabbitmq_client',
|
37
|
+
payload
|
38
|
+
))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
describe '#overriding_configs' do
|
42
|
+
it 'send logger a debug message' do
|
43
|
+
expect(subject.logger).to receive(:debug)
|
44
|
+
.with('Overriding the follwing configs for the created publisher {}')
|
45
|
+
subject.overriding_configs(DummyEvent.new(
|
46
|
+
'overriding_configs.rabbitmq_client',
|
47
|
+
{}
|
48
|
+
))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
describe '#publishing_message' do
|
52
|
+
it 'send logger a debug message' do
|
53
|
+
msg = 'Start>> Publishing a new message '\
|
54
|
+
'(message_id: undefined ) to the exchange (undefined)'
|
55
|
+
expect(subject.logger).to receive(:debug).with(msg)
|
56
|
+
subject.publishing_message(DummyEvent.new(
|
57
|
+
'publishing_message.rabbitmq_client',
|
58
|
+
{}
|
59
|
+
))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
describe '#published_message' do
|
63
|
+
it 'send logger a debug message' do
|
64
|
+
msg = '<<DONE Published a message to the '\
|
65
|
+
'exchange (undefined) with message_id: undefined'
|
66
|
+
expect(subject.logger).to receive(:info).with(msg)
|
67
|
+
subject.published_message(DummyEvent.new(
|
68
|
+
'published_message.rabbitmq_client',
|
69
|
+
{}
|
70
|
+
))
|
71
|
+
end
|
72
|
+
end
|
73
|
+
describe '#confirming_message' do
|
74
|
+
it 'send logger a debug message' do
|
75
|
+
expect(subject.logger).to receive(:debug)
|
76
|
+
.with('Start>> confirming a message (message_id: undefined)')
|
77
|
+
subject.confirming_message(DummyEvent.new(
|
78
|
+
'confirming_message.rabbitmq_client',
|
79
|
+
{}
|
80
|
+
))
|
81
|
+
end
|
82
|
+
end
|
83
|
+
describe '#message_confirmed' do
|
84
|
+
it 'send logger a debug message' do
|
85
|
+
expect(subject.logger).to receive(:debug)
|
86
|
+
.with('<<DONE confirmed a message (message_id: undefined) Successfuly')
|
87
|
+
subject.message_confirmed(DummyEvent.new(
|
88
|
+
'message_confirmed.rabbitmq_client',
|
89
|
+
{}
|
90
|
+
))
|
91
|
+
end
|
92
|
+
end
|
93
|
+
describe '#exhange_not_found' do
|
94
|
+
let(:payload) { { name: 'exchange' } }
|
95
|
+
it 'send logger a error message' do
|
96
|
+
expect(subject.logger).to receive(:error)
|
97
|
+
.with('The Exchange \'exchange\' cannot be found')
|
98
|
+
subject.exhange_not_found(DummyEvent.new(
|
99
|
+
'exhange_not_found.rabbitmq_client',
|
100
|
+
payload
|
101
|
+
))
|
102
|
+
end
|
103
|
+
end
|
104
|
+
describe '#created_exhange' do
|
105
|
+
let(:payload) { { name: 'exchange' } }
|
106
|
+
it 'send logger a debug message' do
|
107
|
+
expect(subject.logger).to receive(:debug)
|
108
|
+
.with('The exchange exchange is created successfuly')
|
109
|
+
subject.created_exhange(DummyEvent.new(
|
110
|
+
'created_exhange.rabbitmq_client',
|
111
|
+
payload
|
112
|
+
))
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
data/spec/plugin_spec.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
class EmptyRabbitmqClientPlugin < RabbitmqClient::Plugin
|
6
|
+
end
|
7
|
+
|
8
|
+
describe EmptyRabbitmqClientPlugin do
|
9
|
+
it 'raise an EmptyPlugin error' do
|
10
|
+
expect { described_class.new }.to raise_error(RabbitmqClient::EmptyPlugin)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe RabbitmqClient::Publisher do
|
6
|
+
describe '#initialize' do
|
7
|
+
context 'no configs is passed' do
|
8
|
+
let(:publisher) { described_class.new }
|
9
|
+
let(:default_session_params) do
|
10
|
+
{ threaded: false, automatically_recover: false, heartbeat: 0 }
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'create publisher with default values' do
|
14
|
+
expect(
|
15
|
+
publisher.instance_variable_get(:@session_params)
|
16
|
+
).to eq default_session_params
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'configs is passed' do
|
21
|
+
let(:session_params) do
|
22
|
+
{ session_params: {
|
23
|
+
threaded: true,
|
24
|
+
automatically_recover: true,
|
25
|
+
heartbeat_publisher: 10
|
26
|
+
} }
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:publisher) { described_class.new(session_params) }
|
30
|
+
let(:expected) do
|
31
|
+
{ automatically_recover: false, heartbeat: 10,
|
32
|
+
heartbeat_publisher: 10, threaded: false }
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'always overwrites automatically_recover and threaded' do
|
36
|
+
expect(publisher.instance_variable_get(:@session_params)).to eq expected
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'use :heartbeat_publisher value for :heartbeat' do
|
40
|
+
expect(
|
41
|
+
publisher
|
42
|
+
.instance_variable_get(:@session_params)[:heartbeat]
|
43
|
+
).to eq expected[:heartbeat_publisher]
|
44
|
+
expect(
|
45
|
+
publisher
|
46
|
+
.instance_variable_get(:@session_params)[:heartbeat_publisher]
|
47
|
+
).to eq expected[:heartbeat_publisher]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#publish' do
|
53
|
+
let(:bunny_session) { double('bunny_session') }
|
54
|
+
let(:bunny_channel) { double('bunny_channel') }
|
55
|
+
let(:exchange_name) { 'exchange' }
|
56
|
+
let(:exchange) { double('exchange') }
|
57
|
+
let(:confirmed) { true }
|
58
|
+
|
59
|
+
before do
|
60
|
+
allow(Bunny).to receive(:new).and_return(bunny_session)
|
61
|
+
allow(bunny_session).to receive(:start)
|
62
|
+
allow(bunny_session).to receive(:create_channel)
|
63
|
+
.and_return(bunny_channel)
|
64
|
+
allow(bunny_channel).to receive(:confirm_select)
|
65
|
+
allow(exchange).to receive(:create).and_return(exchange)
|
66
|
+
allow(exchange).to receive(:publish)
|
67
|
+
allow(exchange).to receive(:name).and_return('exchange')
|
68
|
+
allow(bunny_channel).to receive(:wait_for_confirms)
|
69
|
+
.and_return(confirmed)
|
70
|
+
allow(bunny_channel).to receive(:close)
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'with minimum config' do
|
74
|
+
let(:publisher) { described_class.new }
|
75
|
+
it {
|
76
|
+
expect(publisher.publish({},
|
77
|
+
exchange_name: exchange_name)).to be_nil
|
78
|
+
}
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'when confirmation fail' do
|
82
|
+
let(:exchange_registry) { double('exchange_registry') }
|
83
|
+
let(:publisher) do
|
84
|
+
described_class.new(exchange_registry: exchange_registry)
|
85
|
+
end
|
86
|
+
|
87
|
+
before do
|
88
|
+
expect(bunny_channel).to receive(:wait_for_confirms).and_return(false)
|
89
|
+
allow(bunny_channel).to receive(:nacked_set).and_return(1)
|
90
|
+
allow(bunny_channel).to receive(:unconfirmed_set).and_return(2)
|
91
|
+
allow(exchange_registry).to receive(:find).and_return(exchange)
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'raises error' do
|
95
|
+
expect do
|
96
|
+
publisher.publish('message',
|
97
|
+
message_id: 'abc',
|
98
|
+
exchange_name: exchange_name)
|
99
|
+
end.to raise_error(
|
100
|
+
RabbitmqClient::MessagePublisher::ConfirmationFailed
|
101
|
+
)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'when exchange is not defined' do
|
106
|
+
let(:exchange_registry) { RabbitmqClient::ExchangeRegistry.new }
|
107
|
+
let(:publisher) do
|
108
|
+
described_class.new(exchange_registry: exchange_registry)
|
109
|
+
end
|
110
|
+
let(:type) { 'test' }
|
111
|
+
let(:options) { {} }
|
112
|
+
|
113
|
+
before do
|
114
|
+
exchange_registry.add(exchange_name, type, options)
|
115
|
+
allow(Bunny::Exchange).to receive(:new).and_return(exchange)
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'defines exchange' do
|
119
|
+
publisher.publish('message',
|
120
|
+
message_id: 'abc',
|
121
|
+
exchange_name: exchange_name)
|
122
|
+
expect(
|
123
|
+
Bunny::Exchange
|
124
|
+
).to have_received(:new)
|
125
|
+
.with(bunny_channel, type, exchange_name, options)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'when error raised' do
|
130
|
+
let(:error) { StandardError.new('network_error') }
|
131
|
+
let(:exchange_registry) { double('exchange_registry') }
|
132
|
+
let(:publisher) do
|
133
|
+
described_class.new(exchange_registry: exchange_registry)
|
134
|
+
end
|
135
|
+
|
136
|
+
before do
|
137
|
+
allow(exchange_registry).to receive(:find).and_return(exchange)
|
138
|
+
expect(bunny_channel).to receive(:wait_for_confirms).and_raise(error)
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'raise an error' do
|
142
|
+
expect do
|
143
|
+
publisher.publish('message',
|
144
|
+
message_id: 'abc',
|
145
|
+
exchange_name: exchange_name)
|
146
|
+
end.to raise_error(error)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -4,4 +4,87 @@ RSpec.describe RabbitmqClient do
|
|
4
4
|
it 'has a version number' do
|
5
5
|
expect(RabbitmqClient::VERSION).not_to be nil
|
6
6
|
end
|
7
|
+
|
8
|
+
describe '.add_exchange' do
|
9
|
+
let(:name) { 'exchange' }
|
10
|
+
let(:type) { 'test_exchange' }
|
11
|
+
|
12
|
+
it 'add exchange to the registry' do
|
13
|
+
registry = RabbitmqClient.instance_variable_get(:@exchange_registry)
|
14
|
+
|
15
|
+
expect do
|
16
|
+
registry.find(name)
|
17
|
+
end.to raise_error(
|
18
|
+
RabbitmqClient::ExchangeRegistry::ExchangeNotFound
|
19
|
+
)
|
20
|
+
RabbitmqClient.add_exchange(name, type {})
|
21
|
+
exchange = registry.find(name)
|
22
|
+
|
23
|
+
expect(exchange.name).to eq(name)
|
24
|
+
expect(exchange.type).to eq(type)
|
25
|
+
expect(exchange.options).to eq({})
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '.publish' do
|
30
|
+
let(:publisher) { double('Publisher') }
|
31
|
+
let(:options) { { headers: { store: { uuid: '123456789' } } } }
|
32
|
+
|
33
|
+
before do
|
34
|
+
allow(RabbitmqClient::Publisher).to receive(:new).and_return(publisher)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'execute the publish callbacks with the mutated headers' do
|
38
|
+
expect(publisher).to receive(:publish).with('message', options)
|
39
|
+
RabbitmqClient.publish('message', options)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '.lifecycle' do
|
44
|
+
it 'return a RabbitmqClient::Lifecycle instance' do
|
45
|
+
expect(RabbitmqClient.lifecycle).to be_kind_of(RabbitmqClient::Lifecycle)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '.logger' do
|
50
|
+
context 'with default settings' do
|
51
|
+
before do
|
52
|
+
RabbitmqClient.instance_variable_set(:@logger, nil)
|
53
|
+
end
|
54
|
+
it 'return a STDOUT logger' do
|
55
|
+
logger = RabbitmqClient.logger
|
56
|
+
logdev = logger.instance_variable_get(:@logdev)
|
57
|
+
dev = logdev.instance_variable_get(:@dev)
|
58
|
+
expect(logger).to be_kind_of(Logger)
|
59
|
+
expect(logger.level).to eq(1)
|
60
|
+
expect(dev.inspect).to eq('#<IO:<STDOUT>>')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
context 'with custome settings' do
|
64
|
+
let(:logger_configs) do
|
65
|
+
{
|
66
|
+
logs_format: 'plain',
|
67
|
+
logs_to_stdout: false,
|
68
|
+
logs_level: :debug,
|
69
|
+
logs_filename: 'testing.log'
|
70
|
+
}
|
71
|
+
end
|
72
|
+
before do
|
73
|
+
RabbitmqClient.instance_variable_set(:@logger, nil)
|
74
|
+
RabbitmqClient.configure do |config|
|
75
|
+
config.logger_configs = logger_configs
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'create file logger' do
|
80
|
+
logger = RabbitmqClient.logger
|
81
|
+
logdev = logger.instance_variable_get(:@logdev)
|
82
|
+
dev = logdev.instance_variable_get(:@dev)
|
83
|
+
expect(RabbitmqClient.config.logger_configs).to eq(logger_configs)
|
84
|
+
expect(logger.level).to eq(0)
|
85
|
+
expect(logger).to be_kind_of(Logger)
|
86
|
+
expect(dev.inspect).to eq('#<File:testing.log>')
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
7
90
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class DummyRabbitmqClientPlugin < RabbitmqClient::Plugin
|
4
|
+
callbacks do |lifecycle|
|
5
|
+
lifecycle.before(:publish) do |_message, options|
|
6
|
+
options[:user_id] = '10101010'
|
7
|
+
options[:user_name] = 'JohnDeo'
|
8
|
+
end
|
9
|
+
lifecycle.after(:publish) do |_delivery_info, _properties, _payload|
|
10
|
+
options[:user_id] = nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe RabbitmqClient::TagsFilter do
|
6
|
+
describe '.tags' do
|
7
|
+
context 'using default values' do
|
8
|
+
it 'return nil as default' do
|
9
|
+
expect(RabbitmqClient::TagsFilter.tags).to eq(nil)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'using RequestStore as global store' do
|
14
|
+
let(:global_store) { double('Store') }
|
15
|
+
before do
|
16
|
+
RabbitmqClient.config.global_store = global_store
|
17
|
+
end
|
18
|
+
|
19
|
+
after do
|
20
|
+
RabbitmqClient.config.global_store = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'return empty hash as default' do
|
24
|
+
allow(global_store).to receive(:store).and_return({})
|
25
|
+
expect(RabbitmqClient::TagsFilter.tags).to eq({})
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'fillter store keys and only return whitelisted keys' do
|
29
|
+
allow(global_store).to receive(:store).and_return(
|
30
|
+
not_allowed: 'test',
|
31
|
+
'x-request-id' => '1010'
|
32
|
+
)
|
33
|
+
expect(RabbitmqClient::TagsFilter.tags).to eq('x-request-id' => '1010')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe RabbitmqClient::TextFormatter do
|
6
|
+
subject { described_class.new }
|
7
|
+
let(:message) { 'Test loG message' }
|
8
|
+
let(:global_store) { double('Store') }
|
9
|
+
let(:time) { Time.now }
|
10
|
+
let(:formated_time) { time.strftime('%Y-%m-%dT%H:%M:%S.%6N ') }
|
11
|
+
|
12
|
+
before do
|
13
|
+
RabbitmqClient.config.global_store = global_store
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
RabbitmqClient.config.global_store = nil
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '.call' do
|
21
|
+
it 'formatt the log message' do
|
22
|
+
allow(global_store).to receive(:store).and_return({})
|
23
|
+
log_line = subject.call('DEBUG', time, nil, message)
|
24
|
+
expect(log_line).to match(
|
25
|
+
/D, \[#{formated_time}#\d+\] DEBUG -- : #{message}/
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'map int severity to string' do
|
30
|
+
allow(global_store).to receive(:store).and_return({})
|
31
|
+
log_line = subject.call(0, time, nil, message)
|
32
|
+
expect(log_line).to match(
|
33
|
+
/D, \[#{formated_time}#\d+\] DEBUG -- : #{message}/
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'add tags to the log message' do
|
38
|
+
allow(global_store).to receive(:store).and_return('x-request-id': '10')
|
39
|
+
log_line = subject.call(1, time, nil, message)
|
40
|
+
expect(log_line).to match(
|
41
|
+
/I, \[#{formated_time}#\d+\] INFO -- : \[x-request-id: 10\] #{message}/
|
42
|
+
)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rabbitmq_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Al-waleed shihadeh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -192,6 +192,20 @@ dependencies:
|
|
192
192
|
- - "~>"
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: 0.2.4
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: solargraph
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - "~>"
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: 0.37.2
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - "~>"
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: 0.37.2
|
195
209
|
- !ruby/object:Gem::Dependency
|
196
210
|
name: timecop
|
197
211
|
requirement: !ruby/object:Gem::Requirement
|
@@ -212,28 +226,55 @@ email:
|
|
212
226
|
- 'wshihadeh dot dev at gmail dot com '
|
213
227
|
executables:
|
214
228
|
- console
|
229
|
+
- setup
|
215
230
|
extensions: []
|
216
231
|
extra_rdoc_files: []
|
217
232
|
files:
|
218
233
|
- ".gitignore"
|
219
234
|
- ".overcommit.yml"
|
235
|
+
- ".reek.yml"
|
220
236
|
- ".rspec"
|
221
237
|
- ".rubocop.yml"
|
222
238
|
- ".ruby-gemset"
|
223
239
|
- ".ruby-version"
|
224
240
|
- ".travis.yml"
|
225
241
|
- Gemfile
|
226
|
-
- Gemfile.lock
|
227
242
|
- LICENSE.txt
|
228
243
|
- README.md
|
229
244
|
- Rakefile
|
230
245
|
- bin/console
|
246
|
+
- bin/setup
|
231
247
|
- lib/rabbitmq_client.rb
|
248
|
+
- lib/rabbitmq_client/callback.rb
|
249
|
+
- lib/rabbitmq_client/exchange.rb
|
250
|
+
- lib/rabbitmq_client/exchange_registry.rb
|
251
|
+
- lib/rabbitmq_client/json_formatter.rb
|
252
|
+
- lib/rabbitmq_client/json_log_subscriber.rb
|
253
|
+
- lib/rabbitmq_client/lifecycle.rb
|
254
|
+
- lib/rabbitmq_client/log_subscriber_base.rb
|
255
|
+
- lib/rabbitmq_client/logger_builder.rb
|
256
|
+
- lib/rabbitmq_client/message_publisher.rb
|
257
|
+
- lib/rabbitmq_client/plain_log_subscriber.rb
|
258
|
+
- lib/rabbitmq_client/plugin.rb
|
259
|
+
- lib/rabbitmq_client/publisher.rb
|
260
|
+
- lib/rabbitmq_client/tags_filter.rb
|
261
|
+
- lib/rabbitmq_client/text_formatter.rb
|
232
262
|
- lib/rabbitmq_client/version.rb
|
233
263
|
- rabbitmq_client.gemspec
|
234
264
|
- script/travis.sh
|
265
|
+
- spec/callback_spec.rb
|
266
|
+
- spec/exchange_registry_spec.rb
|
267
|
+
- spec/json_formatter_spec.rb
|
268
|
+
- spec/json_log_subscriber_spec.rb
|
269
|
+
- spec/lifecycle_spec.rb
|
270
|
+
- spec/plain_log_subscriber_spec.rb
|
271
|
+
- spec/plugin_spec.rb
|
272
|
+
- spec/publisher_spec.rb
|
235
273
|
- spec/rabbitmq_client_spec.rb
|
236
274
|
- spec/spec_helper.rb
|
275
|
+
- spec/support/dummy_rabbitmq_client_plugin.rb
|
276
|
+
- spec/tags_filter_spec.rb
|
277
|
+
- spec/text_formatter_spec.rb
|
237
278
|
homepage: https://github.com/wshihadeh/rabbitmq_client
|
238
279
|
licenses:
|
239
280
|
- MIT
|
@@ -251,14 +292,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
251
292
|
version: '0'
|
252
293
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
253
294
|
requirements:
|
254
|
-
- - "
|
295
|
+
- - ">="
|
255
296
|
- !ruby/object:Gem::Version
|
256
|
-
version:
|
297
|
+
version: '0'
|
257
298
|
requirements: []
|
258
299
|
rubygems_version: 3.0.3
|
259
300
|
signing_key:
|
260
301
|
specification_version: 4
|
261
302
|
summary: RabbitMq client library
|
262
303
|
test_files:
|
304
|
+
- spec/callback_spec.rb
|
305
|
+
- spec/exchange_registry_spec.rb
|
306
|
+
- spec/json_formatter_spec.rb
|
307
|
+
- spec/json_log_subscriber_spec.rb
|
308
|
+
- spec/lifecycle_spec.rb
|
309
|
+
- spec/plain_log_subscriber_spec.rb
|
310
|
+
- spec/plugin_spec.rb
|
311
|
+
- spec/publisher_spec.rb
|
263
312
|
- spec/rabbitmq_client_spec.rb
|
264
313
|
- spec/spec_helper.rb
|
314
|
+
- spec/support/dummy_rabbitmq_client_plugin.rb
|
315
|
+
- spec/tags_filter_spec.rb
|
316
|
+
- spec/text_formatter_spec.rb
|