Coder Social home page Coder Social logo

rising_dragon's Introduction

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.

rising_dragon's People

Contributors

ota42y avatar shinofumijp avatar sue445 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rising_dragon's Issues

Explicit delete feature of RisingDragon::Event

For example, at exception handling, I want to delete RisingDragon::Event at an arbitrary timing.

Simply implement it as follows.

e.g.)

    1 module RisingDragon
    2   class Event
    3     attr_reader :id, :type, :timestamp, :data
~   4     def initialize(id:, type:, timestamp:, data:, sqs_msg:)
    5       @id = id
    6       @type = type
    7       @timestamp = timestamp
    8       @data = data
+   9       @sqs_msg = sqs_msg
   10     end
   11
   12     def to_json(*option)
   13       {
   14         id: @id,
   15         type: @type,
   16         timestamp: @timestamp,
   17         data: @data,
   18       }.to_json(*option)
   19     end
+  20
+  21     def delete
+  22       @sqs_msg.delete
+  23     end
   24   end
   25 end

This is an implementation to have sqs_msg passed from Shoryuken as an attribute of RisingDragon::Event.

Delete of RisingDragon::Event can be realized with this implementation, but I do not know whether it meets the designing policy of RisingDragon (it will increase the responsibility of RisingDragon::Event), I would like you to check it.

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.