Giter VIP home page Giter VIP logo

kcl-rb's Introduction

kcl-rb

CI

Overview

Documentation

The Amazon Kinesis Client Library for Pure Ruby (Amazon KCL) enables Ruby developers to easily consume and process data from Amazon Kinesis.

Already KCL for Ruby is provided by AWS, but Java is required for the operating environment because MultiLangDaemon is used. kcl-rb is built on Pure Ruby, not depend on Java.

Installation

Add this line to your application's Gemfile:

gem 'kcl-rb'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install kcl-rb

Usage

It's okay if you develop it according to the KCL specifications.

Implement the RecordProcessor

class RecordProcessor < Kcl::RecordProcessor
  def after_initialize(initialization_input)
    puts "SHARD_ID: #{initialization_input.shard_id}"
  end

  def process_records(records_input)
    puts "Current behind: #{records_input.millis_behind_latest}"
    records_input.records.each do |record|
      puts "Record: #{record}"
    end
  end

  def shutdown(shutdown_input)
    puts "Shutdown reason: #{shutdown_input.shutdown_reason}"

    if shutdown_input.shutdown_reason == Kcl::Workers::ShutdownReason::TERMINATE
      shutdown_input.record_checkpointer.update_checkpoint(nil)
    end
  end
end

Implement a Class Factory for the RecordProcessor

class RecordProcessorFactory < Kcl::RecordProcessorFactory
  def create_processor
    RecordProcessor.new
  end
end

Initialize KCL configurations

Kcl.configure do |config|
  config.dynamodb_endpoint = "http://localhost:4566"
  config.dynamodb_table_name = "kcl-rb-test"
  config.workers_health_table_name = "kcl-rb-test-health"
  config.kinesis_endpoint = "http://localhost:4566"
  config.kinesis_stream_name = "kcl-rb-test"
end

If you want to see all the setting items, please see config class file.

Run a Worker

worker_id = 'kcl-worker'
factory = RecordProcessorFactory.new
Kcl::Worker.run(worker_id, factory)

If you want more concrete example, look under the demo directory.

Development

Prerequisites

  • Install Ruby 2.7.1
  • Install docker
  • Install Terraform

Build & Run for RSpec

Create Kinesis resources on localstack using Terraform

$ docker-compose up -d
$ cd terraform
$ terraform init
$ terraform apply

Build dependencies.

$ bundle install --path vendor/bundle

And run RSpec.

$ bundle exec rspec

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/waka/kcl-rb.

License

The gem is available as open source under the terms of the MIT License.

kcl-rb's People

Contributors

dependabot[bot] avatar skcc321 avatar thecubed avatar waka avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

thecubed

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.