rabid_mq 0.1.35 → 0.1.36

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd62092327b8c0d5914d4364b48564eb16c9aba0
4
- data.tar.gz: c468666cc6283c529c5ffdd94ce8df8034e83ecd
3
+ metadata.gz: 60a529e7dee912940f223740162d45767a53f765
4
+ data.tar.gz: 7097749742e8805903bce0a94b1272bf1f5c64c6
5
5
  SHA512:
6
- metadata.gz: 347116d5de2b0c93543cb52c882ca242a2c6ea534a91e75548c8a2a3dbc56e70936fada7f1369711c2f4f3657611aa34100fb81250b64d3be8b4ff1339093a53
7
- data.tar.gz: 87d949b44cdc05cfcd8d52a8d85881e4d20321d106bb865f106cee655bc39918b28dc7cb301de1b41fd34572e21a0bbe9c37563cfc16e7e830640b8e89348097
6
+ metadata.gz: a4308b5d1918dc730e499ec1f4efb7a80c68f6df7958a53565c50e7aac89e97ba7392e0d9ba00de9a42375e0f5f98eac042143bf2bf196f086eea9642e474b3b
7
+ data.tar.gz: 4be16cafabcd10e23addc95ad062d02f5162bd0901f57569ec615fa071f08d9ec8eef68e1b355ce7fe8bdb245f7186b51b185db6b60a72f6d87ff0d9aa84c1aa
@@ -18,33 +18,23 @@ module RabidMQ
18
18
 
19
19
  included do
20
20
  class << self
21
- attr_reader :amqp_queue, :amqp_exchange, :amqp_queue_name
21
+ attr_reader :amqp_queue, :amqp_exchange, :routing_key
22
22
 
23
23
  def amqp(queue, exchange, exclusive: false, routing_key: '#')
24
- # Set up an exchange
25
- setup_exchange(exchange)
26
- queue_name(queue)
27
-
24
+ self.queue_name queue, exclusive: exclusive
25
+ self.exchange(exchange)
28
26
  @routing_key = routing_key
29
-
30
- # Set up Queue
31
- setup_queue(queue, exclusive: exclusive)
32
-
33
- # Bind together
34
27
  amqp_queue.bind(amqp_exchange, routing_key: routing_key)
35
28
  end
36
29
 
37
30
  # Use this as a macro in including classes like
38
31
  # class MyClass
39
32
  # include RabidMQ::Listener
33
+ # queue_name 'some.queue_name', exclusive: true
40
34
  # end
41
35
  #
42
- def queue_name(name)
43
- @amqp_queue_name ||= name
44
- end
45
-
46
- def setup_queue(name, **options)
47
- @amqp_queue = RabidMQ.channel.queue(amqp_queue_name, **options)
36
+ def queue_name(name, **options)
37
+ @amqp_queue = RabidMQ.channel.queue(name_with_env(name), **options)
48
38
  end
49
39
 
50
40
  # Use this as a macro in including classes like
@@ -53,12 +43,10 @@ module RabidMQ
53
43
  # exchange 'exchange.name'
54
44
  # end
55
45
  #
56
- def setup_exchange(topic, **options)
57
- @amqp_exchange = RabidMQ.topic_exchange topic, **options
46
+ def exchange(topic, **options)
47
+ @amqp_exchange = RabidMQ.topic_exchange name_with_env(topic), **options
58
48
  end
59
49
 
60
- alias_method :exchange, :setup_exchange
61
-
62
50
  def bind(exchange=amqp_exchange, routing_key: @routing_key, **options)
63
51
  amqp_queue.bind(exchange, routing_key: routing_key, **options)
64
52
  end
@@ -23,8 +23,8 @@ module RabidMQ
23
23
  end
24
24
 
25
25
  class << self
26
- def amqp_broadcast(topic, payload, routing_key: self.default_amqp_routing_key, **options)
27
- exchange = topic_exchange(topic, **options)
26
+ def amqp_broadcast(topic, payload, routing_key: self.default_amqp_routing_key)
27
+ exchange = topic_exchange(topic)
28
28
  exchange.publish(payload, routing_key: routing_key)
29
29
  rescue => e
30
30
  if defined? ::Rails
@@ -42,6 +42,11 @@ module RabidMQ
42
42
  self.name.underscore.gsub(/\//, '.')
43
43
  end
44
44
 
45
+ # Provide a topic exchange on demand connected to the existing channel
46
+ def topic_exchange(topic, **options)
47
+ channel.topic(name_with_env(topic), **options)
48
+ end
49
+
45
50
  # Provide fanout exchange
46
51
  def fanout_exchange(topic, **options)
47
52
  channel.fanout(name_with_env(topic), **options)
@@ -49,13 +54,12 @@ module RabidMQ
49
54
 
50
55
  # Get a channel with the Bunny::Session
51
56
  delegate :channel,
52
- :name_with_env,
53
- :topic_exchange,
57
+ :reconnect,
54
58
  to: ::RabidMQ
55
59
 
56
- # # Start a new connection
60
+ # Start a new connection
57
61
  def amqp_connect
58
- amqp_connection.tap do |c|
62
+ connection.tap do |c|
59
63
  c.start
60
64
  end
61
65
  end
@@ -67,8 +71,8 @@ module RabidMQ
67
71
  end
68
72
 
69
73
  # Provide a new or existing Bunny::Session
70
- def amqp_connection
71
- @amqp_connection ||= Bunny.new RabidMQ::Config.load_config
74
+ def connection
75
+ @connection ||= Bunny.new RabidMQ::Config.load_config
72
76
  end
73
77
 
74
78
  end
@@ -1,3 +1,3 @@
1
1
  module RabidMQ
2
- VERSION = "0.1.35"
2
+ VERSION = "0.1.36"
3
3
  end
data/lib/rabid_mq.rb CHANGED
@@ -15,17 +15,8 @@ module RabidMQ
15
15
  class << self
16
16
 
17
17
  # Provide a topic exchange on demand connected to the existing channel
18
- def topic_exchange(topic, durable: false, **options)
19
- channel.topic(name_with_env(topic), durable: durable, **options)
20
- rescue Bunny::PreconditionFailed => e
21
- if !e.message.match(/inequivalent arg 'durable'/).nil?
22
- puts "[WARNING] RabbitMQ exchange durability does not match for #{topic}, overriding to match exchange!"
23
- durable = !durable
24
- reconnect
25
- topic_exchange(topic, durable: durable, **options)
26
- else
27
- fail e
28
- end
18
+ def topic_exchange(topic, **options)
19
+ channel.topic(name_with_env(topic), **options)
29
20
  end
30
21
 
31
22
  # Provide fanout exchange
data/rabid_mq.gemspec CHANGED
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ["lib"]
32
32
 
33
- spec.add_dependency 'bunny', '~> 2.9.2'
33
+ spec.add_dependency 'bunny', '~> 2.7.2'
34
34
  spec.add_dependency 'activesupport'
35
35
 
36
36
  spec.add_development_dependency "bundler", "~> 1.14"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rabid_mq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.35
4
+ version: 0.1.36
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyrone Wilson
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.9.2
19
+ version: 2.7.2
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: 2.9.2
26
+ version: 2.7.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement