bi-frost 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/bifrost.rb +6 -0
- data/lib/bifrost/bus.rb +24 -0
- data/lib/bifrost/entity.rb +1 -6
- data/lib/bifrost/manager.rb +1 -1
- data/lib/bifrost/message.rb +2 -2
- data/lib/bifrost/topic.rb +9 -9
- data/lib/bifrost/version.rb +1 -1
- data/lib/bifrost/worker.rb +3 -3
- data/spec/bifrost/message_spec.rb +1 -3
- data/spec/bifrost/subscriber_spec.rb +1 -1
- data/spec/bifrost/topic_spec.rb +2 -3
- data/spec/bifrost/worker_spec.rb +1 -4
- data/spec/spec_helper.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2c0c05d4f226f4592d8b654a36e2a324dcf0042
|
4
|
+
data.tar.gz: 2a085487e7a616543e690d4d428d89087d1b750d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89b9ae01ccb0f14d03d926494afa83491b98cbc597b796a1e8eb48e606acc92b8bc23648b16548a7df71803b16b5536ec285262fde25d1a09cee58aebb3cb8cf
|
7
|
+
data.tar.gz: da58e3c72a1e34338089a4a253e56fe60871f5564538613379b6d510827a42682d8d51e8dca56b3742c556eeb1beed4aa3952a6eb479e8eb60dd8ffe274e5c94
|
data/README.md
CHANGED
@@ -31,7 +31,7 @@ bus and how it works please refer to this [article](https://azure.microsoft.com/
|
|
31
31
|
|
32
32
|
To begin using this gem we need to start by setting some environment variables. The gem in development and
|
33
33
|
test environments supports .env files (i.e. .env.test and .env.development etc). The environment variables that
|
34
|
-
require to be set prior to using the gem are;
|
34
|
+
require to be set prior to using the gem are; `AZURE_BUS_NAMESPACE`, `AZURE_BUS_KEY_NAME` and `AZURE_BUS_KEY_SECRET`. The values for these variables
|
35
35
|
can be obtained from your Azure management portal. For more information on how to obtain these values for your
|
36
36
|
service bus please refer to this [article](https://azure.microsoft.com/en-us/documentation/articles/service-bus-authentication-and-authorization/).
|
37
37
|
|
@@ -141,4 +141,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
141
141
|
|
142
142
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
143
143
|
|
144
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
144
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/bifrost.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'bifrost/bus'
|
1
2
|
require 'bifrost/entity'
|
2
3
|
require 'bifrost/message'
|
3
4
|
require 'bifrost/topic'
|
@@ -24,6 +25,11 @@ module Bifrost
|
|
24
25
|
topic
|
25
26
|
end
|
26
27
|
|
28
|
+
# Get an instance of the bus
|
29
|
+
def self.bus
|
30
|
+
Bifrost::Bus.new
|
31
|
+
end
|
32
|
+
|
27
33
|
# Creates a manager instance
|
28
34
|
def self.manager
|
29
35
|
Bifrost::Manager.new
|
data/lib/bifrost/bus.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'Azure'
|
2
|
+
|
3
|
+
module Bifrost
|
4
|
+
# This type represents the Bifrost as a managed entity
|
5
|
+
# NOTE: Warning, this object should never use shared state as it is referenced initialize
|
6
|
+
# each worker
|
7
|
+
class Bus
|
8
|
+
attr_reader :interface
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
Azure.sb_namespace = ENV['AZURE_BUS_NAMESPACE']
|
12
|
+
host = "https://#{Azure.sb_namespace}.servicebus.windows.net"
|
13
|
+
signer = Azure::ServiceBus::Auth::SharedAccessSigner.new(ENV['AZURE_BUS_KEY_NAME'], ENV['AZURE_BUS_KEY_SECRET'])
|
14
|
+
@interface ||= Azure::ServiceBus::ServiceBusService.new(host, signer: signer)
|
15
|
+
end
|
16
|
+
|
17
|
+
# This method returns a list of topics currently defined on the Bifrost
|
18
|
+
def topics
|
19
|
+
@interface.list_topics.map do |t|
|
20
|
+
Topic.new(t.name)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/bifrost/entity.rb
CHANGED
@@ -4,13 +4,8 @@ module Bifrost
|
|
4
4
|
# Types that require access to the message bus should inherit this type. We've chosen
|
5
5
|
# inheritance at this point, perhaps a mixin might be a better approach
|
6
6
|
class Entity
|
7
|
-
attr_reader :bus
|
8
|
-
|
9
7
|
def initialize
|
10
|
-
|
11
|
-
host = "https://#{Azure.sb_namespace}.servicebus.windows.net"
|
12
|
-
signer = Azure::ServiceBus::Auth::SharedAccessSigner.new(ENV['KEY_NAME'], ENV['KEY_SECRET'])
|
13
|
-
@bus ||= Azure::ServiceBus::ServiceBusService.new(host, signer: signer)
|
8
|
+
@bus ||= Bifrost::Bus.new
|
14
9
|
end
|
15
10
|
end
|
16
11
|
end
|
data/lib/bifrost/manager.rb
CHANGED
@@ -25,7 +25,7 @@ module Bifrost
|
|
25
25
|
if topic.nil? || subscriber.nil? || proc.nil?
|
26
26
|
raise InvalidWorkerDefinitionError, 'Invalid worker'
|
27
27
|
else
|
28
|
-
|
28
|
+
Worker.supervise(as: Worker.handle(topic, subscriber), args: [topic, subscriber, proc])
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
data/lib/bifrost/message.rb
CHANGED
@@ -4,7 +4,7 @@ require_relative 'entity'
|
|
4
4
|
module Bifrost
|
5
5
|
# A message is a letter that we send to a topic. It must contain a subject and body
|
6
6
|
# The receiver can process both fields on receipt of the message
|
7
|
-
class Message <
|
7
|
+
class Message < Entity
|
8
8
|
attr_reader :subject, :body, :status, :message_id
|
9
9
|
|
10
10
|
# A message must have a valid subject and body. The service
|
@@ -20,7 +20,7 @@ module Bifrost
|
|
20
20
|
def post_to(topic)
|
21
21
|
if topic.exists?
|
22
22
|
message = create_brokered_message
|
23
|
-
bus.send_topic_message(topic.name, message)
|
23
|
+
@bus.interface.send_topic_message(topic.name, message)
|
24
24
|
update_message_state_to_delivered(message)
|
25
25
|
true
|
26
26
|
else
|
data/lib/bifrost/topic.rb
CHANGED
@@ -6,18 +6,17 @@ module Bifrost
|
|
6
6
|
# Topics are central to the pub/sub system in the Bifrost. All messages must be delivered
|
7
7
|
# to a topic. The topic is responsible for forwarding the message to registered subscribers
|
8
8
|
class Topic < Entity
|
9
|
-
attr_reader :name
|
9
|
+
attr_reader :name
|
10
10
|
|
11
|
-
def initialize(name
|
11
|
+
def initialize(name)
|
12
12
|
@name ||= name
|
13
|
-
@options ||= options
|
14
13
|
super()
|
15
14
|
end
|
16
15
|
|
17
16
|
# If the topic has been defined this method returns true, if not
|
18
17
|
# it returns false
|
19
18
|
def exists?
|
20
|
-
bus.
|
19
|
+
@bus.topics.each do |topic|
|
21
20
|
return true if topic.name == name
|
22
21
|
end
|
23
22
|
false
|
@@ -28,7 +27,7 @@ module Bifrost
|
|
28
27
|
if exists?
|
29
28
|
false
|
30
29
|
else
|
31
|
-
bus.create_topic(name)
|
30
|
+
@bus.interface.create_topic(name)
|
32
31
|
true
|
33
32
|
end
|
34
33
|
end
|
@@ -36,7 +35,7 @@ module Bifrost
|
|
36
35
|
# If a topic is defined, we can remove the definition
|
37
36
|
def delete
|
38
37
|
if exists?
|
39
|
-
bus.delete_topic(name)
|
38
|
+
@bus.interface.delete_topic(name)
|
40
39
|
true
|
41
40
|
else
|
42
41
|
false
|
@@ -47,9 +46,10 @@ module Bifrost
|
|
47
46
|
def add_subscriber(subscriber)
|
48
47
|
if exists?
|
49
48
|
begin
|
50
|
-
bus.create_subscription(name, subscriber.name)
|
49
|
+
@bus.interface.create_subscription(name, subscriber.name)
|
51
50
|
rescue Azure::Core::Http::HTTPError => e
|
52
|
-
|
51
|
+
return false if e.status_code == 409
|
52
|
+
raise e
|
53
53
|
end
|
54
54
|
true
|
55
55
|
else
|
@@ -61,7 +61,7 @@ module Bifrost
|
|
61
61
|
def remove_subscriber(subscriber)
|
62
62
|
if exists?
|
63
63
|
begin
|
64
|
-
bus.delete_subscription(name, subscriber.name)
|
64
|
+
@bus.interface.delete_subscription(name, subscriber.name)
|
65
65
|
rescue Azure::Core::Http::HTTPError => e
|
66
66
|
return false if e.status_code == 404
|
67
67
|
raise e
|
data/lib/bifrost/version.rb
CHANGED
@@ -9,7 +9,7 @@ module Bifrost
|
|
9
9
|
|
10
10
|
# The patch version of Bifrost, updated only for bug fixes from the last
|
11
11
|
# feature release.
|
12
|
-
PATCH_VERSION =
|
12
|
+
PATCH_VERSION = 3
|
13
13
|
|
14
14
|
# The full version as a string.
|
15
15
|
VERSION = "#{MAJOR_VERSION}.#{MINOR_VERSION}.#{PATCH_VERSION}".freeze
|
data/lib/bifrost/worker.rb
CHANGED
@@ -7,7 +7,7 @@ module Bifrost
|
|
7
7
|
# This class is used to read messages from the subscriber, and process the messages one
|
8
8
|
# by one. This class is a worker/actor which focusses on processes a single topic/subscriber
|
9
9
|
# combination one at a time
|
10
|
-
class Worker <
|
10
|
+
class Worker < Entity
|
11
11
|
include Celluloid
|
12
12
|
include Celluloid::Internals::Logger
|
13
13
|
include Celluloid::Notifications
|
@@ -55,10 +55,10 @@ module Bifrost
|
|
55
55
|
|
56
56
|
# Actual processing of the message
|
57
57
|
def read_message
|
58
|
-
message = bus.receive_subscription_message(topic, subscriber, timeout: ENV['TIMEOUT'] || 10)
|
58
|
+
message = @bus.interface.receive_subscription_message(topic, subscriber, timeout: ENV['TIMEOUT'] || 10)
|
59
59
|
if message
|
60
60
|
callback.call(message.properties['message'])
|
61
|
-
bus.delete_subscription_message(message)
|
61
|
+
@bus.interface.delete_subscription_message(message)
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
data/spec/bifrost/topic_spec.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'bifrost
|
3
|
-
require 'bifrost/subscriber'
|
2
|
+
require 'bifrost'
|
4
3
|
|
5
4
|
describe Bifrost::Topic do
|
6
5
|
subject(:topic) { Bifrost::Topic.new('topic_name') }
|
@@ -78,7 +77,7 @@ describe Bifrost::Topic do
|
|
78
77
|
it 'should not be able to add a duplicate subscriber' do
|
79
78
|
subscriber = Bifrost::Subscriber.new('another_new_subscriber')
|
80
79
|
expect(new_topic.add_subscriber(subscriber)).to be_truthy
|
81
|
-
expect
|
80
|
+
expect(new_topic.add_subscriber(subscriber)).to be_falsey
|
82
81
|
end
|
83
82
|
end
|
84
83
|
|
data/spec/bifrost/worker_spec.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'bifrost/exceptions/unsupported_lambda_error'
|
3
|
-
require 'bifrost
|
4
|
-
require 'bifrost/topic'
|
5
|
-
require 'bifrost/subscriber'
|
6
|
-
require 'bifrost/worker'
|
3
|
+
require 'bifrost'
|
7
4
|
|
8
5
|
describe Bifrost::Worker do
|
9
6
|
let(:cb) { proc { |m| puts "Received: message #{m}" } }
|
data/spec/spec_helper.rb
CHANGED
@@ -12,7 +12,7 @@ RSpec.configure do |config|
|
|
12
12
|
Dotenv.load('.env.test')
|
13
13
|
|
14
14
|
# All specs use this pre-defined namespace in Azure
|
15
|
-
Azure.sb_namespace = ENV['
|
15
|
+
Azure.sb_namespace = ENV['AZURE_BUS_NAMESPACE']
|
16
16
|
|
17
17
|
# rspec-expectations config goes here. You can use an alternate
|
18
18
|
# assertion/expectation library such as wrong or the stdlib/minitest
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bi-frost
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shirren Premaratne
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: azure
|
@@ -160,6 +160,7 @@ extra_rdoc_files: []
|
|
160
160
|
files:
|
161
161
|
- README.md
|
162
162
|
- lib/bifrost.rb
|
163
|
+
- lib/bifrost/bus.rb
|
163
164
|
- lib/bifrost/entity.rb
|
164
165
|
- lib/bifrost/exceptions/duplicate_subscriber_error.rb
|
165
166
|
- lib/bifrost/exceptions/invalid_worker_definition_error.rb
|
@@ -177,7 +178,7 @@ files:
|
|
177
178
|
- spec/bifrost/version_spec.rb
|
178
179
|
- spec/bifrost/worker_spec.rb
|
179
180
|
- spec/spec_helper.rb
|
180
|
-
homepage: https://github.com/
|
181
|
+
homepage: https://github.com/shirren/bifrost
|
181
182
|
licenses:
|
182
183
|
- MIT
|
183
184
|
metadata: {}
|