bi-frost 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/bifrost/message.rb +14 -10
- data/lib/bifrost/version.rb +2 -2
- data/lib/bifrost/worker.rb +1 -0
- data/spec/bifrost/bus_spec.rb +0 -1
- data/spec/bifrost/message_spec.rb +10 -10
- data/spec/bifrost/worker_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8b9ebfc0c96cc0f16a2bd99f5c4ac62bf2af316
|
4
|
+
data.tar.gz: f766bfcb594119c63145c848f114973b631bef4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61e070940b3a4cb3f7e5bcd0b44b55ec379b07487ce145a92c765551fc326ab7af97c33faf95c7bdb33a13130ca5ccffbec5c1153fe5d1bb3383e8725937c937
|
7
|
+
data.tar.gz: 66067c6787062a0e72e7bb0f6bb5da4c45202a8e6aee9dd2b0b5d0bc037c8ad89ea1bf01b10c1b90a0f7459c2d2da7f69840a4d6faeee1c5024201569493b53e
|
data/README.md
CHANGED
@@ -66,13 +66,13 @@ message = Bifrost::Message.new(content: 'some data')
|
|
66
66
|
message.publish(topic)
|
67
67
|
```
|
68
68
|
|
69
|
-
This function returns a `true` or `false` indicating the success of the message delivery. This method is synchronous. Each message has an identifier which gets sets upon successful delivery only.
|
69
|
+
This function returns a `true` or `false` indicating the success of the message delivery. This method is synchronous. Each message has an identifier which gets sets upon successful delivery only. A Bifrost message can be either a primitive type or a ruby hash.
|
70
70
|
|
71
|
-
A message can also be optionally published with a
|
71
|
+
A message can also be optionally published with meta data or properties, this data structure is a hash.
|
72
72
|
|
73
73
|
```ruby
|
74
74
|
topic = Bifrost::Topic.new('topic_name')
|
75
|
-
message = Bifrost::Message.new(content: 'some data', '
|
75
|
+
message = Bifrost::Message.new({ content: 'some data' }, { app_name: 'bifrost' })
|
76
76
|
message.publish(topic)
|
77
77
|
```
|
78
78
|
|
data/lib/bifrost/message.rb
CHANGED
@@ -5,15 +5,15 @@ 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
7
|
class Message < Entity
|
8
|
-
attr_reader :
|
8
|
+
attr_reader :meta, :body, :status, :message_id
|
9
9
|
|
10
10
|
alias_method :resource_id, :message_id
|
11
11
|
alias_method :id, :message_id
|
12
12
|
|
13
13
|
# A message must have a valid subject and body. The service
|
14
14
|
# bus is initialised in the Entity class
|
15
|
-
def initialize(body,
|
16
|
-
@
|
15
|
+
def initialize(body, meta = {})
|
16
|
+
@meta = meta
|
17
17
|
if body.is_a?(Azure::ServiceBus::BrokeredMessage)
|
18
18
|
merge(body)
|
19
19
|
else
|
@@ -56,11 +56,12 @@ module Bifrost
|
|
56
56
|
def merge(raw_message)
|
57
57
|
@status = :delivered
|
58
58
|
begin
|
59
|
-
@
|
59
|
+
@meta = raw_message.properties
|
60
|
+
@body = JSON.parse(raw_message.body)
|
60
61
|
rescue JSON::ParserError
|
61
|
-
@body = raw_message
|
62
|
+
@body = raw_message
|
62
63
|
end
|
63
|
-
@message_id = raw_message.
|
64
|
+
@message_id = raw_message.message_id
|
64
65
|
end
|
65
66
|
|
66
67
|
# Create the message and attempt to deliver It
|
@@ -69,17 +70,20 @@ module Bifrost
|
|
69
70
|
update_message_state_to_delivered(message)
|
70
71
|
end
|
71
72
|
|
72
|
-
# Create the brokered message
|
73
|
+
# Create the brokered message, note that the Bifrost message supports native
|
74
|
+
# ruby hashes, but during the transport these messages are converted to JSON
|
75
|
+
# strings
|
73
76
|
def create_brokered_message
|
74
|
-
|
75
|
-
message
|
77
|
+
payload = body.respond_to?(:to_json) ? body.to_json : body
|
78
|
+
message = Azure::ServiceBus::BrokeredMessage.new(payload, meta)
|
79
|
+
message.message_id = SecureRandom.uuid
|
76
80
|
message
|
77
81
|
end
|
78
82
|
|
79
83
|
# Update the status of the message post delivery
|
80
84
|
def update_message_state_to_delivered(message)
|
81
85
|
@status = :delivered
|
82
|
-
@message_id = message.
|
86
|
+
@message_id = message.message_id
|
83
87
|
end
|
84
88
|
end
|
85
89
|
end
|
data/lib/bifrost/version.rb
CHANGED
@@ -5,11 +5,11 @@ module Bifrost
|
|
5
5
|
MAJOR_VERSION = 0
|
6
6
|
|
7
7
|
# The minor version of Bifrost, updated for new feature releases.
|
8
|
-
MINOR_VERSION =
|
8
|
+
MINOR_VERSION = 4
|
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 = 0
|
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
@@ -57,6 +57,7 @@ module Bifrost
|
|
57
57
|
|
58
58
|
# Actual processing of the message
|
59
59
|
def read_message
|
60
|
+
byebug
|
60
61
|
raw_message = @bus.interface.receive_subscription_message(topic, subscriber, timeout: ENV['TIMEOUT'] || 10)
|
61
62
|
if raw_message
|
62
63
|
info("Worker #{self} picked up message #{raw_message}") if Bifrost.debug?
|
data/spec/bifrost/bus_spec.rb
CHANGED
@@ -2,9 +2,9 @@ require 'spec_helper'
|
|
2
2
|
require 'bifrost'
|
3
3
|
|
4
4
|
describe Bifrost::Message do
|
5
|
-
subject(:message) { Bifrost::Message.new({ content: 'some data' }, '
|
5
|
+
subject(:message) { Bifrost::Message.new({ content: 'some data' }, { app_name: 'bifrost' }) }
|
6
6
|
|
7
|
-
it { is_expected.to respond_to(:
|
7
|
+
it { is_expected.to respond_to(:meta) }
|
8
8
|
it { is_expected.to respond_to(:status) }
|
9
9
|
it { is_expected.to respond_to(:message_id) }
|
10
10
|
it { is_expected.to respond_to(:resource_id) }
|
@@ -18,11 +18,6 @@ describe Bifrost::Message do
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
it 'should be able to auto generate a subject' do
|
22
|
-
new_message = Bifrost::Message.new(content: 'some data')
|
23
|
-
expect(new_message).to_not be_nil
|
24
|
-
end
|
25
|
-
|
26
21
|
describe 'publish' do
|
27
22
|
it 'should publish to a valid topic' do
|
28
23
|
topic = Bifrost::Topic.new('valid-topic')
|
@@ -31,7 +26,14 @@ describe Bifrost::Message do
|
|
31
26
|
expect(message.publish(topic)).to be_truthy
|
32
27
|
expect(message.status).to eq(:delivered)
|
33
28
|
expect(message.message_id).not_to be_nil
|
34
|
-
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should publish a primitive in its payload' do
|
32
|
+
topic = Bifrost::Topic.new('valid-topic')
|
33
|
+
topic.save
|
34
|
+
topic.add_subscriber(Bifrost::Subscriber.new('new_subscriber'))
|
35
|
+
msg = Bifrost::Message.new(1, { app_name: 'bifrost' })
|
36
|
+
expect(msg.publish(topic)).to be_truthy
|
35
37
|
end
|
36
38
|
|
37
39
|
it 'should not be postable to an invalid topic' do
|
@@ -50,7 +52,6 @@ describe Bifrost::Message do
|
|
50
52
|
expect(message.status).to eq(:delivered)
|
51
53
|
expect(message.message_id).not_to be_nil
|
52
54
|
expect(response).to eq(message.message_id)
|
53
|
-
topic.delete
|
54
55
|
end
|
55
56
|
|
56
57
|
it 'should update the message id on a replublish of the same messsage' do
|
@@ -64,7 +65,6 @@ describe Bifrost::Message do
|
|
64
65
|
expect(response).to eq(message.message_id)
|
65
66
|
upd_response = message.publish!(topic)
|
66
67
|
expect(upd_response).not_to eq(response)
|
67
|
-
topic.delete
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'should raise an exception upon publish to an invalid topic' do
|
data/spec/bifrost/worker_spec.rb
CHANGED
@@ -31,7 +31,7 @@ describe Bifrost::Worker do
|
|
31
31
|
topic.save
|
32
32
|
subscriber = Bifrost::Subscriber.new('subscriber')
|
33
33
|
topic.add_subscriber(subscriber)
|
34
|
-
msg = Bifrost::Message.new([item1: { data: 2 }, item2: { more_data: 3 }])
|
34
|
+
msg = Bifrost::Message.new([item1: { data: 2 }, item2: { more_data: 3 }], { app_name: 'bifrost' })
|
35
35
|
msg.publish(topic)
|
36
36
|
expect(msg.status).to eq(:delivered)
|
37
37
|
expect(msg.message_id).not_to be_nil
|
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.
|
4
|
+
version: 0.4.0
|
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-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: azure
|