twingly-amqp 4.5.0 → 5.0.0

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
- SHA256:
3
- metadata.gz: 7551c367b84090b3f0e7345ef8b24128983e194074bea558e3595aeaf7d846ce
4
- data.tar.gz: 8c633747ce2675338de1ac65eb7b67e21e3f39ce036351482736653a1755a597
2
+ SHA1:
3
+ metadata.gz: 4bf473c247b052b8ce685889a9635c1ebc6d2d29
4
+ data.tar.gz: 76f4b60b762f886504740e7d339abd10c2e977c8
5
5
  SHA512:
6
- metadata.gz: 1838eadf2e3fec47833c1dfdbc8000bb18d0c77b3d39d30252cb4d7855f2c83bacf3ffcbc70627043da7d6b402adc95110c28cf60eef84838d49b3b075b4b84d
7
- data.tar.gz: 17c0fa7c47552ff00832b0484dbaea894bf15ecce43c65e3d8cd1cb9abaae6717237ade7b26a77ea7daac4aa43d7ace7092de87ca2d823e0f37161b7e8cfdfbd
6
+ metadata.gz: 7eed41cba865d45e552319c2e6d69542295b2156b3bc0634f158e66db88085cc6f9cee1cfd38622c47b8a96c656e8666248503d8b4c06d755a801e63438130fc
7
+ data.tar.gz: 12ad08613eca61a511fcdf117a913119b304d0ce60f7be67aaea3388f88a1851bc5f0d4210e6a244144c271a13d72276e75628d4565fad590414fdc05e400878
data/lib/twingly/amqp.rb CHANGED
@@ -4,6 +4,7 @@ require "twingly/amqp/connection"
4
4
  require "twingly/amqp/subscription"
5
5
  require "twingly/amqp/ping_options"
6
6
  require "twingly/amqp/pinger"
7
+ require "twingly/amqp/publisher"
7
8
  require "twingly/amqp/default_exchange_publisher"
8
9
  require "twingly/amqp/topic_exchange_publisher"
9
10
  require "twingly/amqp/null_logger"
@@ -1,48 +1,17 @@
1
+ require "twingly/amqp/publisher"
1
2
  require "twingly/amqp/connection"
2
- require "json"
3
- require "ostruct"
4
3
 
5
4
  module Twingly
6
5
  module AMQP
7
6
  class DefaultExchangePublisher
7
+ include Publisher
8
+
8
9
  def initialize(queue_name:, connection: nil)
9
10
  options.routing_key = queue_name
10
11
 
11
12
  connection ||= Connection.instance
12
13
  @exchange = connection.create_channel.default_exchange
13
14
  end
14
-
15
- def publish(message)
16
- raise ArgumentError unless message.respond_to?(:to_h)
17
-
18
- payload = message.to_h.to_json
19
- opts = options.to_h
20
- @exchange.publish(payload, opts)
21
- end
22
-
23
- # only used by tests to avoid sleeping
24
- def publish_with_confirm(message)
25
- channel = @exchange.channel
26
- channel.confirm_select unless channel.using_publisher_confirmations?
27
-
28
- publish(message)
29
-
30
- @exchange.wait_for_confirms
31
- end
32
-
33
- def configure_publish_options
34
- yield options
35
- end
36
-
37
- private
38
-
39
- def options
40
- @options ||=
41
- OpenStruct.new(
42
- content_type: "application/json",
43
- persistent: true,
44
- )
45
- end
46
15
  end
47
16
  end
48
17
  end
@@ -0,0 +1,47 @@
1
+ require "json"
2
+ require "ostruct"
3
+
4
+ module Twingly
5
+ module AMQP
6
+ module Publisher
7
+ def publish(message)
8
+ payload =
9
+ if message.kind_of?(Array)
10
+ message
11
+ elsif message.respond_to?(:to_h)
12
+ message.to_h
13
+ else
14
+ raise ArgumentError
15
+ end
16
+
17
+ json_payload = payload.to_json
18
+ opts = options.to_h
19
+ @exchange.publish(json_payload, opts)
20
+ end
21
+
22
+ # only used by tests to avoid sleeping
23
+ def publish_with_confirm(message)
24
+ channel = @exchange.channel
25
+ channel.confirm_select unless channel.using_publisher_confirmations?
26
+
27
+ publish(message)
28
+
29
+ @exchange.wait_for_confirms
30
+ end
31
+
32
+ def configure_publish_options
33
+ yield options
34
+ end
35
+
36
+ private
37
+
38
+ def options
39
+ @options ||=
40
+ OpenStruct.new(
41
+ content_type: "application/json",
42
+ persistent: true,
43
+ )
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,48 +1,17 @@
1
+ require "twingly/amqp/publisher"
1
2
  require "twingly/amqp/connection"
2
- require "json"
3
- require "ostruct"
4
3
 
5
4
  module Twingly
6
5
  module AMQP
7
6
  class TopicExchangePublisher
7
+ include Publisher
8
+
8
9
  def initialize(exchange_name:, routing_key: nil, connection: nil, opts: {})
9
10
  options.routing_key = routing_key
10
11
 
11
12
  connection ||= Connection.instance
12
13
  @exchange = connection.create_channel.topic(exchange_name, opts)
13
14
  end
14
-
15
- def publish(message)
16
- raise ArgumentError unless message.respond_to?(:to_h)
17
-
18
- payload = message.to_h.to_json
19
- opts = options.to_h
20
- @exchange.publish(payload, opts)
21
- end
22
-
23
- # only used by tests to avoid sleeping
24
- def publish_with_confirm(message)
25
- channel = @exchange.channel
26
- channel.confirm_select unless channel.using_publisher_confirmations?
27
-
28
- publish(message)
29
-
30
- @exchange.wait_for_confirms
31
- end
32
-
33
- def configure_publish_options
34
- yield options
35
- end
36
-
37
- private
38
-
39
- def options
40
- @options ||=
41
- OpenStruct.new(
42
- content_type: "application/json",
43
- persistent: true,
44
- )
45
- end
46
15
  end
47
16
  end
48
17
  end
@@ -1,5 +1,5 @@
1
1
  module Twingly
2
2
  module Amqp
3
- VERSION = "4.5.0".freeze
3
+ VERSION = "5.0.0".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twingly-amqp
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.5.0
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Twingly AB
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-25 00:00:00.000000000 Z
11
+ date: 2019-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -87,6 +87,7 @@ files:
87
87
  - lib/twingly/amqp/null_logger.rb
88
88
  - lib/twingly/amqp/ping_options.rb
89
89
  - lib/twingly/amqp/pinger.rb
90
+ - lib/twingly/amqp/publisher.rb
90
91
  - lib/twingly/amqp/session.rb
91
92
  - lib/twingly/amqp/subscription.rb
92
93
  - lib/twingly/amqp/topic_exchange_publisher.rb
@@ -110,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
111
  version: '0'
111
112
  requirements: []
112
113
  rubyforge_project:
113
- rubygems_version: 2.7.6
114
+ rubygems_version: 2.6.14.1
114
115
  signing_key:
115
116
  specification_version: 4
116
117
  summary: Ruby library for talking to RabbitMQ