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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 986bfabd346d59957dd78009b4ea2170214dcd0d
4
- data.tar.gz: e9454650e4be44971f021473143866bc22f31af6
3
+ metadata.gz: f8b9ebfc0c96cc0f16a2bd99f5c4ac62bf2af316
4
+ data.tar.gz: f766bfcb594119c63145c848f114973b631bef4d
5
5
  SHA512:
6
- metadata.gz: bb982048b43860fed16c4e7af9058d9fdb34c206420c67c02d047e2763a9b5510d4599e94e2952e41d297832806de3c8df79966e9acb0ff528e79a4bb3d6830d
7
- data.tar.gz: d19145821ad14b54be7ec645959956c1a93059d58a8cf618a82b5fd8d8f8e262ef5a9fae40c427da552a2c411d41edce06959993c3969672519e9a3a460f21f5
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 subject;
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', 'message subject')
75
+ message = Bifrost::Message.new({ content: 'some data' }, { app_name: 'bifrost' })
76
76
  message.publish(topic)
77
77
  ```
78
78
 
@@ -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 :subject, :body, :status, :message_id
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, subject = nil)
16
- @subject = subject || SecureRandom.base64
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
- @body = JSON.parse(raw_message.properties['message'])
59
+ @meta = raw_message.properties
60
+ @body = JSON.parse(raw_message.body)
60
61
  rescue JSON::ParserError
61
- @body = raw_message.properties['message']
62
+ @body = raw_message
62
63
  end
63
- @message_id = raw_message.correlation_id
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
- message = Azure::ServiceBus::BrokeredMessage.new(subject, message: body)
75
- message.correlation_id = SecureRandom.uuid
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.correlation_id
86
+ @message_id = message.message_id
83
87
  end
84
88
  end
85
89
  end
@@ -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 = 3
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 = 2
12
+ PATCH_VERSION = 0
13
13
 
14
14
  # The full version as a string.
15
15
  VERSION = "#{MAJOR_VERSION}.#{MINOR_VERSION}.#{PATCH_VERSION}".freeze
@@ -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?
@@ -16,7 +16,6 @@ describe Bifrost::Bus do
16
16
  topic.save
17
17
  dup_topic = Bifrost::Topic.new('bus-topic')
18
18
  expect(bus.topic_exists?(dup_topic)).to be_truthy
19
- topic.delete
20
19
  end
21
20
  end
22
21
  end
@@ -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' }, 'subscriber_name') }
5
+ subject(:message) { Bifrost::Message.new({ content: 'some data' }, { app_name: 'bifrost' }) }
6
6
 
7
- it { is_expected.to respond_to(:subject) }
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
- topic.delete
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
@@ -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.3.2
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-19 00:00:00.000000000 Z
11
+ date: 2016-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: azure