Git Product home page Git Product logo

kafka-to-liveview's Introduction

Kafka To LiveView

A POC code repository to show an event flowing from

  1. Kafka
  2. Broadway
  3. Elixir Pubsub
  4. Live View

Deploy via Nullstone

  1. Create postgresql datastore.
  2. Create kafka datastore.
  3. Create a public web app. (Remember app-name for later)
  4. Add the postgresql datastore (from step 1) to the app.
  5. Add the kafka datastore (from step 2) to the app.
  6. Add the SECRET_KEY_BASE for Rails Cookies capability to the app. (this capability works for Rails and Phoenix)
  7. Provision
nullstone up --wait --block=<app-name> --env=<env-name>
  1. Build, push, and deploy
docker build -t pubsublive .
nullstone launch --source=pubsublive --app=<app-name> --env=<env-name>

How to run locally with docker

# Start zookeeper, kafka, and postgres (detached)
docker compose up -d db kafka zookeeper
# Start app and tail logs
docker compose up app

Create a topic. FOr this demo, we are using the topic "orders"

docker compose exec kafka kafka-topics.sh --create --topic orders --bootstrap-server kafka:9092

How to run locally without docker

Visit http://localhost:4000/ticker

Download Kafka

Get the latest version of Kafka

Start Kafka

Start the server

$ bin/zookeeper-server-start.sh config/zookeeper.properties
$ bin/kafka-server-start.sh config/server.properties

Create a topic, if not already in place. For this demo we are using the topic "orders"

$ bin/kafka-topics.sh --create --topic orders --bootstrap-server localhost:9092

Additional Help

Fire Away

Send messages to Kafka, to be picked up by Broadway, to send to Phoenix to send to FE

# Format is unique id, name, and a price.  Name and price will update based on ID
# Number of messages to send
PubsubLive.Orders.simulate(100)

Code to look at for wiring



lib
├── pubsublive
│   ├── application.ex           # Broadway Config
│   ├── my_broadway.ex           # Broadway Code to accept Kafka
│   ├── orders.ex                # Generate messages for Kafka
└── pubsublive_web
    ├── live
    │   ├── ticker.ex            # Ticker LiveView, most of the code is here
    │   └── ticker_component.ex  # Ticker Component
    └── router.ex                # routes added for /ticker 

assets
├── css
│   └── app.css                  # Styling for flash on change
└── js
    └── app.js                   # Small hook for JS/LiveView Interop to flash

kafka-to-liveview's People

Contributors

newtonlabs avatar bsick7 avatar

Stargazers

Sean Chatman avatar  avatar Chris Parker avatar

Watchers

 avatar James Cloos avatar

Forkers

bsick7

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.