Commit eaa08e45 authored by Alexander Lercher's avatar Alexander Lercher

Rest Gateway / Trace Retrieval: fixed communication

parent 140ea8d9
......@@ -76,9 +76,13 @@ definitions:
TransactionFrom:
type: "string"
format: "uuid"
TransactionFromLatLng:
type: "string"
TransactionTo:
type: "string"
format: "uuid"
TransactionToLatLng:
type: "string"
TransferredAsset:
type: "string"
ResourceIds:
......
......@@ -21,10 +21,6 @@ from MessageList import MessageList
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)
......
from flask import request, Response
import main
from messaging.MessageSender import MessageSender
import json
# import main
message_sender = MessageSender()
message_sender.connect()
message_sender.create_exchange('inhub', 'direct')
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)
message = {'type': 'blockchain-transaction', 'content': json.dumps(body)}
message_sender.send('inhub', json.dumps(message), 'trace-retrieval')
return Response(status=201)
return Response(status=400)
def isBlockchainTraceValid(trace) -> bool:
return 'TransactionId' in trace \
......
import pymongo
MONGO_DB_HOST = 'trace-retrieval-db'
# MONGO_DB_HOST = '143.205.173.36'
MONGO_DB_PORT = '27017'
# MONGO_DB_PORT = '30003'
class MongoRepository:
# TODO extract to docker env var
......
from db.MongoRepository import MongoRepository
import json
import logging
LOGGER = logging.getLogger(__name__)
......@@ -11,12 +12,13 @@ class MessageHandler:
def handle_message(self, body):
LOGGER.info(f"Received message: {body}")
if not 'type' in body:
message = json.loads(body)
if not 'type' in message:
LOGGER.warning(f"Message has no type field")
return
if body['type'] == 'blockchain-transaction':
self.handle_blockchain_transaction(body['content'])
if message['type'] == 'blockchain-transaction':
self.handle_blockchain_transaction(json.loads(message['content']))
def handle_blockchain_transaction(self, transaction):
self._mongo_repo.insert_trace(transaction)
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