From 697841764958d87b8bff1667e8b3abc17ec0ad4b Mon Sep 17 00:00:00 2001 From: Eduardo Hattori Date: Tue, 12 Apr 2022 17:58:11 -0300 Subject: [PATCH] feat: create a parent broker and impl aws_broker --- lib/pipefy_message/providers/aws_broker.rb | 21 +++++++++++++++++++++ lib/pipefy_message/providers/broker.rb | 9 +++++++++ 2 files changed, 30 insertions(+) create mode 100644 lib/pipefy_message/providers/aws_broker.rb create mode 100644 lib/pipefy_message/providers/broker.rb diff --git a/lib/pipefy_message/providers/aws_broker.rb b/lib/pipefy_message/providers/aws_broker.rb new file mode 100644 index 0000000..066a120 --- /dev/null +++ b/lib/pipefy_message/providers/aws_broker.rb @@ -0,0 +1,21 @@ +require "aws-sdk-sqs" +require "json" + +module PipefyMessage + module Providers + class AwsBroker < Broker + def initialize(queue_url) + @poller = Aws::SQS::QueuePoller.new(queue_url) + @wait_time_seconds = 10 + end + + def poller() + ## Aws poller + @poller.poll(wait_time_seconds: @wait_time_seconds) do |received_message| + payload = JSON.parse(received_message.body) + yield(payload) + end + end + end + end +end \ No newline at end of file diff --git a/lib/pipefy_message/providers/broker.rb b/lib/pipefy_message/providers/broker.rb new file mode 100644 index 0000000..de3a1aa --- /dev/null +++ b/lib/pipefy_message/providers/broker.rb @@ -0,0 +1,9 @@ +module PipefyMessage + module Providers + class Broker + def poller() + raise NotImplementedError + end + end + end +end \ No newline at end of file