0.01
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Event driven architecture library for AWS SNS/SQS include SQS worker and SNS publisher
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.14
>= 0.52.1.0
~> 0.10
~> 12.0
~> 3

Runtime

>= 3.1.7
 Project Readme

Build Status Code Climate

RisingDragon

Use AWS SQS/SNS as event worker for Microservices.

(Shoryuken wrapper)

Installation

Add this line to your application's Gemfile:

gem 'rising_dragon'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rising_dragon

Publisher Usage

require 'aws-sdk'
require 'rising_dragon'

sns_client = Aws::SNS::Client.new(
    access_key_id: Settings.aws.access_key_id,
    secret_access_key: Settings.aws.secret_access_key,
    region: Settings.aws.region,
)

publisher = ::RisingDragon::SNS::Publisher.new(sns_client)

data = { id: 1, name: "first last" }
publisher.publish("SNSTopicName", "EventType", data)

Worker Usage

execute bundle exec shoryuken -r steps_worker.rb

setting file

# steps_worker.rb
require 'aws-sdk'
require 'rising_dragon'

RisingDragon.sqs_client = Aws::SQS::Client.new(
  secret_access_key: Settings.aws.secret_access_key,
  access_key_id:     Settings.aws.access_key_id,
  region:            Settings.aws.steps_sqs.region
)

class StepsEventHandler < ::RisingDragon::SQS::Handler
  def handle(event)
    puts event.type
    puts event.data
    puts event.id
    puts event.timestamp
  end
end

class SQSWorker
  include RisingDragon::SQS::Worker

  rising_dragon_options "SQSQueueName"
  
  rising_dragon_register "StepsEvent", StepsEventHandler
  rising_dragon_ignore "IgnoreEvent"
end

event structure

{
    Message: {
        type: "StepsEvent",
        data: {
            # write youre event data
            "id": 42,
            "datetime": DateTime.new(2016, 04, 01, 16, 00, 00, "+09:00")
        },
        id: SecureRandom.uuid,
        timestamp: (Time.now.to_f * 1000).to_i
    }
}

Development

After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ota42y/rising_dragon. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.