mimi-messaging-sqs_sns 0.6.1 → 0.7.0

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: 1f7bfa555dbbe8a3d917d0133811c6f2af643016e5864628a8ae7ae79ec2a9fc
4
- data.tar.gz: adc4769159cb678ca05e69c0d5b174b2d9a87064da8fcddf16916596ab14889e
3
+ metadata.gz: b02992abcb101248ebc54069aba5b3887417930b7613a84ed4b6723ad7ce3060
4
+ data.tar.gz: 3b830249dfb56e42a7d380571402c2abef55d74f3e90bf0b9f537e105078cd27
5
5
  SHA512:
6
- metadata.gz: 377f9dc7b50c0c3c4edd77afec14e2473fdebbfd4751a18d358c27b9c4281e3af2566f5f70c68fb228a75316d985a2f8f4cab4c74b5d233335e2986875fa88b0
7
- data.tar.gz: becd20ef9d41f474ee072a8af75b8b885e40f47b8c34ddca61269cd413fb88368d4715808e4ca8a507b2c56e41b6db0aaf1381c0c9e1715dc4397aa4dcf1888b
6
+ metadata.gz: 4d6ecfe3d2202124b10ff03129166249f518fca0f15c2e513ba5ab6b2835a713671618eab623fb39e3cbebe3c8351e0688884743e4f69baa3832b1db94a6a858
7
+ data.tar.gz: 5bb7ae92080d112f16a4127b010f7f102ebd71cb53b4701b756e9bbab8c43fae42618969c148fd71f67678dbf34ed4d6c734307a1c84f7201229d5bd95c3907a
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # Changelog
2
+
3
+ ## v0.7.0
4
+
5
+ * [#1](https://github.com/kukushkin/mimi-messaging-sqs_sns/pull/1)
6
+ * Added KMS support for creating queues/topics with sever-side encryption enabled
7
+ * Optimized stopping of the adapter: stopping all consumers in parallel
8
+
9
+
10
+ ## v0.6.x
11
+
12
+ * Basic functionality implemented, see missing features in [TODO](TODO.md)
data/README.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  AWS SQS/SNS adapter for [mimi-messaging](https://github.com/kukushkin/mimi-messaging).
4
4
 
5
+ * [Changes](CHANGELOG.md)
6
+
7
+
5
8
  ## Installation
6
9
 
7
10
  Add this line to your application's Gemfile:
@@ -43,7 +46,6 @@ Mimi::Messaging.configure(
43
46
  Mimi::Messaging.start
44
47
  ```
45
48
 
46
-
47
49
  ## Contributing
48
50
 
49
51
  Bug reports and pull requests are welcome on GitHub at https://github.com/kukushkin/mimi-messaging-sqs_sns. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
data/examples/query.rb CHANGED
@@ -8,6 +8,7 @@ AWS_SQS_ENDPOINT_URL = "http://localstack:4566"
8
8
  AWS_SNS_ENDPOINT_URL = "http://localstack:4566"
9
9
  AWS_ACCESS_KEY_ID = "foo"
10
10
  AWS_SECRET_ACCESS_KEY = "bar"
11
+ AWS_SQS_SNS_KMS_MASTER_KEY_ID = "blah"
11
12
 
12
13
  logger = Logger.new(STDOUT)
13
14
  logger.level = Logger::INFO
@@ -18,7 +19,8 @@ Mimi::Messaging.configure(
18
19
  mq_aws_secret_access_key: AWS_SECRET_ACCESS_KEY,
19
20
  mq_aws_region: AWS_REGION,
20
21
  mq_aws_sqs_endpoint: AWS_SQS_ENDPOINT_URL,
21
- mq_aws_sns_endpoint: AWS_SNS_ENDPOINT_URL
22
+ mq_aws_sns_endpoint: AWS_SNS_ENDPOINT_URL,
23
+ mq_aws_sqs_sns_kms_master_key_id: AWS_SQS_SNS_KMS_MASTER_KEY_ID
22
24
  )
23
25
  adapter = Mimi::Messaging.adapter
24
26
 
@@ -2,11 +2,12 @@
2
2
 
3
3
  require "mimi/messaging/sqs_sns"
4
4
 
5
- AWS_REGION = "eu-west-1"
6
- AWS_SQS_ENDPOINT_URL = "http://localstack:4566"
7
- AWS_SNS_ENDPOINT_URL = "http://localstack:4566"
8
- AWS_ACCESS_KEY_ID = "foo"
5
+ AWS_REGION = "eu-west-1"
6
+ AWS_SQS_ENDPOINT_URL = "http://localstack:4566"
7
+ AWS_SNS_ENDPOINT_URL = "http://localstack:4566"
8
+ AWS_ACCESS_KEY_ID = "foo"
9
9
  AWS_SECRET_ACCESS_KEY = "bar"
10
+ AWS_SQS_SNS_KMS_MASTER_KEY_ID = "blah"
10
11
 
11
12
  class Processor
12
13
  def self.call_command(method_name, message, opts)
@@ -30,7 +31,8 @@ Mimi::Messaging.configure(
30
31
  mq_aws_secret_access_key: AWS_SECRET_ACCESS_KEY,
31
32
  mq_aws_region: AWS_REGION,
32
33
  mq_aws_sqs_endpoint: AWS_SQS_ENDPOINT_URL,
33
- mq_aws_sns_endpoint: AWS_SNS_ENDPOINT_URL
34
+ mq_aws_sns_endpoint: AWS_SNS_ENDPOINT_URL,
35
+ mq_aws_sqs_sns_kms_master_key_id: AWS_SQS_SNS_KMS_MASTER_KEY_ID
34
36
  )
35
37
  adapter = Mimi::Messaging.adapter
36
38
  queue_name = "test"
@@ -47,4 +49,3 @@ ensure
47
49
  puts "Stopping adapter"
48
50
  adapter.stop
49
51
  end
50
-
@@ -56,7 +56,8 @@ module Mimi
56
56
  mq_aws_sqs_endpoint: nil,
57
57
  mq_aws_sns_endpoint: nil,
58
58
 
59
- mq_aws_sqs_read_timeout: 10, # seconds
59
+ mq_aws_sqs_sns_kms_master_key_id: nil,
60
+ mq_aws_sqs_read_timeout: 20, # seconds
60
61
  }.freeze
61
62
 
62
63
  # Initializes SQS/SNS adapter
@@ -93,6 +94,7 @@ module Mimi
93
94
  # for processors.
94
95
  #
95
96
  def stop_all_processors
97
+ @consumers&.each(&:signal_stop)
96
98
  @consumers&.each(&:stop)
97
99
  @consumers = nil
98
100
  @reply_consumer&.stop
@@ -227,13 +229,16 @@ module Mimi
227
229
  def create_queue(queue_name)
228
230
  fqn = sqs_sns_converted_full_name(queue_name)
229
231
  Mimi::Messaging.log "Creating a queue: #{fqn}"
230
- result = sqs_client.create_queue(queue_name: fqn)
232
+ attrs = {}
233
+ if options[:mq_aws_sqs_sns_kms_master_key_id]
234
+ attrs["KmsMasterKeyId"] = options[:mq_aws_sqs_sns_kms_master_key_id]
235
+ end
236
+ result = sqs_client.create_queue(queue_name: fqn, attributes: attrs)
231
237
  result.queue_url
232
238
  rescue StandardError => e
233
239
  raise Mimi::Messaging::ConnectionError, "Failed to create queue '#{queue_name}': #{e}"
234
240
  end
235
241
 
236
-
237
242
  # Finds a queue URL for a queue with given name.
238
243
  #
239
244
  # If an existing queue with this name is not found,
@@ -315,6 +320,7 @@ module Mimi
315
320
  unless message.is_a?(Mimi::Messaging::Message)
316
321
  raise ArgumentError, "Message is expected as argument"
317
322
  end
323
+
318
324
  Mimi::Messaging.log "Delivering message to: #{queue_url}, headers: #{message.headers}"
319
325
  sqs_client.send_message(
320
326
  queue_url: queue_url,
@@ -479,7 +485,11 @@ module Mimi
479
485
  def create_topic(topic_name)
480
486
  fqn = sqs_sns_converted_full_name(topic_name)
481
487
  Mimi::Messaging.log "Creating a topic: #{fqn}"
482
- result = sns_client.create_topic(name: fqn)
488
+ attrs = {}
489
+ if options[:mq_aws_sqs_sns_kms_master_key_id]
490
+ attrs["KmsMasterKeyId"] = options[:mq_aws_sqs_sns_kms_master_key_id]
491
+ end
492
+ result = sns_client.create_topic(name: fqn, attributes: attrs)
483
493
  result.topic_arn
484
494
  rescue StandardError => e
485
495
  raise Mimi::Messaging::ConnectionError, "Failed to create topic '#{topic_name}': #{e}"
@@ -496,7 +506,7 @@ module Mimi
496
506
  )
497
507
  queue_arn = result.attributes["QueueArn"]
498
508
  Mimi::Messaging.log "Subscribing queue to a topic: '#{topic_arn}'->'#{queue_url}'"
499
- result = sns_client.subscribe(
509
+ _result = sns_client.subscribe(
500
510
  topic_arn: topic_arn,
501
511
  protocol: "sqs",
502
512
  endpoint: queue_arn,
@@ -518,6 +528,7 @@ module Mimi
518
528
  unless message.is_a?(Mimi::Messaging::Message)
519
529
  raise ArgumentError, "Message is expected as argument"
520
530
  end
531
+
521
532
  Mimi::Messaging.log "Delivering message to: #{topic_arn}"
522
533
  sns_client.publish(
523
534
  topic_arn: topic_arn,
@@ -11,13 +11,21 @@ module Mimi
11
11
  @stop_requested = false
12
12
  Mimi::Messaging.log "Starting consumer for: #{queue_url}"
13
13
  @consumer_thread = Thread.new do
14
- while not @stop_requested do
14
+ while not @stop_requested
15
15
  read_and_process_message(adapter, queue_url, block)
16
16
  end
17
17
  Mimi::Messaging.log "Stopping consumer for: #{queue_url}"
18
18
  end
19
19
  end
20
20
 
21
+ # Requests the Consumer to stop, without actually waiting for it
22
+ #
23
+ def signal_stop
24
+ @stop_requested = true
25
+ end
26
+
27
+ # Requests the Consumer to stop AND waits until it does
28
+ #
21
29
  def stop
22
30
  @stop_requested = true
23
31
  @consumer_thread.join
@@ -35,6 +43,7 @@ module Mimi
35
43
  def read_and_process_message(adapter, queue_url, block)
36
44
  message = read_message(adapter, queue_url)
37
45
  return unless message
46
+
38
47
  Mimi::Messaging.log "Read message from: #{queue_url}"
39
48
  block.call(message)
40
49
  ack_message(adapter, queue_url, message)
@@ -54,6 +63,7 @@ module Mimi
54
63
  )
55
64
  return nil if result.messages.count == 0
56
65
  return result.messages.first if result.messages.count == 1
66
+
57
67
  raise Mimi::Messaging::ConnectionError, "Unexpected number of messages read"
58
68
  end
59
69
 
@@ -3,7 +3,7 @@
3
3
  module Mimi
4
4
  module Messaging
5
5
  module SQS_SNS
6
- VERSION = "0.6.1"
6
+ VERSION = "0.7.0"
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mimi-messaging-sqs_sns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Kukushkin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-18 00:00:00.000000000 Z
11
+ date: 2021-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mimi-messaging
@@ -124,6 +124,7 @@ files:
124
124
  - ".gitignore"
125
125
  - ".rspec"
126
126
  - ".travis.yml"
127
+ - CHANGELOG.md
127
128
  - CODE_OF_CONDUCT.md
128
129
  - Gemfile
129
130
  - LICENSE.txt
@@ -165,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
166
  - !ruby/object:Gem::Version
166
167
  version: '0'
167
168
  requirements: []
168
- rubygems_version: 3.0.3
169
+ rubygems_version: 3.1.2
169
170
  signing_key:
170
171
  specification_version: 4
171
172
  summary: AWS SQS/SNS adapter for mimi-messaging