bunny-publisher 0.1.4 → 0.1.5

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: ca9d3016280b5da1593899d13cc673628ebfaecd541c32ac111e9a0b33dc0694
4
- data.tar.gz: d5c4c936574f79c726689f10a82f057691d20f26df50b46fdb5e799b6fca77bb
3
+ metadata.gz: 9578d81f2d9e983145b25db99694b6600ceb72260af7400d53d222a4f0723d09
4
+ data.tar.gz: 88a145f8ea8e6859d383d9983093d467140f3fe3104a164aa0526125da1defc0
5
5
  SHA512:
6
- metadata.gz: 927b66235ed1b35777b79dcbd4581fdd17a56550074f2842939ba35be74d1069545398308df4a93e3be1ad6f056e4e4d46d607d041aab4a0092790df673d0e2f
7
- data.tar.gz: 3f5493eff0fc05d825dcc17ab8ddc756e06cbabd2420be83ddbcdb3c84c1bc48d8b673328f88dd690ee5e996dbd1272a59d9251b449acfe1d40c6cd17a2d5e5c
6
+ metadata.gz: b256c60e4c18f7c033867a18077273246188aabc01091a9cd27c3927330daa6f461ed35c1bef7890f1817937884c920fd25807530b0ddbf03a436c9dacaf8727
7
+ data.tar.gz: f669cd0022bc139539232aebc467bdba3a0c373fc121ce6a91d2304731b23002e1d51401e4c418435cb753e9ffeaa7f926f5ab52634c84edcc20b3c40c7b49f7
@@ -4,7 +4,13 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
6
6
 
7
- ## [Unreleased](https://github.com/veeqo/bunny-publisher/compare/v0.1.4...HEAD)
7
+ ## [Unreleased](https://github.com/veeqo/bunny-publisher/compare/v0.1.5...HEAD)
8
+
9
+
10
+ ## [0.1.5](https://github.com/veeqo/bunny-publisher/compare/v0.1.4...v0.1.5) - 2020-11-04
11
+
12
+ ### Fixed
13
+ - [#7](https://github.com/veeqo/bunny-publisher/pull/7) Enforce single channel for threaded apps
8
14
 
9
15
 
10
16
  ## [0.1.4](https://github.com/veeqo/bunny-publisher/compare/v0.1.3...v0.1.4) - 2020-11-03
@@ -8,7 +8,7 @@ module BunnyPublisher
8
8
 
9
9
  define_callbacks :after_publish, :before_publish, :around_publish
10
10
 
11
- attr_reader :connection
11
+ attr_reader :connection, :channel, :exchange
12
12
 
13
13
  def initialize(publish_connection: nil, connection: nil, exchange: nil, exchange_options: {}, **options)
14
14
  @mutex = Mutex.new
@@ -25,13 +25,15 @@ module BunnyPublisher
25
25
  end
26
26
 
27
27
  def publish(message, options = {})
28
- ensure_connection!
28
+ @mutex.synchronize do
29
+ ensure_connection!
29
30
 
30
- run_callback(:before_publish, message, options)
31
- result = run_callback(:around_publish, message, options) { exchange.publish(message, options) }
32
- run_callback(:after_publish, message, options)
31
+ run_callback(:before_publish, message, options)
32
+ result = run_callback(:around_publish, message, options) { exchange.publish(message, options) }
33
+ run_callback(:after_publish, message, options)
33
34
 
34
- result
35
+ result
36
+ end
35
37
  end
36
38
 
37
39
  def close
@@ -43,31 +45,14 @@ module BunnyPublisher
43
45
  private
44
46
 
45
47
  def ensure_connection!
46
- @mutex.synchronize { connect! unless connected? }
48
+ connect! unless connected?
47
49
  end
48
50
 
49
51
  def connect!
50
52
  @connection ||= build_connection
51
53
  connection.start
52
-
53
- connection_variables[:channel] ||= connection.create_channel
54
- connection_variables[:exchange] ||= build_exchange
55
- end
56
-
57
- def thread_variables
58
- Thread.current[:bunny_publisher] ||= {}.compare_by_identity
59
- end
60
-
61
- def connection_variables
62
- thread_variables[connection] ||= {}
63
- end
64
-
65
- def channel
66
- connection_variables[:channel]
67
- end
68
-
69
- def exchange
70
- connection_variables[:exchange]
54
+ @channel = connection.create_channel
55
+ @exchange = build_exchange
71
56
  end
72
57
 
73
58
  def build_connection
@@ -49,7 +49,7 @@ module BunnyPublisher
49
49
 
50
50
  private
51
51
 
52
- attr_reader :republish_connection
52
+ attr_reader :republish_connection, :republish_channel, :republish_exchange
53
53
 
54
54
  def connect!
55
55
  super
@@ -65,7 +65,7 @@ module BunnyPublisher
65
65
  end
66
66
 
67
67
  def ensure_republish_connection!
68
- @republish_mutex.synchronize { connect_for_republish! unless connected_for_republish? }
68
+ connect_for_republish! unless connected_for_republish?
69
69
  end
70
70
 
71
71
  def connected_for_republish?
@@ -75,31 +75,19 @@ module BunnyPublisher
75
75
  def connect_for_republish!
76
76
  @republish_connection ||= build_republish_connection
77
77
  republish_connection.start
78
-
79
- republish_connection_variables[:republish_channel] ||= republish_connection.create_channel
80
- republish_connection_variables[:republish_exchange] ||= build_republish_exchange
81
- end
82
-
83
- def republish_connection_variables
84
- thread_variables[republish_connection] ||= {}
85
- end
86
-
87
- def republish_channel
88
- republish_connection_variables[:republish_channel]
89
- end
90
-
91
- def republish_exchange
92
- republish_connection_variables[:republish_exchange]
78
+ @republish_channel = republish_connection.create_channel
79
+ @republish_exchange = clone_exchange_for_republish
93
80
  end
94
81
 
95
82
  def build_republish_connection
96
83
  Bunny.new(connection.instance_variable_get(:'@opts')) # TODO: find more elegant way to "clone" connection
97
84
  end
98
85
 
99
- def build_republish_exchange
100
- return republish_channel.default_exchange if @exchange_name.nil? || @exchange_name == ''
86
+ def clone_exchange_for_republish
87
+ republish_channel.default_exchange if exchange.name == ''
101
88
 
102
- republish_channel.exchange(@exchange_name, @exchange_options)
89
+ republish_channel.exchange exchange.name,
90
+ exchange.instance_variable_get(:'@options').merge(type: exchange.type)
103
91
  end
104
92
 
105
93
  def on_message_return(return_info, properties, message)
@@ -121,14 +109,16 @@ module BunnyPublisher
121
109
  end
122
110
 
123
111
  def setup_queue_for_republish(return_info, properties, message)
124
- ensure_republish_connection!
112
+ @republish_mutex.synchronize do
113
+ ensure_republish_connection!
125
114
 
126
- queue = declare_republish_queue(return_info, properties, message)
115
+ queue = declare_republish_queue(return_info, properties, message)
127
116
 
128
- # default exchange already has bindings with queues
129
- declare_republish_queue_binding(queue, return_info, properties, message) unless republish_exchange.name == ''
117
+ # default exchange already has bindings with queues
118
+ declare_republish_queue_binding(queue, return_info, properties, message) unless republish_exchange.name == ''
130
119
 
131
- republish_channel.deregister_queue(queue) # we are not going to work with this queue in this channel
120
+ republish_channel.deregister_queue(queue) # we are not going to work with this queue in this channel
121
+ end
132
122
  end
133
123
 
134
124
  def ensure_message_is_unrouted!(return_info, properties, message)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BunnyPublisher
4
- VERSION = '0.1.4'
4
+ VERSION = '0.1.5'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bunny-publisher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rustam Sharshenov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-03 00:00:00.000000000 Z
11
+ date: 2020-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  - !ruby/object:Gem::Version
135
135
  version: '0'
136
136
  requirements: []
137
- rubygems_version: 3.1.4
137
+ rubygems_version: 3.0.6
138
138
  signing_key:
139
139
  specification_version: 4
140
140
  summary: AMQP publisher for RabbitMQ based on Bunny