propono 2.0.0.rc2 → 2.0.0.rc3
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/README.md +3 -3
- data/lib/propono/components/client.rb +1 -1
- data/lib/propono/configuration.rb +27 -22
- data/lib/propono/logger.rb +2 -2
- data/lib/propono/services/queue_listener.rb +1 -1
- data/lib/propono/version.rb +1 -1
- data/test/components/aws_client_test.rb +20 -0
- data/test/configuration_test.rb +38 -0
- data/test/services/publisher_test.rb +0 -6
- data/test/test_helper.rb +15 -20
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97673d01a5c39db6689660e59a8667a342c759ab
|
4
|
+
data.tar.gz: 3e221dff98ec598ee9bd3144bca3dbae9a286de2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94bbdc2ef73278a7258ef1d404c225e26e40db5f62cd5f5f3d1b7a35380b6867e256fc39dbda5755291bca3c5333444190a516a86ffcacaac98a21559cc0371c
|
7
|
+
data.tar.gz: cac7956743dbf2c7eab5237966471ccdc86cc460756d9f0d113284637d360746af27abbb1dc4eea65a962cca18a0a6696a4a74d279e819ad7a152ec8af215af8
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@ It's beautifully simple to use. [Watch an introduction](https://www.youtube.com/
|
|
10
10
|
|
11
11
|
```ruby
|
12
12
|
# On Machine A
|
13
|
-
Propono::Client.new.
|
13
|
+
Propono::Client.new.listen('some-topic') do |message|
|
14
14
|
puts "I just received: #{message}"
|
15
15
|
end
|
16
16
|
|
@@ -26,7 +26,7 @@ Propono::Client.new.publish('some-topic', "The Best Message Ever")
|
|
26
26
|
Version 2 of Propono changed a few things:
|
27
27
|
- We moved from a global interface to a client interface. Rather than calling `publish` and equivalent on `Propono`, you should now initialize a `Propono::Client` and then call everything on that client. This fixes issues with thread safety and global config.
|
28
28
|
- We have also removed the dependancy on Fog and instead switch to the `sns` and `sqs` mini-gems of `aws-sdk`.
|
29
|
-
- UDP and TCP support have been removed,
|
29
|
+
- UDP and TCP support have been removed, and `subscribe_by_post` has been removed.
|
30
30
|
- We are now using long-polling. This makes Propono **significantly** faster (10-100x).
|
31
31
|
|
32
32
|
## Installation
|
@@ -68,7 +68,7 @@ Listening for messages is easy too. Just tell Propono what your application is c
|
|
68
68
|
```ruby
|
69
69
|
client = Propono::Client.new
|
70
70
|
client.config.application_name = "application-name" # Something unique to this app.
|
71
|
-
client.
|
71
|
+
client.listen('some-topic') do |message|
|
72
72
|
# ... Do something interesting with the message
|
73
73
|
end
|
74
74
|
```
|
@@ -51,7 +51,7 @@ module Propono
|
|
51
51
|
|
52
52
|
# Creates a new SNS-SQS subscription on the specified topic.
|
53
53
|
#
|
54
|
-
# This is implicitly called by {#
|
54
|
+
# This is implicitly called by {#listen}.
|
55
55
|
#
|
56
56
|
# @param [String] topic The name of the topic to subscribe to.
|
57
57
|
def subscribe(topic)
|
@@ -5,36 +5,41 @@ module Propono
|
|
5
5
|
|
6
6
|
class Configuration
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
:max_retries, :num_messages_per_poll
|
13
|
-
]
|
14
|
-
attr_writer *SETTINGS
|
15
|
-
|
16
|
-
def initialize
|
17
|
-
self.logger = Propono::Logger.new
|
18
|
-
self.queue_suffix = ""
|
19
|
-
self.use_iam_profile = false
|
20
|
-
self.max_retries = 0
|
21
|
-
self.num_messages_per_poll = 10
|
22
|
-
end
|
8
|
+
def self.add_setting(sym, required: true)
|
9
|
+
define_method(sym) do
|
10
|
+
required ? get_or_raise(sym) : @settings[sym]
|
11
|
+
end
|
23
12
|
|
24
|
-
|
25
|
-
|
26
|
-
get_or_raise(setting)
|
13
|
+
define_method("#{sym}=") do |new_value|
|
14
|
+
@settings[sym] = new_value
|
27
15
|
end
|
28
16
|
end
|
29
17
|
|
30
|
-
|
18
|
+
add_setting :access_key
|
19
|
+
add_setting :secret_key
|
20
|
+
add_setting :queue_region
|
21
|
+
add_setting :application_name
|
22
|
+
add_setting :logger
|
23
|
+
add_setting :max_retries
|
24
|
+
add_setting :num_messages_per_poll
|
25
|
+
|
26
|
+
add_setting :use_iam_profile, required: false
|
27
|
+
add_setting :queue_suffix, required: false
|
28
|
+
|
29
|
+
def initialize
|
30
|
+
@settings = {
|
31
|
+
logger: Propono::Logger.new,
|
32
|
+
queue_suffix: "",
|
33
|
+
use_iam_profile: false,
|
34
|
+
max_retries: 0,
|
35
|
+
num_messages_per_poll: 10
|
36
|
+
}
|
37
|
+
end
|
31
38
|
|
32
39
|
private
|
33
40
|
|
34
41
|
def get_or_raise(setting)
|
35
|
-
|
36
|
-
val.nil?? raise(ProponoConfigurationError.new("Configuration for #{setting} is not set")) : val
|
42
|
+
@settings[setting] || raise(ProponoConfigurationError.new("Configuration for #{setting} is not set"))
|
37
43
|
end
|
38
44
|
end
|
39
45
|
end
|
40
|
-
|
data/lib/propono/logger.rb
CHANGED
@@ -6,13 +6,13 @@ module Propono
|
|
6
6
|
|
7
7
|
StdLevels.each do |level|
|
8
8
|
define_method level do |*args|
|
9
|
-
$stdout.puts
|
9
|
+
$stdout.puts(*args)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
ErrorLevels.each do |level|
|
14
14
|
define_method level do |*args|
|
15
|
-
$stderr.puts
|
15
|
+
$stderr.puts(*args)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -93,7 +93,7 @@ module Propono
|
|
93
93
|
|
94
94
|
def requeue_message_on_failure(sqs_message, exception)
|
95
95
|
next_queue = (sqs_message.failure_count < propono_config.max_retries) ? main_queue : failed_queue
|
96
|
-
propono_config.logger.error "Error
|
96
|
+
propono_config.logger.error "Error processing message, moving to queue: #{next_queue}"
|
97
97
|
aws_client.send_to_sqs(next_queue, sqs_message.to_json_with_exception(exception))
|
98
98
|
end
|
99
99
|
|
data/lib/propono/version.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Propono
|
4
|
+
class AwsClientTest < Minitest::Test
|
5
|
+
|
6
|
+
def test_publish_to_sns_proxies
|
7
|
+
client = AwsClient.new(nil)
|
8
|
+
sns_client = mock
|
9
|
+
message = {foo: 'bar'}
|
10
|
+
topic_arn = "asd"
|
11
|
+
topic = mock(arn: topic_arn)
|
12
|
+
sns_client.expects(:publish).with(
|
13
|
+
topic_arn: topic_arn,
|
14
|
+
message: message.to_json
|
15
|
+
)
|
16
|
+
client.stubs(sns_client: sns_client)
|
17
|
+
client.publish_to_sns(topic, message)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/test/configuration_test.rb
CHANGED
@@ -45,12 +45,29 @@ module Propono
|
|
45
45
|
assert_equal application_name, propono_config.application_name
|
46
46
|
end
|
47
47
|
|
48
|
+
def test_default_logger
|
49
|
+
assert propono_config.logger.is_a?(Propono::Logger)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_logger
|
53
|
+
propono_config.logger = :my_logger
|
54
|
+
assert_equal :my_logger, propono_config.logger
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_default_queue_suffix
|
58
|
+
assert_equal "", propono_config.queue_suffix
|
59
|
+
end
|
60
|
+
|
48
61
|
def test_queue_suffix
|
49
62
|
queue_suffix = "test-application-name"
|
50
63
|
propono_config.queue_suffix = queue_suffix
|
51
64
|
assert_equal queue_suffix, propono_config.queue_suffix
|
52
65
|
end
|
53
66
|
|
67
|
+
def test_default_num_messages_per_poll
|
68
|
+
assert_equal 10, propono_config.num_messages_per_poll
|
69
|
+
end
|
70
|
+
|
54
71
|
def test_num_messages_per_poll
|
55
72
|
val = 3
|
56
73
|
propono_config.num_messages_per_poll = val
|
@@ -81,6 +98,27 @@ module Propono
|
|
81
98
|
end
|
82
99
|
end
|
83
100
|
|
101
|
+
def test_missing_logger_throws_exception
|
102
|
+
propono_config.logger = nil
|
103
|
+
assert_raises(ProponoConfigurationError) do
|
104
|
+
propono_config.logger
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_missing_max_retries_throws_exception
|
109
|
+
propono_config.max_retries = nil
|
110
|
+
assert_raises(ProponoConfigurationError) do
|
111
|
+
propono_config.max_retries
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_missing_num_messages_per_poll_throws_exception
|
116
|
+
propono_config.num_messages_per_poll = nil
|
117
|
+
assert_raises(ProponoConfigurationError) do
|
118
|
+
propono_config.num_messages_per_poll
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
84
122
|
def test_default_max_retries
|
85
123
|
assert_equal 0, propono_config.max_retries
|
86
124
|
end
|
@@ -115,12 +115,6 @@ module Propono
|
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
118
|
-
def test_publish_should_raise_exception_if_topic_is_nil
|
119
|
-
assert_raises(PublisherError, "Topic is nil") do
|
120
|
-
Publisher.publish(aws_client, propono_config, nil, "foobar")
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
118
|
def test_publish_should_raise_exception_if_message_is_nil
|
125
119
|
assert_raises(PublisherError, "Message is nil") do
|
126
120
|
Publisher.publish(aws_client, propono_config, "foobar", nil)
|
data/test/test_helper.rb
CHANGED
@@ -14,28 +14,23 @@ class Minitest::Test
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def propono_config
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
@propono_config.logger.stubs(:error)
|
29
|
-
|
30
|
-
@propono_config
|
17
|
+
@propono_config ||= Propono::Configuration.new.tap do |c|
|
18
|
+
c.access_key = "test-access-key"
|
19
|
+
c.secret_key = "test-secret-key"
|
20
|
+
c.queue_region = "us-east-1"
|
21
|
+
c.application_name = "MyApp"
|
22
|
+
c.queue_suffix = ""
|
23
|
+
|
24
|
+
c.logger.stubs(:debug)
|
25
|
+
c.logger.stubs(:info)
|
26
|
+
c.logger.stubs(:error)
|
27
|
+
end
|
31
28
|
end
|
32
29
|
|
33
30
|
def aws_client
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
@aws_client.stubs(:sqs_client)
|
39
|
-
@aws_client
|
31
|
+
@aws_client ||= Propono::AwsClient.new(mock).tap do |c|
|
32
|
+
c.stubs(:sns_client)
|
33
|
+
c.stubs(:sqs_client)
|
34
|
+
end
|
40
35
|
end
|
41
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: propono
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.
|
4
|
+
version: 2.0.0.rc3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MalcyL
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-10-
|
12
|
+
date: 2017-10-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-sdk-sns
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- lib/propono/utils.rb
|
143
143
|
- lib/propono/version.rb
|
144
144
|
- propono.gemspec
|
145
|
+
- test/components/aws_client_test.rb
|
145
146
|
- test/components/aws_config_test.rb
|
146
147
|
- test/components/client_test.rb
|
147
148
|
- test/components/queue_subscription_test.rb
|
@@ -182,6 +183,7 @@ signing_key:
|
|
182
183
|
specification_version: 4
|
183
184
|
summary: General purpose pub/sub library built on top of AWS SNS and SQS
|
184
185
|
test_files:
|
186
|
+
- test/components/aws_client_test.rb
|
185
187
|
- test/components/aws_config_test.rb
|
186
188
|
- test/components/client_test.rb
|
187
189
|
- test/components/queue_subscription_test.rb
|