Commit 447c76aa authored by Alexander Lercher's avatar Alexander Lercher

Rest Gateway: takes traces via REST, message to trace-retrieval

parent 5a50ca77
......@@ -13,7 +13,7 @@ class MessageSender:
_connection: pika.BlockingConnection = None
_channel: pika.channel.Channel = None
def __init__(self, rabbit_mq_ip='143.205.173.36', rabbit_mq_port=30302):
def __init__(self, rabbit_mq_ip='rabbit-mq', rabbit_mq_port=5672):
self._rabbit_mq_ip = rabbit_mq_ip
self._rabbit_mq_port = rabbit_mq_port
......
......@@ -39,4 +39,54 @@ paths:
description: "Lists all messages received from Rabbit MQ."
responses:
200:
description: "Message list"
\ No newline at end of file
description: "Message list"
/trace:
post:
operationId: "rest.blockchain_trace.receive"
tags:
- "Blockchain Trace"
summary: "Add a new blockchain trace to SMART"
description: "Receives a new blockchain trace to store in SMART."
parameters:
- in: body
name: "BlockchainTrace"
description: "The trace to be added"
required: true
schema:
$ref: "#/definitions/BlockchainTrace"
responses:
201:
description: "Successfully added"
400:
description: "Invalid input"
definitions:
BlockchainTrace:
type: "object"
properties:
TransactionId:
type: string
format: uuid
Timestamp:
type: "string"
format: "date-time"
ApplicationType:
type: "string"
TransactionFrom:
type: "string"
format: "uuid"
TransactionTo:
type: "string"
format: "uuid"
TransferredAsset:
type: "string"
ResourceIds:
type: "string"
ResourceMd5:
type: "string"
ResourceState:
type: "string"
Metadata:
type: "string"
\ No newline at end of file
......@@ -19,11 +19,12 @@ from messaging.MessageReceiver import MessageReceiver
from messaging.MessageSender import MessageSender
from MessageList import MessageList
RABBIT_MQ_DNS_NAME = 'rabbit-mq'
RABBIT_MQ_PORT = '5672'
messages = MessageList.getInstance()
message_sender = MessageSender()
message_sender.connect()
message_sender.create_exchange('inhub', 'direct')
# init message handler
def message_received_callback(channel, method, properties, body):
messages.appendMessage(body)
......@@ -44,9 +45,7 @@ def api_root():
# start app
if __name__ == '__main__':
message_rec = MessageReceiver(
rabbit_mq_ip=RABBIT_MQ_DNS_NAME, rabbit_mq_port=RABBIT_MQ_PORT,
exchange_name='rest-gateway', exchange_type='direct', queue_name='rest-gateway', auto_ack=True)
message_rec = MessageReceiver(exchange_name='rest-gateway', exchange_type='direct', queue_name='rest-gateway', auto_ack=True)
message_rec.start(message_received_callback, pika_error_callback)
app.run(host='0.0.0.0', port=5000, debug=True, use_reloader=False) # disable reloader so only subscribed once to rabbitmq
\ No newline at end of file
from flask import request, Response
import main
def receive():
body = request.json
if isBlockchainTraceValid(body):
message = {'type': 'blockchain-transaction', 'content': body}
main.message_sender.send('inhub', message, 'trace-retrieval')
return Response(status=201)
def isBlockchainTraceValid(trace) -> bool:
return 'TransactionId' in trace \
and 'Timestamp' in trace \
and 'ApplicationType' in trace \
and 'TransactionFrom' in trace \
and 'TransactionFromLatLng' in trace \
and 'TransactionTo' in trace \
and 'TransactionToLatLng' in trace \
and 'TransferredAsset' in trace \
and 'ResourceIds' in trace \
and 'ResourceMd5' in trace \
and 'ResourceState' in trace \
and 'Metadata' in trace
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment