Giter Site home page Giter Site logo

kafka_producer's Introduction

Kafka Service App

Python application that concurrently sends out http request to NAV endpoint and writes the response to Kafka server.

Pre-requisites

  • Apache Kafka 2.13-2.8
  • Java version "1.8.0_301"

Steps

  1. Clone the project
git https://github.com/nihadtp/kafka_producer.git
  1. Got Kafka directory and open a terminal and start zookeeper and kafka server
sudo ./bin/zookeeper-server-start.sh config/zookeeper.properties
sudo ./bin/kafka-server-start.sh config/server.properties
  1. Create an input topic. Use the same name in the spark streaming app configuration.
./kafka-topics.sh --create --topic mutualFundTopic --if-not-exists --partitions 4 --config max.message.bytes=10000000 --bootstrap-server localhost:9092
  1. Create an error topic to send back invalid data
./kafka-topics.sh --create --topic error_topic --if-not-exists --partitions 1 --config max.message.bytes=10000000 --bootstrap-server localhost:9092
  1. Go to main project directory- kafka_producer and instal dependencies
pip install -r requirements.txt
  1. Run the python application
python kafka_service.py

Python application will start sending out http response to kafka. I have added logger to see the real time status.

  1. Concurrently open a new terminal and start a cron job using cronTab and periodically execute job.py which fetches latest NAV data from API and write out to Kafka.
$ cronttab -e
* * * * * /Users/nihadtp/miniforge3/lib/python3.9 /Users/nihadtp/Downloads/prodigal/job.py
~                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
~                                                                                                                                                                 
~                                                                                                                                                                 
"/tmp/crontab.wGXZbtOPBt" 2L, 92B

Five asteroid means the script is executed every minute. You can configure the period using number of asteroids to match the requirement. For example giving 0 0 * * * will periodically run this script at every day at 0th minute and 0th hour.

kafka_producer's People

Watchers

Nihad Thailakandy Pandikashala  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.