Git Product home page Git Product logo

database-to-kafka's Introduction

Send database table (rows filtered by criteria) to Kafka

Every second by the scheduler in one transaction

  1. Lock rows in database table by criteria (to concurrency with another instance of microservices)
  2. Select rows
  3. Convert rows to messages
  4. Send messages to Kafka
  5. Update selected rows in database table
  6. Unlock rows

Used Simple Moving Average (SMA) for adjust the amount of rows selected from database

Core in GetTradeRsProcessor.java


  • Execute postgresql.sql instance to create database table
  • Run DataGenerator.java to fill table by test data before execution
  • Build mvn clean install
  • Run 1st instance ./run.sh
  • Run 2nd instance ./run2.sh
  • To monitoring process, execute
select count(*) from sample.trade t where t.sent = true;

Test data like this:

INSERT INTO sample.trade (id, client_id, exchange, ticker, price, amount, date, status, sent) 
VALUES (13784, 29321, 'NASDAQ', 'AAPL', 246.31, 28, '2020-09-25 17:22:28.931+00', 'COMPLETED', false);
INSERT INTO sample.trade (id, client_id, exchange, ticker, price, amount, date, status, sent) 
VALUES (13785, 43001, 'NYSE', 'DIS', 226.14, 2, '2020-09-25 17:22:28.931+00', 'CANCELLED', false);
INSERT INTO sample.trade (id, client_id, exchange, ticker, price, amount, date, status, sent) 
VALUES (13786, 14295, 'NASDAQ', 'MSFT', 290.8, 97, '2020-09-25 17:22:28.931+00', 'CANCELLED', false);

  1. Run Zookeeper bin/zookeeper-server-start.sh config/zookeeper.properties
  2. Run Kafka bin/kafka-server-start.sh config/server.properties
  3. See Topics bin/kafka-topics.sh --list --bootstrap-server localhost:9092

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.