Python, Flask and Pulsar
docker run -it -p 6650:6650 -p 8080:8080 apachepulsar/pulsar:2.4.1 bin/pulsar standalone docker build -t mydocker . docker run --rm -it mydocker bash
examples/python-pulsar/docker-compose.yml
version: '3.7' services: web: build: . ports: - "5001:5000" volumes: - .:/opt links: - pulsar pulsar: image: apachepulsar/pulsar:2.5.2 container_name: my-pulsar expose: - 8080 - 6650 command: > /bin/bash -c "bin/apply-config-from-env.py conf/standalone.conf && bin/pulsar standalone" # dashboard: # image: apachepulsar/pulsar-dashboard # depends_on: # - pulsar # ports: # - "5002:80" # environment: # - SERVICE_URL=http://pulsar:8080
examples/python-pulsar/Dockerfile
FROM ubuntu:20.04 RUN apt-get update && \ apt-get upgrade -y && \ apt-get install -y python3 RUN apt-get install -y python3-pip COPY requirements.txt /opt/ RUN pip3 install -r /opt/requirements.txt WORKDIR /opt CMD FLASK_APP=app FLASK_DEBUG=1 flask run --host 0.0.0.0 --port 5000
examples/python-pulsar/pulsar_demo.py
mport pulsar client = pulsar.Client('pulsar://localhost:6650') consumer = client.subscribe('my-topic', subscription_name='my-sub') # while True: # msg = consumer.receive() # print("Received message: '{}'".format(msg.data()) # consumer.acknowledge(msg) client.close()