eventq 2.1.2 → 2.1.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
  SHA256:
3
- metadata.gz: ba5bfee3e1fd027189bc32012b22e94f4d7bd81707ef3811d1748f9ee09a4887
4
- data.tar.gz: 0f32197796b9c7b5bf5b7f57146bdd8ca992931fecadd594455e72cd2213ef93
3
+ metadata.gz: 2ff7c42a020c9dcd1c69286c86121aa5c1479f7b7cb2338e46a257cab1826d8b
4
+ data.tar.gz: b02d13924c3619d54ea0a5e8b75bb103457a6001550608d739a9f257e8ad87ef
5
5
  SHA512:
6
- metadata.gz: b0133ee80992c77a7105a22a720bc8ca4d17da12849ed02b56b0640056646f3a30c401dfc4ab789b964a843b0e0cdfcdde765f225b936e1ac94e874e73fcd0a4
7
- data.tar.gz: a4c024e13ff25f62fc6497af126871a9aa6de1d1369b11bed51dddcd87829d7950600f4fea8c9e030bf54bc0376427d8e40276fe2f0f8e8478f073d556a3acc6
6
+ metadata.gz: 07c73cb255746f3059981a488e19a81bee3a593eefda8db954ddc35f53b0f3803cd8da4dc27a4764b736b09f25eb19fea89136dfc25bd0612c4eb41851626391
7
+ data.tar.gz: 48f78d71377237644e0bb0b28329a6f5dfa468e5b4c00700bf60d6798691e10eeb0978f435bc6ca88bc29ec57dc7b89995d9eb15a99512259c9c088dd6192713
data/README.md CHANGED
@@ -266,7 +266,7 @@ This method is called to configure the NonceManager, and must be called before s
266
266
 
267
267
  - **server** [String] [Required] This is redis server url.
268
268
  - **timeout** [Integer] [Optional] [Default=10000 (10 seconds)] This is the time in milliseconds that should be used for the initial nonce lock (this value should be low so as to not affect failure retries but long enough to cover the processing of the received message).
269
- - **lifespan** [Integer] [Optional] [Default=3600000 (60 minutes)] This is the length of time the nonce should be kept for after processing of a message has completed.
269
+ - **lifespan** [Integer] [Optional] [Default=3600 (60 minutes)] This is the length of time the nonce should be kept for after processing of a message has completed.
270
270
 
271
271
  **Example**
272
272
 
@@ -15,35 +15,37 @@ module EventQ
15
15
  @serialization_manager = EventQ::SerializationProviders::Manager.new
16
16
  @signature_manager = EventQ::SignatureProviders::Manager.new
17
17
 
18
- #this array is used to record known event types
18
+ # this array is used to record known event types
19
19
  @known_event_types = []
20
20
 
21
21
  end
22
22
 
23
- def registered?(event_type)
24
- @known_event_types.include?(event_type)
23
+ def registered?(event_type, region = nil)
24
+ topic_key = "#{region}:#{event_type}"
25
+ @known_event_types.include?(topic_key)
25
26
  end
26
27
 
27
- def register_event(event_type)
28
- if registered?(event_type)
28
+ def register_event(event_type, region = nil)
29
+ if registered?(event_type, region)
29
30
  return true
30
31
  end
31
32
 
32
- @client.sns_helper.create_topic_arn(event_type)
33
- @known_event_types << event_type
33
+ topic_key = "#{region}:#{event_type}"
34
+ @client.sns_helper(region).create_topic_arn(event_type, region)
35
+ @known_event_types << topic_key
34
36
  true
35
37
  end
36
38
 
37
- def publish(topic:, event:, context: {})
38
- raise_event(topic, event, context)
39
+ def publish(topic:, event:, context: {}, region: nil)
40
+ raise_event(topic, event, context, region)
39
41
  end
40
42
 
41
- def raise_event(event_type, event, context = {})
42
- register_event(event_type)
43
+ def raise_event(event_type, event, context = {}, region = nil)
44
+ register_event(event_type, region)
43
45
 
44
46
  with_prepared_message(event_type, event, context) do |message|
45
- topic_arn = topic_arn(event_type)
46
- response = @client.sns.publish(
47
+ topic_arn = topic_arn(event_type, region)
48
+ response = @client.sns(region).publish(
47
49
  topic_arn: topic_arn,
48
50
  message: message,
49
51
  subject: event_type
@@ -60,7 +62,6 @@ module EventQ
60
62
  def raise_event_in_queue(event_type, event, queue, delay, context = {})
61
63
  queue_url = @client.sqs_helper.get_queue_url(queue)
62
64
  with_prepared_message(event_type, event, context) do |message|
63
-
64
65
  response = @client.sqs.send_message(
65
66
  queue_url: queue_url,
66
67
  message_body: sqs_message_body_for(message),
@@ -108,8 +109,8 @@ module EventQ
108
109
  serialization_provider.serialize(queue_message)
109
110
  end
110
111
 
111
- def topic_arn(event_type)
112
- @client.sns_helper.get_topic_arn(event_type)
112
+ def topic_arn(event_type, region = nil)
113
+ @client.sns_helper(region).get_topic_arn(event_type, region)
113
114
  end
114
115
 
115
116
  def sqs_message_body_for(payload_message)
@@ -4,7 +4,7 @@ module EventQ
4
4
  module Amazon
5
5
  class QueueClient
6
6
  def initialize(options = {})
7
- invalid_keys = options.keys - [:sns_keep_alive_timeout, :sns_continue_timeout ]
7
+ invalid_keys = options.keys - %i[sns_keep_alive_timeout sns_continue_timeout]
8
8
  raise(OptionParser::InvalidOption, invalid_keys) unless invalid_keys.empty?
9
9
 
10
10
  @sns_keep_alive_timeout = options[:sns_keep_alive_timeout] || 30
@@ -12,21 +12,37 @@ module EventQ
12
12
  end
13
13
 
14
14
  # Returns the AWS SQS Client
15
- def sqs
16
- @sqs ||= sqs_client
15
+ def sqs(region = nil)
16
+ if region.nil?
17
+ @sqs ||= sqs_client
18
+ else
19
+ sqs_client(region)
20
+ end
17
21
  end
18
22
 
19
23
  # Returns the AWS SNS Client
20
- def sns
21
- @sns ||= sns_client
24
+ def sns(region = nil)
25
+ if region.nil?
26
+ @sns ||= sns_client
27
+ else
28
+ sns_client(region)
29
+ end
22
30
  end
23
31
 
24
- def sqs_helper
25
- @sqs_helper ||= Amazon::SQS.new(sqs)
32
+ def sqs_helper(region = nil)
33
+ if region.nil?
34
+ @sqs_helper ||= Amazon::SQS.new(sqs)
35
+ else
36
+ Amazon::SQS.new(sqs_client(region))
37
+ end
26
38
  end
27
39
 
28
- def sns_helper
29
- @sns_helper ||= Amazon::SNS.new(sns)
40
+ def sns_helper(region = nil)
41
+ if region.nil?
42
+ @sns_helper ||= Amazon::SNS.new(sns)
43
+ else
44
+ Amazon::SNS.new(sns_client(region))
45
+ end
30
46
  end
31
47
 
32
48
  private
@@ -37,9 +53,10 @@ module EventQ
37
53
  { endpoint: aws_env } unless aws_env.empty?
38
54
  end
39
55
 
40
- def sqs_client
56
+ def sqs_client(region = nil)
41
57
  options = custom_endpoint('sqs')
42
- options.merge!(verify_checksums: false) if options
58
+ options[:verify_checksums] = false if options
59
+ options[:region] = region if region
43
60
 
44
61
  if options
45
62
  Aws::SQS::Client.new(options)
@@ -48,7 +65,7 @@ module EventQ
48
65
  end
49
66
  end
50
67
 
51
- def sns_client
68
+ def sns_client(region = nil)
52
69
  custom_endpoint('sns')
53
70
  options = {
54
71
  http_idle_timeout: @sns_keep_alive_timeout,
@@ -56,6 +73,7 @@ module EventQ
56
73
  }
57
74
  endpoint = custom_endpoint('sns')
58
75
  options.merge!(endpoint) if endpoint
76
+ options[:region] = region if region
59
77
 
60
78
  Aws::SNS::Client.new(options)
61
79
  end
@@ -3,9 +3,8 @@
3
3
  module EventQ
4
4
  module Amazon
5
5
  class SubscriptionManager
6
-
7
6
  def initialize(options)
8
- mandatory = [:client, :queue_manager]
7
+ mandatory = %i[client queue_manager]
9
8
  missing = mandatory - options.keys
10
9
  raise "[#{self.class}] - Missing options #{missing} must be specified." unless missing.empty?
11
10
 
@@ -13,27 +12,26 @@ module EventQ
13
12
  @manager = options[:queue_manager]
14
13
  end
15
14
 
16
- def subscribe(event_type, queue)
17
- topic_arn = @client.sns_helper.create_topic_arn(event_type)
15
+ def subscribe(event_type, queue, topic_region = nil, queue_region = nil)
16
+ topic_arn = @client.sns_helper(topic_region).create_topic_arn(event_type, topic_region)
18
17
 
19
18
  q = @manager.get_queue(queue)
20
- queue_arn = @client.sqs_helper.get_queue_arn(queue)
19
+ queue_arn = @client.sqs_helper(queue_region).get_queue_arn(queue)
20
+
21
+ @client.sqs(queue_region).set_queue_attributes(
22
+ queue_url: q,
23
+ attributes:
24
+ {
25
+ 'Policy' => queue_policy(queue_arn)
26
+ }
27
+ )
21
28
 
22
- @client.sqs.set_queue_attributes(
23
- {
24
- queue_url: q,
25
- attributes:
26
- {
27
- 'Policy' => queue_policy(queue_arn)
28
- }
29
- }
29
+ @client.sns(topic_region).subscribe(
30
+ topic_arn: topic_arn,
31
+ protocol: 'sqs',
32
+ endpoint: queue_arn
30
33
  )
31
34
 
32
- @client.sns.subscribe({
33
- topic_arn: topic_arn,
34
- protocol: 'sqs',
35
- endpoint: queue_arn
36
- })
37
35
  EventQ.logger.debug do
38
36
  "[#{self.class} #subscribe] - Subscribing Queue: #{queue.name} to topic_arn: #{topic_arn}, endpoint: #{queue_arn}"
39
37
  end
@@ -41,24 +39,24 @@ module EventQ
41
39
  true
42
40
  end
43
41
 
44
- def unsubscribe(queue)
42
+ def unsubscribe(_queue)
45
43
  raise "[#{self.class}] - Not implemented. Please unsubscribe the queue from the topic inside the AWS Management Console."
46
44
  end
47
45
 
48
46
  def queue_policy(queue_arn)
49
- '{
50
- "Version": "2012-10-17",
51
- "Id": "SNStoSQS",
52
- "Statement": [
53
- {
54
- "Sid":"rule1",
55
- "Effect": "Allow",
56
- "Principal": "*",
57
- "Action": "sqs:*",
58
- "Resource": "' + queue_arn + '"
59
- }
60
- ]
61
- }'
47
+ '{
48
+ "Version": "2012-10-17",
49
+ "Id": "SNStoSQS",
50
+ "Statement": [
51
+ {
52
+ "Sid":"rule1",
53
+ "Effect": "Allow",
54
+ "Principal": "*",
55
+ "Action": "sqs:*",
56
+ "Resource": "' + queue_arn + '"
57
+ }
58
+ ]
59
+ }'
62
60
  end
63
61
  end
64
62
  end
@@ -17,14 +17,15 @@ module EventQ
17
17
  # Create a TopicArn. if one already exists, it will return a pre-existing ARN from the cache.
18
18
  # Even in the event of multiple threads trying to create one with AWS, AWS is idempotent and won't create
19
19
  # duplicates
20
- def create_topic_arn(event_type)
20
+ def create_topic_arn(event_type, region = nil)
21
21
  _event_type = EventQ.create_event_type(event_type)
22
+ topic_key = "#{region}:#{_event_type}"
22
23
 
23
- arn = get_topic_arn(event_type)
24
+ arn = get_topic_arn(event_type, region)
24
25
  unless arn
25
26
  response = sns.create_topic(name: aws_safe_name(_event_type))
26
27
  arn = response.topic_arn
27
- @@topic_arns[_event_type] = arn
28
+ @@topic_arns[topic_key] = arn
28
29
  end
29
30
 
30
31
  arn
@@ -32,26 +33,28 @@ module EventQ
32
33
 
33
34
  # Check if a TopicArn exists. This will check with AWS if necessary and cache the results if one is found
34
35
  # @return TopicArn [String]
35
- def get_topic_arn(event_type)
36
+ def get_topic_arn(event_type, region = nil)
36
37
  _event_type = EventQ.create_event_type(event_type)
38
+ topic_key = "#{region}:#{_event_type}"
37
39
 
38
- arn = @@topic_arns[_event_type]
40
+ arn = @@topic_arns[topic_key]
39
41
  unless arn
40
42
  response = sns.list_topics
41
43
  arn = response.topics.detect { |topic| topic.topic_arn.end_with?(":#{_event_type}") }&.topic_arn
42
44
 
43
- @@topic_arns[_event_type] = arn if arn
45
+ @@topic_arns[topic_key] = arn if arn
44
46
  end
45
47
 
46
48
  arn
47
49
  end
48
50
 
49
- def drop_topic(event_type)
50
- topic_arn = get_topic_arn(event_type)
51
+ def drop_topic(event_type, region = nil)
52
+ topic_arn = get_topic_arn(event_type, region)
51
53
  sns.delete_topic(topic_arn: topic_arn)
52
54
 
53
55
  _event_type = EventQ.create_event_type(event_type)
54
- @@topic_arns.delete(_event_type)
56
+ topic_key = "#{region}:#{_event_type}"
57
+ @@topic_arns.delete(topic_key)
55
58
 
56
59
  true
57
60
  end
@@ -1,7 +1,7 @@
1
1
  module EventQ
2
2
  class NonceManager
3
3
 
4
- def self.configure(server:,timeout:10000,lifespan:3600000)
4
+ def self.configure(server:,timeout:10000,lifespan:3600)
5
5
  @server_url = server
6
6
  @timeout = timeout
7
7
  @lifespan = lifespan
@@ -54,4 +54,4 @@ module EventQ
54
54
  @lifespan = nil
55
55
  end
56
56
  end
57
- end
57
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eventq
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - SageOne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-18 00:00:00.000000000 Z
11
+ date: 2019-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -266,8 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
266
266
  - !ruby/object:Gem::Version
267
267
  version: '0'
268
268
  requirements: []
269
- rubyforge_project:
270
- rubygems_version: 2.7.8
269
+ rubygems_version: 3.0.2
271
270
  signing_key:
272
271
  specification_version: 4
273
272
  summary: EventQ is a pub/sub system that uses async notifications and message queues