Coder Social home page Coder Social logo

kinesisnet's Introduction

KinesisNet

A simple kinesis consumer/producer library for .NET

Overview

This is a basic library for handling Amazon Kinesis partly inspired by the excellent ReactoKinesisX.

While it's not as (yet) fully featured as the aforementioned library it is enough to play with. Pull requests are welcome.

The idea behind this project was to make the consumption of the AWS Kinesis pipeline/stream easier on .NET. This library allows you to subscribe to a stream and automatically retrieve records as they appear in the stream. The library uses DynamoDB to store checkpoints so that you can interrupt the processing of messages (at any point) and then seamlessly resume from where you left off.

(If you are going to use this library please set up an IAM user and grant him access to Kinesis and Dynamo. The library will automatically create the right tables and persist checkpoints. However, you can turn off Dynamo if you do not wish to use it).

The library also allows you to put records onto the stream (via the Producer component) and make changes to the stream (via the Utilities component). The major advantage of using a library such as this is that it will handle complex events such as resharding automatically. The library looks at the stream at regular intervals and automatically adjusts to the conditions at hand.

There are two major dependencies to this library - AWS SDK and Serilog. If folks prefer to use Log4Net please let me know and/or issue a pull request.

Please feel free to drive-test this library and raise issues/pull requests against the code. There is a sample project included that will give you a sense for how to use KinesisNet.

Basics

Installation

Use Nuget to install KinesisNet into your project Install-Package KinesisNet or via the Package Manager.

How to Run

Create an instance of KManager with your credentials and then use the Consumer to retrieve records or Producer to put records.

    public class RecordProcessor : IRecordProcessor
    {
        public void Process(string shardId, string sequenceNumber, DateTime lastUpdateUtc, IList<Record> records, Action<string, string, DateTime> saveCheckpoint)
        {
            foreach (var record in records)
            {
                var msg = Encoding.UTF8.GetString(record.Data.ToArray());
                Console.WriteLine("ShardId: {0}, Data: {1}", shardId, msg);
            }
            
            saveCheckpoint(shardId, sequenceNumber, lastUpdateUtc);
        }
    }


    static void Main(string[] args)
   	{
        var awsKey = ConfigurationManager.AppSettings["AWSKey"];
        var awsSecret = ConfigurationManager.AppSettings["AWSSecret"];
        var streamName = ConfigurationManager.AppSettings["AWSStreamName"];
        var regionEndpoint = RegionEndpoint.GetBySystemName(ConfigurationManager.AppSettings["AWSRegionEndpoint"]);
        var workerId = "MyComputer";

        var kManager = new KManager(awsKey, awsSecret, streamName, regionEndpoint, workerId);

        var result = kManager
                    .Consumer
                    .Start(new RecordProcessor());

        if (result.Success)
        {
        	Console.WriteLine("We are now processing results");
        }

        kManager.Producer.PutRecord("Create Record " + DateTime.UtcNow);

        kManager.Consumer.Stop(); //stop processing
    }

Configuration

You may configure KinesisNet or get information about the Stream via the utilities component of KManager.

Examples

To come....

kinesisnet's People

Contributors

sbarski avatar

Watchers

 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.