Coder Social home page Coder Social logo

rising_dragon's Introduction

Build Status Dependency 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', '>= 0.3.3'

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.

rising_dragon's People

Contributors

ota42y avatar

Watchers

James Cloos avatar Shinozuka Fumiya avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.