bi-frost 0.2.3 → 0.3.1

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: d92c6ad28d58300dc0d87fa0461b00cffd9319b2
4
- data.tar.gz: 72998caea23e6a28bbd2f2f996ca305f284788d0
3
+ metadata.gz: 411dc7aed154c803362268cf06d0f14b26754adf
4
+ data.tar.gz: c5ce6bd8a38fc2040972ca3b3debf56d1aaf150f
5
5
  SHA512:
6
- metadata.gz: 7dc98b221e3de6afa5e53478c9cc1915cdc50806dc08bf986a6a11d17651fad584f11f06985cf89092c9023bc1d56222b486de18d7ac313f77fecbe873b92c0c
7
- data.tar.gz: 7408d17a8785c8e0d563de1c194fce19dd29b3b0357cb9c3dac2709b10f5efdda58db2152cfd99212ff27cd0d84aec7cc972c18959438046d8cc8554acd4d482
6
+ metadata.gz: 2adc9df5efee3768aad4704ae356fb32c4154146dcce4845928d02ec57ac52b171d97258c393f2f1eb7fa2b2d3ac500d7fb7ad2fabe6cb9916d399ef12674171
7
+ data.tar.gz: 43c9e7c276de096a0de5c392e462761e8147d915457f3c30b74fb55608440b4a462c689c02847c463698b692daa38662d4f33a1eab3a43502a6a412c9ca0aa6f
@@ -7,12 +7,18 @@ module Bifrost
7
7
  class Message < Entity
8
8
  attr_reader :subject, :body, :status, :message_id
9
9
 
10
+ alias_method :resource_id, :message_id
11
+
10
12
  # A message must have a valid subject and body. The service
11
13
  # bus is initialised in the Entity class
12
14
  def initialize(body, subject = nil)
13
15
  @subject = subject || SecureRandom.base64
14
- @body ||= body
15
- @status ||= :undelivered
16
+ if body.is_a?(Azure::ServiceBus::BrokeredMessage)
17
+ merge(body)
18
+ else
19
+ @body ||= body
20
+ @status ||= :undelivered
21
+ end
16
22
  super()
17
23
  end
18
24
 
@@ -39,6 +45,18 @@ module Bifrost
39
45
 
40
46
  private
41
47
 
48
+ # Merges this message with the required properties of the raw Azure brokered message
49
+ # The sender might send a message other than JSON in which case we just send the raw data along
50
+ def merge(raw_message)
51
+ @status = :delivered
52
+ begin
53
+ @body = JSON.parse(raw_message.properties['message'])
54
+ rescue JSON::ParserError
55
+ @body = raw_message.properties['message']
56
+ end
57
+ @message_id = raw_message.correlation_id
58
+ end
59
+
42
60
  # Create the message and attempt to deliver It
43
61
  def send_message(topic, message)
44
62
  @bus.interface.send_topic_message(topic.name, message)
@@ -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 = 2
8
+ MINOR_VERSION = 3
9
9
 
10
10
  # The patch version of Bifrost, updated only for bug fixes from the last
11
11
  # feature release.
12
- PATCH_VERSION = 3
12
+ PATCH_VERSION = 1
13
13
 
14
14
  # The full version as a string.
15
15
  VERSION = "#{MAJOR_VERSION}.#{MINOR_VERSION}.#{PATCH_VERSION}".freeze
@@ -55,10 +55,11 @@ module Bifrost
55
55
 
56
56
  # Actual processing of the message
57
57
  def read_message
58
- message = @bus.interface.receive_subscription_message(topic, subscriber, timeout: ENV['TIMEOUT'] || 10)
59
- if message
60
- callback.call(message.properties['message'])
61
- @bus.interface.delete_subscription_message(message)
58
+ raw_message = @bus.interface.receive_subscription_message(topic, subscriber, timeout: ENV['TIMEOUT'] || 10)
59
+ if raw_message
60
+ message = Bifrost::Message.new(raw_message)
61
+ callback.call(message)
62
+ @bus.interface.delete_subscription_message(raw_message)
62
63
  end
63
64
  end
64
65
  end
@@ -7,6 +7,7 @@ describe Bifrost::Message do
7
7
  it { is_expected.to respond_to(:subject) }
8
8
  it { is_expected.to respond_to(:status) }
9
9
  it { is_expected.to respond_to(:message_id) }
10
+ it { is_expected.to respond_to(:resource_id) }
10
11
  it { is_expected.to respond_to(:body) }
11
12
  it { is_expected.to respond_to(:publish) }
12
13
  it { is_expected.to respond_to(:publish!) }
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.2.3
4
+ version: 0.3.1
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-14 00:00:00.000000000 Z
11
+ date: 2016-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: azure
@@ -200,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
200
  version: '0'
201
201
  requirements: []
202
202
  rubyforge_project:
203
- rubygems_version: 2.5.1
203
+ rubygems_version: 2.4.5.1
204
204
  signing_key:
205
205
  specification_version: 4
206
206
  summary: Bifrost is a pub/sub wrapper library which uses the Azure message bus and