railway-ipc 2.2.1 → 2.2.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: 8153f89992dd3713ca4b6e8792a69d91e80738ae69d26bd3325616c30d854bf2
4
- data.tar.gz: d6680bb1330b885172730f7e9110a255896931d2e627cb50c2b0384cd4a423b2
3
+ metadata.gz: a407ec255b81d23755164c8a2a45393092bd7d5eb2d39caa9e89125974f1822b
4
+ data.tar.gz: 4fd881a27222a11f767f64908aff24851c03a09a3f23cd1dfcf32ea7295c1971
5
5
  SHA512:
6
- metadata.gz: 404ec939662fbc9f4f8e571b95f3d86222c2d8039afd46346ed10b4319b2f5d8a307d4a0047cc75e041b17393031d0a0551088d2f291d4bf70ecd28baf98b449
7
- data.tar.gz: efb5cb9aa4635e7d4a07344a61de6bd1f61d39fecbd8445e7baa2d375413603b7e9398cf391feac8b04a7a7c6fc46f5e9cd56791188ed6fb3e233a856a8e1caa
6
+ metadata.gz: 79135cc5e3a2ee00ec1c79b00f168c5aa4ff7b9bf36c3aba6564c66a5644da1fe787f077443ebf5020660280cd98b58dbd2cc638b64962cc91663226ca87a359
7
+ data.tar.gz: 0ff544182b441fafc71d9be9bfdfc8dfc344dbe9142812559570d7f01cd57cc81d4311599d0a160951d45da9b81309f843f18ae57a3d4010282ba619034b1967
@@ -10,6 +10,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
10
10
  ### Removed
11
11
  ### Fixed
12
12
 
13
+ ## [2.2.2] - 2020-11-20
14
+ ### Fixed
15
+ * Fixed Publisher class channel leak. Channels were being created on each
16
+ instantiation of a Publisher instead of being re-used.
17
+
18
+ ## [2.2.1] - 2020-10-20
19
+ ### Added
20
+ * Logging to indicate when options passed via `listen_to`/`from_queue` are overriding the defaults.
21
+
13
22
  ## [2.2.0] - 2020-10-20
14
23
  ### Added
15
24
  * The ability to configure workers to handle different workloads via `rake railway_ipc::consumers:spawn`
@@ -74,7 +83,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
74
83
  ### Added
75
84
  - Correlation ID and message UUID are auto generated for messages for IDs are not passed in [#23](https://github.com/learn-co/railway_ipc_gem/pull/23)
76
85
 
77
- [Unreleased]: https://github.com/learn-co/railway_ipc_gem/compare/v2.0.3...HEAD
86
+ [Unreleased]: https://github.com/learn-co/railway_ipc_gem/compare/v2.2.2...HEAD
87
+ [2.2.2]: https://github.com/learn-co/railway_ipc_gem/compare/v2.2.1...v2.2.2
88
+ [2.2.1]: https://github.com/learn-co/railway_ipc_gem/compare/v2.2.0...v2.2.1
89
+ [2.2.0]: https://github.com/learn-co/railway_ipc_gem/compare/v2.1.0...v2.2.0
90
+ [2.1.0]: https://github.com/learn-co/railway_ipc_gem/compare/v2.0.3...v2.1.0
78
91
  [2.0.3]: https://github.com/learn-co/railway_ipc_gem/compare/v2.0.2...v2.0.3
79
92
  [2.0.2]: https://github.com/learn-co/railway_ipc_gem/compare/v2.0.1...v2.0.2
80
93
  [2.0.1]: https://github.com/learn-co/railway_ipc_gem/compare/v2.0.0...v2.0.1
@@ -5,6 +5,7 @@ require 'sneakers'
5
5
  require 'sneakers/spawner'
6
6
  require 'bunny'
7
7
  require 'active_record'
8
+ require 'singleton'
8
9
  require 'railway_ipc/logger'
9
10
  require 'railway_ipc/unhandled_message_error'
10
11
  require 'railway_ipc/response'
@@ -14,6 +15,7 @@ require 'railway_ipc/rabbitmq/adapter'
14
15
  require 'railway_ipc/handler'
15
16
  require 'railway_ipc/handler_store'
16
17
  require 'railway_ipc/incoming_message'
18
+ require 'railway_ipc/connection_manager'
17
19
  require 'railway_ipc/publisher'
18
20
  require 'railway_ipc/responder'
19
21
  require 'railway_ipc/rpc/rpc'
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'singleton'
4
+
5
+ module RailwayIpc
6
+ # RabbitMQ connection manager. Ensures there is a single RabbitMQ
7
+ # connection and channel per thread, which prevents channel leaks.
8
+ #
9
+ class ConnectionManager
10
+ include Singleton
11
+
12
+ def initialize
13
+ establish_connection
14
+ end
15
+
16
+ def establish_connection
17
+ @connection = Bunny.new(
18
+ host: settings[:host],
19
+ user: settings[:user],
20
+ pass: settings[:pass],
21
+ port: settings[:port],
22
+ vhost: settings[:vhost] || '/',
23
+ logger: RailwayIpc.logger
24
+ )
25
+ @connection.start
26
+ @channel = @connection.create_channel
27
+
28
+ @connection
29
+ end
30
+
31
+ def channel
32
+ return @channel if connected?
33
+
34
+ establish_connection
35
+ @channel
36
+ end
37
+
38
+ def connected?
39
+ @connection&.connected? && @channel&.open?
40
+ end
41
+
42
+ private
43
+
44
+ def amqp_url
45
+ @amqp_url ||= ENV.fetch('RAILWAY_RABBITMQ_CONNECTION_URL', 'amqp://guest:guest@localhost:5672')
46
+ end
47
+
48
+ def settings
49
+ @settings ||= AMQ::Settings.parse_amqp_url(amqp_url)
50
+ end
51
+ end
52
+ end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'singleton'
4
-
5
3
  module RailwayIpc
6
4
  class SingletonPublisher < Sneakers::Publisher
7
5
  include ::Singleton
@@ -53,19 +51,12 @@ module RailwayIpc
53
51
  end
54
52
 
55
53
  module RailwayIpc
56
- class Publisher < Sneakers::Publisher
54
+ class Publisher
57
55
  attr_reader :exchange_name, :message_store
58
56
 
59
57
  def initialize(opts={})
60
58
  @exchange_name = opts.fetch(:exchange_name)
61
59
  @message_store = opts.fetch(:message_store, RailwayIpc::PublishedMessage)
62
- connection = opts.fetch(:connection, nil)
63
- options = {
64
- exchange: exchange_name,
65
- connection: connection,
66
- exchange_type: :fanout
67
- }.compact
68
- super(options)
69
60
  end
70
61
 
71
62
  # rubocop:disable Metrics/AbcSize
@@ -75,7 +66,7 @@ module RailwayIpc
75
66
  RailwayIpc.logger.info('Publishing message', log_message_options(message))
76
67
 
77
68
  stored_message = message_store.store_message(exchange_name, message)
78
- super(RailwayIpc::Rabbitmq::Payload.encode(message))
69
+ exchange.publish(RailwayIpc::Rabbitmq::Payload.encode(message))
79
70
  rescue RailwayIpc::InvalidProtobuf => e
80
71
  RailwayIpc.logger.error('Invalid protobuf', log_message_options(message))
81
72
  raise e
@@ -88,8 +79,16 @@ module RailwayIpc
88
79
  end
89
80
  # rubocop:enable Metrics/AbcSize
90
81
 
82
+ def exchange
83
+ @exchange ||= channel.exchange(exchange_name, type: :fanout, durable: true, auto_delete: false, arguments: {})
84
+ end
85
+
91
86
  private
92
87
 
88
+ def channel
89
+ RailwayIpc::ConnectionManager.instance.channel
90
+ end
91
+
93
92
  def log_message_options(message)
94
93
  {
95
94
  feature: 'railway_ipc_publisher',
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailwayIpc
4
- VERSION = '2.2.1'
4
+ VERSION = '2.2.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: railway-ipc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-21 00:00:00.000000000 Z
11
+ date: 2020-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -225,6 +225,7 @@ files:
225
225
  - bin/setup
226
226
  - lib/railway_ipc.rb
227
227
  - lib/railway_ipc/Rakefile
228
+ - lib/railway_ipc/connection_manager.rb
228
229
  - lib/railway_ipc/consumer/consumer.rb
229
230
  - lib/railway_ipc/consumer/process_incoming_message.rb
230
231
  - lib/railway_ipc/errors.rb
@@ -278,7 +279,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
278
279
  - !ruby/object:Gem::Version
279
280
  version: '0'
280
281
  requirements: []
281
- rubygems_version: 3.0.3
282
+ rubyforge_project:
283
+ rubygems_version: 2.7.6
282
284
  signing_key:
283
285
  specification_version: 4
284
286
  summary: IPC components for Rails