MCPcopy Create free account
hub / github.com/N4si/microservices-python-app / main

Function main

src/converter-service/consumer.py:6–33  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4from convert import to_mp3
5
6def main():
7 client = MongoClient(os.environ.get('MONGODB_URI'))
8 db_videos = client.videos
9 db_mp3s = client.mp3s
10 # gridfs
11 fs_videos = gridfs.GridFS(db_videos)
12 fs_mp3s = gridfs.GridFS(db_mp3s)
13
14 # rabbitmq connection
15 connection = pika.BlockingConnection(
16 pika.ConnectionParameters(host='rabbitmq',heartbeat=0)
17 )
18 channel = connection.channel()
19
20 def callback(ch, method, properties, body):
21 err = to_mp3.start(body, fs_videos, fs_mp3s, ch)
22 if err:
23 ch.basic_nack(delivery_tag=method.delivery_tag)
24 else:
25 ch.basic_ack(delivery_tag=method.delivery_tag)
26
27 channel.basic_consume(
28 queue=os.environ.get("VIDEO_QUEUE"), on_message_callback=callback
29 )
30
31 print("Waitting for messages, to exit press CTRL+C")
32
33 channel.start_consuming()
34
35if __name__ == "__main__":
36 try:

Callers 1

consumer.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected