Commit eaa08e45 authored by Alexander Lercher's avatar Alexander Lercher

Rest Gateway / Trace Retrieval: fixed communication

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