Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE WIP] consumer stack initial drop #3

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions kafka/consumer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:3.8-slim-buster

WORKDIR /app

COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt

COPY . .

CMD [ "python3", "consumer.py"]
34 changes: 34 additions & 0 deletions kafka/consumer/consumer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

from ensurepip import bootstrap
from confluent_kafka import Consumer
import os



def consume(topic_name,bootstrap_server):
c = Consumer({
'bootstrap.servers': bootstrap_server,
'group.id': 'mygroup',
'auto.offset.reset': 'earliest'})

c.subscribe([topic_name])

while True:
msg = c.poll(1.0)

if msg is None:
continue
if msg.error():
print("Consumer error: {}".format(msg.error()))
continue

print('Received message: {}'.format(msg.value().decode('utf-8')))

c.close()



if __name__ == "__main__":
topic_name = os.getenv('TOPIC', 'new-topic')
bootstrap_server = os.getenv('BOOTSTRAP_SERVER','localhost:9092')
consume(topic_name,bootstrap_server)
1 change: 1 addition & 0 deletions kafka/consumer/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
confluent-kafka
16 changes: 16 additions & 0 deletions manifests/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Pod
metadata:
name: co2signal-kafka-consumer
namespace: kafka
labels:
purpose: co2signal-kafka-consumer
spec:
containers:
- name: co2signal-kafka-consumer
image: quay.io/husky_parul/co2signal_kafka_consumer:latest
env:
- name: BOOTSTRAP_SERVER
value: "my-cluster-kafka-0.my-cluster-kafka-brokers.kafka.svc:9092"
- name: TOPIC
value: "co2-topic"
6 changes: 6 additions & 0 deletions manifests/kafka-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#! /bin/bash

oc new-project kafka ;
kubectl create -f 'https://strimzi.io/install/latest?namespace=kafka' -n kafka ;
kubectl apply -f https://strimzi.io/examples/latest/kafka/kafka-persistent-single.yaml -n kafka ;