cross-service-messenger 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '06840167e7505a7a9cfc4d016a1de1b4c8a879d43bae04f7e789107e29892c5c'
4
+ data.tar.gz: eba3ece9def63e743dc232ad25e5c17b1ce24ac01409712b531e6cbbeb7aa601
5
+ SHA512:
6
+ metadata.gz: a950ab5d6c125b1f88138a5df27f51bf8d40f667c115dc635f685d1a28224d35445b9e894541258b7de368857eae16ff8d7f1f682de183de33f67a43007467da
7
+ data.tar.gz: 1b2b8d6bae3571a765d69a965bf6d567e971fd20bb22a609fdfb9e231a27ab3eb439b1051553828532e109284ed156573194a4905afce7a88aa3d6cf20c891d4
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Shuttlerock Ltd.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,52 @@
1
+ # CrossServiceMessenger
2
+
3
+ [![CircleCI](https://circleci.com/gh/Shuttlerock/cross-service-messenger.svg?style=svg)](https://circleci.com/gh/Shuttlerock/cross-service-messenger)
4
+
5
+ # About
6
+
7
+ Service for communicate apps via AWS SQS.
8
+
9
+ ## Installation in Ruby application
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'cross-service-messenger'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install cross-service-messenger
24
+
25
+ ### Setup a service
26
+
27
+ ```ruby
28
+ CrossServiceMessenger.setup do |config|
29
+ config.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID']
30
+ config.aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
31
+ config.aws_region = ENV['AWS_REGION']
32
+ config.queue_names = {
33
+ from_some_app: 'some_app_prodution_to_my_app_production',
34
+ to_some_app: 'my_app_production_to_some_app_production',
35
+ }
36
+ end
37
+ ```
38
+
39
+
40
+ ## Development
41
+
42
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
43
+
44
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
45
+
46
+ ## License
47
+
48
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
49
+
50
+ ## Code of Conduct
51
+
52
+ Everyone interacting in the CrossServiceMessenger project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Shuttlerock/cross-service-messenger/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cross_service_messenger/version'
4
+ require 'cross_service_messenger/client'
5
+
6
+ # Service for send/pull messages.
7
+ module CrossServiceMessenger
8
+ class << self
9
+ # AWS access key
10
+ attr_accessor :aws_access_key_id
11
+
12
+ # AWS secret access key
13
+ attr_accessor :aws_secret_access_key
14
+
15
+ # AWS region
16
+ attr_accessor :aws_region
17
+
18
+ # AWS SQS queue names
19
+ attr_writer :queue_names
20
+
21
+ # Public: Default way to set up CrossServiceMessenger.
22
+ def setup
23
+ yield self
24
+ end
25
+
26
+ # Public: Get queue names.
27
+ #
28
+ # @return [Hash<Symbol, String>] the queue names.
29
+ def queue_names
30
+ @queue_names ||= {}
31
+ end
32
+
33
+ # Public: Send message to app.
34
+ #
35
+ # @param app [String, Symbol] the app name.
36
+ # @param message_body [String] the message.
37
+ def send_to(app, message_body)
38
+ CrossServiceMessenger::Client.new(:"to_#{app.to_s.downcase}").send_message(message_body)
39
+ end
40
+
41
+ # Public: Pull messages from app.
42
+ #
43
+ # @param app [String, Symbol] the app name.
44
+ def pull_from(app, &block)
45
+ CrossServiceMessenger::Client.new(:"from_#{app.to_s.downcase}").pull(&block)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aws-sdk-sqs'
4
+
5
+ # Client for send/pull messages from AWS SQS.
6
+ class CrossServiceMessenger::Client
7
+ SEMAPHORE = Mutex.new
8
+
9
+ # App name
10
+ attr_reader :app
11
+
12
+ # Public: Constructor.
13
+ #
14
+ # @param app [Symbol] the app name.
15
+ def initialize(app)
16
+ @app = app
17
+ end
18
+
19
+ # Public: Send message.
20
+ #
21
+ # @param message_body [String] the message.
22
+ def send_message(message_body)
23
+ self.class.client.send_message(queue_url: queue_url, message_body: message_body)
24
+ end
25
+
26
+ # Public: Pull messages from app.
27
+ def pull
28
+ poller = Aws::SQS::QueuePoller.new(queue_url, client: self.class.client)
29
+ poller.poll(idle_timeout: 5, wait_time_seconds: 5) do |msg|
30
+ yield msg.body
31
+ end
32
+ end
33
+
34
+ class << self
35
+ # Public: Get AWS SQS queue urls
36
+ #
37
+ # @return [Hash<Symbol, String>] the queue urls.
38
+ def queue_urls
39
+ @queue_urls ||= {}
40
+ end
41
+
42
+ # Public: Get AWS SQS client.
43
+ #
44
+ # @return [Aws::SQS::Client] the client.
45
+ def client
46
+ @client ||= Aws::SQS::Client.new(access_key_id: CrossServiceMessenger.aws_access_key_id,
47
+ secret_access_key: CrossServiceMessenger.aws_secret_access_key,
48
+ region: CrossServiceMessenger.aws_region)
49
+ end
50
+ end
51
+
52
+ private
53
+
54
+ # Private: Get queue URL.
55
+ #
56
+ # @return [String] the queue URL.
57
+ def queue_url
58
+ @queue_url ||= begin
59
+ SEMAPHORE.synchronize do
60
+ self.class.queue_urls[app] ||= self.class.client.get_queue_url(queue_name: queue_name).queue_url
61
+ end
62
+ end
63
+ end
64
+
65
+ # Private: Get queue name.
66
+ #
67
+ # @return [String] the queue name.
68
+ def queue_name
69
+ @queue_name ||= CrossServiceMessenger.queue_names.fetch(app)
70
+ end
71
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CrossServiceMessenger
4
+ VERSION = '0.0.1'
5
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cross-service-messenger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Aleksei Vokhmin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-05-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.9.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.9.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop-performance
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.5.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.5.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: shuttlerock_shared_config
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.2.29
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.2.29
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 0.16.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 0.16.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: aws-sdk-sqs
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.24.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.24.0
83
+ description: Service for communicate apps via AWS SQS.
84
+ email:
85
+ - avokhmin@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - LICENSE
91
+ - README.md
92
+ - lib/cross_service_messenger.rb
93
+ - lib/cross_service_messenger/client.rb
94
+ - lib/cross_service_messenger/version.rb
95
+ homepage: https://github.com/Shuttlerock/cross-service-messenger
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: 2.6.0
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubygems_version: 3.0.3
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Service for communicate apps via AWS SQS.
118
+ test_files: []