-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
53 lines (31 loc) · 881 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from fastapi import FastAPI
from controllers import all_logs, new_log
import json
import asyncio
import aio_pika
from consumer import on_message
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI()
origins = ["*"]
methods = ["GET", "POST", "PUT", "DELETE"]
headers = ["*"]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_methods=methods,
allow_headers=headers,
)
@app.on_event('startup')
async def startup():
loop = asyncio.get_event_loop()
connection = await aio_pika.connect("amqp://guest:guest@localhost/", loop = loop)
channel = await connection.channel()
queue = await channel.declare_queue("logs")
await queue.consume(on_message, no_ack=True)
@app.get("/logs")
async def receiver():
logs = all_logs()
return logs
@app.get("/")
async def hello():
return "hello"