Skip to content
Snippets Groups Projects
Commit 38ccec13 authored by bne86's avatar bne86
Browse files

add the skeleton for a neo4j consumer, set it as default in docker-compose environment.

parent 61b62640
Branches
No related tags found
No related merge requests found
Pipeline #
......@@ -12,19 +12,34 @@ services:
- zookeeper
- kafka
consumer:
neo4j-consumer:
build:
context: ..
dockerfile: docker/kafka/consumer/Dockerfile
dockerfile: docker/kafka/neo4j-consumer/Dockerfile
links:
- kafka
- neo4j
neo4j:
image: neo4j:latest
ports:
- "7474:7474"
- "7687:7687"
environment:
- NEO4J_AUTH=none
producer:
build:
context: ..
dockerfile: docker/kafka/producer/Dockerfile
links:
- kafka
# consumer:
# build:
# context: ..
# dockerfile: docker/kafka/consumer/Dockerfile
# links:
# - kafka
# producer:
# build:
# context: ..
# dockerfile: docker/kafka/producer/Dockerfile
# links:
# - kafka
kafka:
image: wurstmeister/kafka
......
FROM python:2.7-alpine
MAINTAINER bne86 <b.von.st.vieth@fz-juelich.de>
ADD docker/kafka/neo4j-consumer/requirements.txt requirements.txt
RUN pip install -r requirements.txt
ADD docker/kafka/neo4j-consumer/consumer.py consumer.py
CMD python consumer.py
"""consume kafka messages."""
from kafka import KafkaConsumer
from kafka.errors import KafkaError
import json
import logging
if __name__ == '__main__':
logging.getLogger().setLevel('INFO')
logging.info('Starting Kafka Consumer')
consumer = None
tries = 1
while not consumer:
logging.info('{}. try'.format(tries))
try:
consumer = KafkaConsumer('swift',
bootstrap_servers='kafka:9092',
client_id='swift-kafka-consumer',
key_deserializer=lambda k: k.decode('utf-8'),
value_deserializer=lambda m: json.loads(m.decode('utf-8')))
except KafkaError:
logging.info('Currently something wrong with Kafka, retrying...')
tries += 1
print('Consumer done with initialization')
try:
for message in consumer:
logging.info("%s:%d:%d: key=%s value=%s" % (message.topic,
message.partition,
message.offset,
message.key,
message.value))
except KeyboardInterrupt:
logging.info('Exiting Kafka Consumer...')
kafka-python==1.3.2
neo4j-driver==1.1.0rc1
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment