action_subscriber 1.1.1-java → 1.2.0-java
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 +4 -4
- data/lib/action_subscriber.rb +5 -0
- data/lib/action_subscriber/configuration.rb +3 -2
- data/lib/action_subscriber/publisher.rb +44 -0
- data/lib/action_subscriber/version.rb +1 -1
- data/spec/integration/basic_subscriber_spec.rb +2 -4
- data/spec/lib/action_subscriber/publisher_spec.rb +35 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8ac8ca1abfdea9c1287f1ab1a3eb0f4cb87202e
|
4
|
+
data.tar.gz: 4aa07506925ccece2a22b7ef791440b16dbaa296
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2c368899041edc7e2a7fae22f57b99395999ec1e4ce36e71d55f207151c412b8813769556cb9ed570353c22f7a708d36d2a8f13c495cabe745ebeff1686621b
|
7
|
+
data.tar.gz: 3067a218566272a88497743de4a01ebb314a65af374f21943850d3077e9ff4d5270752eb9bedae848f00983e0d6289e1a4a810fee6f987627fcaa84aea85112c
|
data/lib/action_subscriber.rb
CHANGED
@@ -20,6 +20,7 @@ require "action_subscriber/subscribable"
|
|
20
20
|
require "action_subscriber/bunny/subscriber"
|
21
21
|
require "action_subscriber/march_hare/subscriber"
|
22
22
|
require "action_subscriber/babou"
|
23
|
+
require "action_subscriber/publisher"
|
23
24
|
require "action_subscriber/threadpool"
|
24
25
|
require "action_subscriber/base"
|
25
26
|
|
@@ -92,3 +93,7 @@ module ActionSubscriber
|
|
92
93
|
end
|
93
94
|
|
94
95
|
require "action_subscriber/railtie" if defined?(Rails)
|
96
|
+
|
97
|
+
at_exit do
|
98
|
+
::ActionSubscriber::RabbitConnection.publisher_disconnect!
|
99
|
+
end
|
@@ -11,11 +11,12 @@ module ActionSubscriber
|
|
11
11
|
:pop_interval,
|
12
12
|
:port,
|
13
13
|
:prefetch,
|
14
|
+
:publisher_confirms,
|
14
15
|
:threadpool_size,
|
15
16
|
:timeout,
|
16
17
|
:times_to_pop
|
17
18
|
|
18
|
-
DEFAULTS = {
|
19
|
+
DEFAULTS = {
|
19
20
|
:allow_low_priority_methods => false,
|
20
21
|
:default_exchange => 'events',
|
21
22
|
:heartbeat => 5,
|
@@ -25,6 +26,7 @@ module ActionSubscriber
|
|
25
26
|
:pop_interval => 100, # in milliseconds
|
26
27
|
:port => 5672,
|
27
28
|
:prefetch => 200,
|
29
|
+
:publisher_confirms => false,
|
28
30
|
:threadpool_size => 8,
|
29
31
|
:timeout => 1,
|
30
32
|
:times_to_pop => 8
|
@@ -51,7 +53,6 @@ module ActionSubscriber
|
|
51
53
|
##
|
52
54
|
# Instance Methods
|
53
55
|
#
|
54
|
-
|
55
56
|
def initialize
|
56
57
|
self.decoder = {
|
57
58
|
'application/json' => lambda { |payload| JSON.parse(payload) },
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module ActionSubscriber
|
2
|
+
module Publisher
|
3
|
+
# Publish a message to RabbitMQ
|
4
|
+
#
|
5
|
+
# @param [String] route The routing key to use for this message.
|
6
|
+
# @param [String] payload The message you are sending. Should already be encoded as a string.
|
7
|
+
# @param [String] exchange The exchange you want to publish to.
|
8
|
+
# @param [Hash] options hash to set message parameters (e.g. headers)
|
9
|
+
def self.publish(route, payload, exchange_name, options = {})
|
10
|
+
with_exchange(exchange_name) do |exchange|
|
11
|
+
exchange.publish(payload, publishing_options(route, options))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.with_exchange(exchange_name)
|
16
|
+
connection = RabbitConnection.publisher_connection
|
17
|
+
channel = connection.create_channel
|
18
|
+
begin
|
19
|
+
channel.confirm_select if ActionSubscriber.configuration.publisher_confirms
|
20
|
+
exchange = channel.topic(exchange_name)
|
21
|
+
yield(exchange)
|
22
|
+
channel.wait_for_confirms if ActionSubscriber.configuration.publisher_confirms
|
23
|
+
ensure
|
24
|
+
channel.close rescue nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.publishing_options(route, options = {})
|
29
|
+
options[:mandatory] = false unless options.key(:mandatory)
|
30
|
+
options[:persistent] = false unless options.key(:persistent)
|
31
|
+
options[:routing_key] = route
|
32
|
+
|
33
|
+
if ::RUBY_PLATFORM == "java"
|
34
|
+
java_options = {}
|
35
|
+
java_options[:mandatory] = options.delete(:mandatory)
|
36
|
+
java_options[:routing_key] = options.delete(:routing_key)
|
37
|
+
java_options[:properties] = options
|
38
|
+
java_options
|
39
|
+
else
|
40
|
+
options
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -21,10 +21,8 @@ describe "A Basic Subscriber", :integration => true do
|
|
21
21
|
|
22
22
|
context "ActionSubscriber.auto_pop!" do
|
23
23
|
it "routes messages to the right place" do
|
24
|
-
|
25
|
-
|
26
|
-
exchange.publish("Ohai Booked", :routing_key => "greg.basic_push.booked")
|
27
|
-
exchange.publish("Ohai Cancelled", :routing_key => "basic.cancelled")
|
24
|
+
::ActionSubscriber::Publisher.publish("greg.basic_push.booked", "Ohai Booked", "events")
|
25
|
+
::ActionSubscriber::Publisher.publish("basic.cancelled", "Ohai Cancelled", "events")
|
28
26
|
|
29
27
|
verify_expectation_within(2.0) do
|
30
28
|
::ActionSubscriber.auto_pop!
|
@@ -0,0 +1,35 @@
|
|
1
|
+
describe ::ActionSubscriber::Publisher do
|
2
|
+
let(:exchange) { double("Rabbit Exchange") }
|
3
|
+
let(:exchange_name) { "events" }
|
4
|
+
let(:payload) { "Yo Dawg" }
|
5
|
+
let(:route) { "bob.users.created" }
|
6
|
+
|
7
|
+
before { allow(described_class).to receive(:with_exchange).with(exchange_name).and_yield(exchange) }
|
8
|
+
|
9
|
+
describe '.publish' do
|
10
|
+
|
11
|
+
if ::RUBY_PLATFORM == "java"
|
12
|
+
it "publishes to the exchange with default options for march_hare" do
|
13
|
+
expect(exchange).to receive(:publish) do |published_payload, published_options|
|
14
|
+
expect(published_payload).to eq(payload)
|
15
|
+
expect(published_options[:routing_key]).to eq(route)
|
16
|
+
expect(published_options[:mandatory]).to eq(false)
|
17
|
+
expect(published_options[:properties][:persistent]).to eq(false)
|
18
|
+
end
|
19
|
+
|
20
|
+
described_class.publish(route, payload, exchange_name)
|
21
|
+
end
|
22
|
+
else
|
23
|
+
it "publishes to the exchange with default options for bunny" do
|
24
|
+
expect(exchange).to receive(:publish) do |published_payload, published_options|
|
25
|
+
expect(published_payload).to eq(payload)
|
26
|
+
expect(published_options[:routing_key]).to eq(route)
|
27
|
+
expect(published_options[:persistent]).to eq(false)
|
28
|
+
expect(published_options[:mandatory]).to eq(false)
|
29
|
+
end
|
30
|
+
|
31
|
+
described_class.publish(route, payload, exchange_name)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_subscriber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Brian Stien
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2015-09-
|
15
|
+
date: 2015-09-29 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
requirement: !ruby/object:Gem::Requirement
|
@@ -196,6 +196,7 @@ files:
|
|
196
196
|
- lib/action_subscriber/middleware/error_handler.rb
|
197
197
|
- lib/action_subscriber/middleware/router.rb
|
198
198
|
- lib/action_subscriber/middleware/runner.rb
|
199
|
+
- lib/action_subscriber/publisher.rb
|
199
200
|
- lib/action_subscriber/rabbit_connection.rb
|
200
201
|
- lib/action_subscriber/railtie.rb
|
201
202
|
- lib/action_subscriber/rspec.rb
|
@@ -219,6 +220,7 @@ files:
|
|
219
220
|
- spec/lib/action_subscriber/middleware/error_handler_spec.rb
|
220
221
|
- spec/lib/action_subscriber/middleware/router_spec.rb
|
221
222
|
- spec/lib/action_subscriber/middleware/runner_spec.rb
|
223
|
+
- spec/lib/action_subscriber/publisher_spec.rb
|
222
224
|
- spec/lib/action_subscriber/subscribable_spec.rb
|
223
225
|
- spec/lib/action_subscriber/threadpool_spec.rb
|
224
226
|
- spec/spec_helper.rb
|
@@ -265,6 +267,7 @@ test_files:
|
|
265
267
|
- spec/lib/action_subscriber/middleware/error_handler_spec.rb
|
266
268
|
- spec/lib/action_subscriber/middleware/router_spec.rb
|
267
269
|
- spec/lib/action_subscriber/middleware/runner_spec.rb
|
270
|
+
- spec/lib/action_subscriber/publisher_spec.rb
|
268
271
|
- spec/lib/action_subscriber/subscribable_spec.rb
|
269
272
|
- spec/lib/action_subscriber/threadpool_spec.rb
|
270
273
|
- spec/spec_helper.rb
|