Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- version: '3'
- services:
- appone:
- container_name: appone
- restart: always
- build:
- context: ./appone
- dockerfile: Dockerfile
- environment:
- FLASK_APP: ./app.py
- volumes:
- - './appone:/code/:cached'
- ports:
- - "5001:5001"
- apptwo:
- container_name: apptwo
- restart: always
- build:
- context: ./apptwo
- dockerfile: Dockerfile
- environment:
- FLASK_DEBUG: 1
- FLASK_APP: ./app.py
- volumes:
- - ./apptwo:/code:cached
- ports:
- - "5002:5002"
- rabbitmq:
- image: "rabbitmq:3-management"
- hostname: "rabbit"
- ports:
- - "15672:15672"
- - "5672:5672"
- labels:
- NAME: "rabbitmq"
- volumes:
- - ./rabbitmq/rabbitmq-isolated.conf:/etc/rabbitmq/rabbitmq.config
- from flask import Flask
- from flask_restful import Resource, Api
- import pika
- app = Flask(__name__)
- api = Api(app)
- app.config['DEBUG'] = True
- message = "Hello World, its me appone"
- class HelloWorld(Resource):
- def get(self):
- connection = pika.BlockingConnection(
- pika.ConnectionParameters(host='rabbitmq'))
- channel = connection.channel()
- channel.queue_declare(queue='hello', durable=True)
- channel.basic_publish(exchange='', routing_key='hello', body='Hello World!', properties=pika.BasicProperties(delivery_mode=2))
- connection.close()
- return {'message': message}
- api.add_resource(HelloWorld, '/api/appone/post')
- if __name__ == '__main__':
- # Development
- app.run(host="0.0.0.0", port=5001)
- from flask import Flask
- from flask_restful import Resource, Api
- import pika
- from threading import Thread
- app = Flask(__name__)
- api = Api(app)
- app.config['DEBUG'] = True
- data = []
- connection = pika.BlockingConnection(
- pika.ConnectionParameters(host='rabbitmq'))
- channel = connection.channel()
- channel.queue_declare(queue='hello', durable=True)
- def callback(ch, method, properties, body):
- data.append(body)
- ch.basic_ack(delivery_tag = method.delivery_tag)
- channel.basic_consume(queue='hello', on_message_callback=callback)
- thread = Thread(channel.start_consuming())
- thread.start()
- class HelloWorld(Resource):
- def get(self):
- return {'message': data}
- api.add_resource(HelloWorld, '/api/apptwo/get')
- if __name__ == '__main__':
- app.run(debug=True, host="0.0.0.0", port=5002)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement