init project
This commit is contained in:
53
reciever/app.py
Normal file
53
reciever/app.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import pika
|
||||
from flask import Flask, jsonify, request
|
||||
import json
|
||||
import time
|
||||
import threading
|
||||
|
||||
app = Flask(__name__)
|
||||
exch = 'mobilon'
|
||||
server = 'rabbitmq'
|
||||
r_user = 'rabbit'
|
||||
r_pass = 'mrl2X0jwnYuCCiKFTshG7WKyOAhfDo'
|
||||
|
||||
|
||||
class RMQ(object):
|
||||
def __init__(self) -> None:
|
||||
self.connection = pika.BlockingConnection(pika.ConnectionParameters(
|
||||
'rabbitmq', 5672, 'mkt', pika.PlainCredentials('rabbit', 'mrl2X0jwnYuCCiKFTshG7WKyOAhfDo')))
|
||||
self.channel = self.connection.channel()
|
||||
self.channel.exchange_declare(
|
||||
exchange='mobilion', exchange_type='fanout')
|
||||
result = self.channel.queue_declare(queue='incoming')
|
||||
self.channel.queue_bind(exchange='mobilion', queue=result.method.queue)
|
||||
|
||||
def call(self, n):
|
||||
self.response = None
|
||||
self.channel.basic_publish(
|
||||
exchange='mobilion', routing_key='', body=str(n))
|
||||
self.channel.close()
|
||||
self.connection.close()
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def default():
|
||||
return ("Ok")
|
||||
|
||||
|
||||
@app.route("/api/call/add/", methods=["POST"])
|
||||
def rm():
|
||||
try:
|
||||
d: dict = request.get_json(True)
|
||||
s: str = json.dumps(d).encode('utf8', errors="ignore")
|
||||
rp = RMQ()
|
||||
threading.Thread(target=rp.call(str(d),)).start()
|
||||
except Exception as e:
|
||||
app.logger.error(e)
|
||||
finally:
|
||||
return ("Ok")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.debug = False
|
||||
app.run(host="0.0.0.0", port=5000)
|
||||
app.run(port=5000)
|
||||
14
reciever/dockerfile
Normal file
14
reciever/dockerfile
Normal file
@@ -0,0 +1,14 @@
|
||||
FROM alpine
|
||||
|
||||
RUN apk update && apk upgrade && apk add python3 && apk add -U tzdata
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY requirements.txt requirements.txt
|
||||
ADD app.py /app
|
||||
RUN python3 -m venv .venv
|
||||
RUN /app/.venv/bin/pip3 install -r /app/requirements.txt
|
||||
|
||||
EXPOSE 5000
|
||||
|
||||
CMD [".venv/bin/python3", "app.py"]
|
||||
8
reciever/phone.code-workspace
Normal file
8
reciever/phone.code-workspace
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": ".."
|
||||
}
|
||||
],
|
||||
"settings": {}
|
||||
}
|
||||
9
reciever/requirements.txt
Normal file
9
reciever/requirements.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
click==8.1.3
|
||||
Flask==2.2.3
|
||||
importlib-metadata==6.1.0
|
||||
itsdangerous==2.1.2
|
||||
Jinja2==3.1.2
|
||||
MarkupSafe==2.1.2
|
||||
pika==1.3.1
|
||||
Werkzeug==2.2.3
|
||||
zipp==3.15.0
|
||||
Reference in New Issue
Block a user