aws-broker 0.0.2 → 0.0.3

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
  SHA1:
3
- metadata.gz: c78e1a8326e34ac698ddf33e647d8d263c101256
4
- data.tar.gz: 8d4a5395d3a052901010f33758b112c54f46d478
3
+ metadata.gz: 47445eb1fe64609e924b638fba632b0d59808374
4
+ data.tar.gz: ffaa55778697fe1c9fa6dd4e59d79e07dbd23f6a
5
5
  SHA512:
6
- metadata.gz: 8dd6ecdeeeed53fa28f319acd16a3cbdbfcd471807869868db89e6a8156a7a09c03208f2fa094101e7f081f08359700591e0a72186aa5296d6d9d5b7afb736aa
7
- data.tar.gz: 21f4532b4ec60c021ae997e197d0e343a719cc6e8188538fee0f0e1d8a7f2beef07c9b4aee2214787bfc84b6ceb13f88da5a47ca8663386361fb5a95584c5bda
6
+ metadata.gz: 00cbd98f3230911e14f541a5f917e6009ed6c83673f8298d73cebe9f0a1a522c9eb903d38cbcafae28e933b5c702639cbdf7ab9b7c4b6c130261ca5c43b01787
7
+ data.tar.gz: b627d025fe2558cfdd629ff289bc5a18602a25f2e70e6a164aeedb081954b6db930e02f462001b70fd58cf3d52208fe1972c00c3e826511b0fd9c2467753b349
data/README.md CHANGED
@@ -1,22 +1,72 @@
1
- # AWS Broker
1
+ # AWS Broker [![Gem Version](https://badge.fury.io/rb/aws-broker.svg)](https://badge.fury.io/rb/aws-broker)
2
2
 
3
3
  :incoming_envelope: Ruby pub-sub on AWS
4
4
 
5
5
  * * *
6
6
 
7
+ [![CircleCI](https://circleci.com/gh/Thanx/aws-broker.svg?style=svg)](https://circleci.com/gh/Thanx/aws-broker)
8
+
7
9
  ### Background
8
10
 
9
11
  This lightweight abstraction simplifies pub-sub on AWS's SNS and SQS services.
10
12
  Message processing is not part of this gem - we recommend using
11
13
  [Shoryuken](https://github.com/phstc/shoryuken) in addition to this gem.
12
14
 
13
- ### Usage
15
+ ### Installation
14
16
 
15
- Usage:
17
+ gem 'aws-broker'
18
+
19
+ ### Usage
16
20
 
17
21
  Broker = Aws::Broker
18
22
  topic = 'topic'
19
23
  queue = 'queue'
20
24
  message = { id: 0 }
25
+
26
+ # subscribe topic to specified queue
21
27
  Broker.subscribe(topic, queue)
28
+
29
+ # subscribe topic to default queue
30
+ # "topic" or "prefix-topic" (see options)
31
+ Broker.subscribe(topic)
32
+
33
+ # publish message to topic
22
34
  Broker.publish(topic, message)
35
+
36
+ ### Configuration
37
+
38
+ #### Broker Options
39
+
40
+ Aws::Broker can be configured via the following:
41
+
42
+ Aws::Broker.configure do |config|
43
+ config.enabled = false
44
+ config.queue_prefix = 'prefix'
45
+ end
46
+
47
+ The following options are available:
48
+
49
+ | Option | Default | Description |
50
+ |----------------|---------|--------------------------------------------------|
51
+ | `enabled` | true | if false, don't trigger API calls to AWS |
52
+ | `queue_prefix` | nil | prefix for default queue name (prefix-topic) |
53
+
54
+ #### AWS Client
55
+
56
+ AWS Broker wraps the AWS SQS and SNS clients. All configuration is the same as
57
+ the AWS SDK. See
58
+ [Configuring the AWS SDK for Ruby](http://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/setup-config.html)
59
+ for details.
60
+
61
+ Some supported options:
62
+
63
+ * `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_REGION` env variables
64
+ * shared `~/.aws/credentials` file
65
+ * IAM
66
+ * `Aws.config[:credentials]`
67
+
68
+ ### Inspiration
69
+
70
+ * [propono](https://github.com/iHiD/propono)
71
+ * [shoryuken](https://github.com/phstc/shoryuken)
72
+ * [bunny](https://github.com/ruby-amqp/bunny)
@@ -5,7 +5,7 @@ module Aws
5
5
  private
6
6
 
7
7
  def enabled?
8
- Broker.config.enabled?
8
+ config.enabled?
9
9
  end
10
10
 
11
11
  def create_topic
@@ -13,15 +13,11 @@ module Aws
13
13
  end
14
14
 
15
15
  def sns
16
- @sns ||= Aws::SNS::Client.new(credentials)
16
+ @sns ||= Aws::SNS::Client.new
17
17
  end
18
18
 
19
- def credentials
20
- {
21
- access_key_id: ENV['AWS_ACCESS_KEY'],
22
- secret_access_key: ENV['AWS_SECRET_KEY'],
23
- region: ENV['AWS_REGION']
24
- }
19
+ def config
20
+ Broker.config
25
21
  end
26
22
 
27
23
  end
@@ -2,14 +2,12 @@ module Aws
2
2
  class Broker
3
3
  class Config
4
4
 
5
- attr_accessor :enabled
5
+ attr_accessor :enabled, :queue_prefix
6
6
  alias_method :enabled?, :enabled
7
7
 
8
- attr_accessor :queue_prefix
9
-
10
8
  def initialize
11
- self.enabled = true
12
- self.queue_prefix = nil
9
+ self.enabled = true
10
+ self.queue_prefix = nil
13
11
  end
14
12
 
15
13
  end
@@ -1,7 +1,7 @@
1
1
  module Aws
2
2
  class Broker
3
3
 
4
- VERSION = '0.0.2'.freeze
4
+ VERSION = '0.0.3'.freeze
5
5
 
6
6
  end
7
7
  end
@@ -12,6 +12,7 @@ module Aws
12
12
  def subscribe
13
13
  return unless enabled?
14
14
  create_queue
15
+ find_queue_arn
15
16
  create_topic
16
17
  sns.subscribe(
17
18
  topic_arn: @topic_arn,
@@ -24,8 +25,8 @@ module Aws
24
25
  private
25
26
 
26
27
  def queue_name
27
- if Broker.config.queue_prefix
28
- "#{Broker.config.queue_prefix}-#{@topic}"
28
+ if config.queue_prefix
29
+ "#{config.queue_prefix}-#{@topic}"
29
30
  else
30
31
  @topic
31
32
  end
@@ -35,6 +36,9 @@ module Aws
35
36
  @queue_url = sqs.create_queue(
36
37
  queue_name: @queue
37
38
  ).queue_url
39
+ end
40
+
41
+ def find_queue_arn
38
42
  @queue_arn = sqs.get_queue_attributes(
39
43
  queue_url: @queue_url,
40
44
  attribute_names: ['QueueArn']
@@ -50,31 +54,31 @@ module Aws
50
54
 
51
55
  def policy
52
56
  <<-POLICY
53
- {
54
- "Version": "2008-10-17",
55
- "Id": "#{@queue_arn}/SQSDefaultPolicy",
56
- "Statement": [
57
- {
58
- "Sid": "#{@queue_arn}-Sid",
59
- "Effect": "Allow",
60
- "Principal": {
61
- "AWS": "*"
62
- },
63
- "Action": "SQS:*",
64
- "Resource": "#{@queue_arn}",
65
- "Condition": {
66
- "StringEquals": {
67
- "aws:SourceArn": "#{@topic_arn}"
68
- }
69
- }
70
- }
71
- ]
72
- }
57
+ {
58
+ "Version": "2008-10-17",
59
+ "Id": "#{@queue_arn}/SQSDefaultPolicy",
60
+ "Statement": [
61
+ {
62
+ "Sid": "#{@queue_arn}-Sid",
63
+ "Effect": "Allow",
64
+ "Principal": {
65
+ "AWS": "*"
66
+ },
67
+ "Action": "SQS:*",
68
+ "Resource": "#{@queue_arn}",
69
+ "Condition": {
70
+ "StringEquals": {
71
+ "aws:SourceArn": "#{@topic_arn}"
72
+ }
73
+ }
74
+ }
75
+ ]
76
+ }
73
77
  POLICY
74
78
  end
75
79
 
76
80
  def sqs
77
- @sqs ||= Aws::SQS::Client.new(credentials)
81
+ @sqs ||= Aws::SQS::Client.new
78
82
  end
79
83
 
80
84
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-broker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eng @ Thanx
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-16 00:00:00.000000000 Z
11
+ date: 2017-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-sns