rabbitmq_client 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a2b060865b600b3377cbb16799ecdc82fedbd874b8b9f158c58a57604925c7b8
4
- data.tar.gz: 211d0b536583982f7248a188daab96c77ec2a37765f840bdf85b4dfb9bf27930
3
+ metadata.gz: f1ef09ac95da0ede5b1635fc2c1317f972e41c72868badb5ec79c9b3848d1b7d
4
+ data.tar.gz: c2798f711e2995e47b9e46649b04c730a2e7541769b9526498c1087771f6c2e3
5
5
  SHA512:
6
- metadata.gz: 7ca283805742bb671e6f43818ba3c9ad4f2ad8587f708c1d41fd472ccfaefa6e50f8d615feffeb4699a7a5f1b8957ebe5eda770f77229cab60a8283c066640b5
7
- data.tar.gz: 5431a7e2bfe7a6ef70ab1bdcdb9e79069178b1071f09a481c656c431d7e7174291efbf4861d6e4ee35fc7cfc6d0d3620e1fff7a188b5d83a6bc3c3765cbb2224
6
+ metadata.gz: 7df0e4e90fcf1ae255822730a5162209a69374a12f643e8ac9f0ea0d524f48ad797cdf3132e604bc816bf2a2590fdc77ece185c05a0b80e293501ed62e20312d
7
+ data.tar.gz: b5f09649b1a0c4937418bc19d61befe0b60bc74ddef757a684ffd0b14cf22901112b1602ab79badc886205365c7d9288e08a4e8ada68c18a12d7c4113ecfaf87
data/.overcommit.yml CHANGED
@@ -31,3 +31,5 @@
31
31
  #
32
32
  # IndexTags:
33
33
  # enabled: true # Generate a tags file with `ctags` each time HEAD changes
34
+
35
+
data/.reek.yml CHANGED
@@ -13,6 +13,8 @@ detectors:
13
13
  - "RabbitmqClient::Plugin#callback_block"
14
14
  UtilityFunction:
15
15
  exclude:
16
+ - 'RabbitmqClient::PublisherJob#notify'
17
+ - 'RabbitmqClient::PublisherJob#handle_publish_event'
16
18
  - 'RabbitmqClient::Publisher#notify'
17
19
  - 'LogSubscriberBase#logger'
18
20
  - 'RabbitmqClient::JsonLogSubscriber'
data/README.md CHANGED
@@ -127,7 +127,7 @@ end
127
127
  ## <a name="plugins"></a> Plugins
128
128
  RabbitmqClient plugins are classes that define a callbacks that can be executed before or after events that occuers during RabbitmqClient lifecycle.
129
129
  Current supprted lifecycle events are:
130
- - publish: occure when publisgin a massage is triggered.
130
+ - publish: occure when publishing a massage is triggered.
131
131
 
132
132
  Here is an example where we define a plugin to add some headers to message options before publishing the message.
133
133
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'message_publisher'
3
+ require_relative 'publisher_job'
4
4
 
5
5
  module RabbitmqClient
6
6
  # Publisher class is responsible for publishing events to rabbitmq exhanges
@@ -17,14 +17,21 @@ module RabbitmqClient
17
17
  def publish(data, options)
18
18
  return nil unless @exchange_registry
19
19
 
20
- handle_publish_event(data, options)
21
- rescue StandardError => e
22
- notify('network_error', error: e, options: options)
23
- raise
20
+ if async
21
+ PublisherJob.perform_async(@exchange_registry,
22
+ @session_pool, data, options)
23
+ else
24
+ PublisherJob.new.perform(@exchange_registry,
25
+ @session_pool, data, options)
26
+ end
24
27
  end
25
28
 
26
29
  private
27
30
 
31
+ def async
32
+ @config.dig(:session_params, :async_publisher) || false
33
+ end
34
+
28
35
  def overwritten_config_notification
29
36
  return unless overwritten_config?
30
37
 
@@ -48,19 +55,6 @@ module RabbitmqClient
48
55
  ) || 0)
49
56
  end
50
57
 
51
- def handle_publish_event(data, options)
52
- exchange = @exchange_registry.find(options.fetch(:exchange_name, nil))
53
- @session_pool.with do |session|
54
- session.start
55
- channel = session.create_channel
56
- channel.confirm_select
57
- message = MessagePublisher.new(data, exchange, channel, options)
58
- message.publish
59
- message.wait_for_confirms
60
- channel.close
61
- end
62
- end
63
-
64
58
  def create_connection_pool
65
59
  pool_size = @session_params.fetch(:session_pool, 1)
66
60
  ConnectionPool.new(size: pool_size) do
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'message_publisher'
4
+ require 'sucker_punch'
5
+
6
+ module RabbitmqClient
7
+ # Publisher class is responsible for publishing events to rabbitmq exhanges
8
+ class PublisherJob
9
+ include SuckerPunch::Job
10
+
11
+ def perform(registry, session_pool, data, options)
12
+ handle_publish_event(registry, session_pool, data, options)
13
+ rescue StandardError => e
14
+ notify('network_error', error: e, options: options)
15
+ raise
16
+ end
17
+
18
+ private
19
+
20
+ def handle_publish_event(registry, session_pool, data, options)
21
+ exchange = registry.find(options.fetch(:exchange_name, nil))
22
+ session_pool.with do |session|
23
+ session.start
24
+ channel = session.create_channel
25
+ channel.confirm_select
26
+ message = MessagePublisher.new(data, exchange, channel, options)
27
+ message.publish
28
+ message.wait_for_confirms
29
+ channel.close
30
+ end
31
+ end
32
+
33
+ def notify(event, payload = {})
34
+ ActiveSupport::Notifications.instrument(
35
+ "#{event}.rabbitmq_client",
36
+ payload
37
+ )
38
+ end
39
+ end
40
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # :nodoc:
4
4
  module RabbitmqClient
5
- VERSION = '0.0.1'
5
+ VERSION = '0.0.2'
6
6
  end
@@ -53,6 +53,7 @@ module RabbitmqClient
53
53
  config_accessor(:session_params, instance_accessor: false) do
54
54
  {
55
55
  heartbeat_publisher: 0,
56
+ async_publisher: true,
56
57
  session_pool: 1
57
58
  }
58
59
  end
@@ -18,9 +18,10 @@ Gem::Specification.new do |spec|
18
18
  spec.metadata['allowed_push_host'] = 'https://rubygems.org'
19
19
  spec.metadata['homepage_uri'] = spec.homepage
20
20
 
21
- spec.add_runtime_dependency 'activesupport', '~> 6.0.0'
22
- spec.add_runtime_dependency 'bunny', '~> 2.14.3'
21
+ spec.add_runtime_dependency 'activesupport', '> 5.0.0'
22
+ spec.add_runtime_dependency 'bunny', '>= 2.7.4'
23
23
  spec.add_runtime_dependency 'connection_pool', '~> 2.2.2'
24
+ spec.add_runtime_dependency 'sucker_punch', '~> 2.0'
24
25
 
25
26
  spec.add_development_dependency 'bundler', '~> 1.17.2'
26
27
  spec.add_development_dependency 'byebug', '~> 11.0.1'
@@ -126,6 +126,30 @@ describe RabbitmqClient::Publisher do
126
126
  end
127
127
  end
128
128
 
129
+ context 'when async is enabled' do
130
+ let(:exchange_registry) { RabbitmqClient::ExchangeRegistry.new }
131
+ let(:publisher) do
132
+ described_class.new(exchange_registry: exchange_registry,
133
+ session_params: { async_publisher: true })
134
+ end
135
+ let(:type) { 'test' }
136
+ let(:options) { {} }
137
+
138
+ before do
139
+ exchange_registry.add(exchange_name, type, options)
140
+ allow(RabbitmqClient::PublisherJob).to receive(:perform_async)
141
+ end
142
+
143
+ it 'defines exchange' do
144
+ publisher.publish('message',
145
+ message_id: 'abc',
146
+ exchange_name: exchange_name)
147
+ expect(
148
+ RabbitmqClient::PublisherJob
149
+ ).to have_received(:perform_async)
150
+ end
151
+ end
152
+
129
153
  context 'when error raised' do
130
154
  let(:error) { StandardError.new('network_error') }
131
155
  let(:exchange_registry) { double('exchange_registry') }
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rabbitmq_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
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-06 00:00:00.000000000 Z
11
+ date: 2020-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
- version: 6.0.0
19
+ version: 5.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">"
25
25
  - !ruby/object:Gem::Version
26
- version: 6.0.0
26
+ version: 5.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bunny
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 2.14.3
33
+ version: 2.7.4
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 2.14.3
40
+ version: 2.7.4
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: connection_pool
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.2.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: sucker_punch
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -257,6 +271,7 @@ files:
257
271
  - lib/rabbitmq_client/plain_log_subscriber.rb
258
272
  - lib/rabbitmq_client/plugin.rb
259
273
  - lib/rabbitmq_client/publisher.rb
274
+ - lib/rabbitmq_client/publisher_job.rb
260
275
  - lib/rabbitmq_client/tags_filter.rb
261
276
  - lib/rabbitmq_client/text_formatter.rb
262
277
  - lib/rabbitmq_client/version.rb