Skip to content

Commit

Permalink
Merge pull request #30 from Sage/API-1973/Wrap_message_body_when_rais…
Browse files Browse the repository at this point in the history
…ing_event_directly_in_SQS

API-1973: Wrap message body when raising event directly in SQS
  • Loading branch information
vaughanbrittonsage authored Nov 16, 2017
2 parents c7c3c2c + cfecf4a commit 9321d6a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion eventq_aws/eventq_aws.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec'

spec.add_dependency 'aws-sdk-core'
spec.add_dependency 'aws-sdk-core', '~> 2.0'
spec.add_dependency 'eventq_base', '~> 1.15'

if RUBY_PLATFORM =~ /java/
Expand Down
6 changes: 5 additions & 1 deletion eventq_aws/lib/eventq_aws/aws_eventq_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def raise_event_in_queue(event_type, event, queue, delay, context = {})

response = @client.sqs.send_message(
queue_url: queue_url,
message_body: message,
message_body: sqs_message_body_for(message),
delay_seconds: delay
)

Expand Down Expand Up @@ -111,6 +111,10 @@ def serialized_message(queue_message)
def topic_arn(event_type)
@client.get_topic_arn(event_type)
end

def sqs_message_body_for(payload_message)
JSON.dump(EventQ::Amazon::QueueWorker::MESSAGE => payload_message)
end
end
end
end
4 changes: 3 additions & 1 deletion eventq_aws/lib/eventq_aws/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

module EventQ
module Amazon
VERSION = "1.14.0"
VERSION = "1.14.1"
end
end
8 changes: 5 additions & 3 deletions eventq_aws/spec/aws_eventq_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@

it 'sends an event to SQS' do
expect(queue_client.sqs).to receive(:send_message) do |options|
message_json = JSON.parse(options[:message_body])
expect(message_json['content']).to eql event
expect(message_json['type']).to eql event_type
outer_message_json = JSON.parse(options[:message_body])

inner_message_json = JSON.parse(outer_message_json[EventQ::Amazon::QueueWorker::MESSAGE])
expect(inner_message_json['content']).to eql event
expect(inner_message_json['type']).to eql event_type

expect(options[:delay_seconds]).to eql delay_seconds
end.and_return(result)
Expand Down
2 changes: 1 addition & 1 deletion eventq_aws/spec/integration/aws_eventq_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
expect(response.messages.length).to eq(1)

msg = response.messages[0]
payload_hash = JSON.load(msg.body)
payload_hash = JSON.load(JSON.load(msg.body)[EventQ::Amazon::QueueWorker::MESSAGE])
payload = class_kit.from_hash(hash: payload_hash, klass: EventQ::QueueMessage)

EventQ.logger.debug { "[QUEUE] - received message: #{msg_body}" }
Expand Down

0 comments on commit 9321d6a

Please sign in to comment.