Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SMART
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UNI-KLU
SMART
Commits
fde49aef
Commit
fde49aef
authored
Aug 19, 2019
by
Alexander Lercher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Trace Retrieval: restarting message_receiver; cleanup
parent
eaa08e45
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
45 additions
and
20 deletions
+45
-20
MongoRepository.py
tools/MongoRepository.py
+25
-0
swagger.yml
...b-in/trace-retrieval-microservice/app/configs/swagger.yml
+2
-2
MongoRepository.py
...in/trace-retrieval-microservice/app/db/MongoRepository.py
+0
-2
main.py
transaction-hub-in/trace-retrieval-microservice/app/main.py
+16
-14
MessageHandler.py
...ce-retrieval-microservice/app/messaging/MessageHandler.py
+2
-2
blockchain_trace.py
...trace-retrieval-microservice/app/rest/blockchain_trace.py
+0
-0
debug.py
...ion-hub-in/trace-retrieval-microservice/app/rest/debug.py
+0
-0
No files found.
tools/MongoRepository.py
0 → 100644
View file @
fde49aef
import
pymongo
MONGO_DB_HOST
=
'143.205.173.36'
MONGO_DB_PORT
=
'30003'
class
MongoRepository
:
# TODO extract to docker env var
_username
=
'root'
_password
=
'root'
_collection
:
pymongo
.
collection
.
Collection
=
None
def
__init__
(
self
,
username
=
_username
,
password
=
_password
):
myclient
=
pymongo
.
MongoClient
(
f
"mongodb://{username}:{password}@{MONGO_DB_HOST}:{MONGO_DB_PORT}/"
)
database
=
myclient
[
'traceRetrievalDB'
]
# trace retrieval
self
.
_collection
=
database
[
'traces'
]
def
insert_trace
(
self
,
content
:
dict
):
self
.
_collection
.
insert_one
(
content
)
def
get_traces
(
self
,
selection
:
dict
=
{}):
return
self
.
_collection
.
find
(
selection
)
traces
=
MongoRepository
()
.
get_traces
()
for
t
in
traces
:
print
(
str
(
t
))
\ No newline at end of file
transaction-hub-in/trace-retrieval-microservice/app/configs/swagger.yml
View file @
fde49aef
...
...
@@ -15,7 +15,7 @@ basePath: "/api"
paths
:
/debug
:
post
:
operationId
:
"
debug.echo"
operationId
:
"
rest.
debug.echo"
tags
:
-
"
Echo"
summary
:
"
Echo
function
for
debugging
purposes"
...
...
@@ -32,7 +32,7 @@ paths:
/trace
:
post
:
operationId
:
"
blockchain_trace.receive"
operationId
:
"
rest.
blockchain_trace.receive"
tags
:
-
"
Blockchain
Trace"
summary
:
"
Add
a
new
blockchain
trace
to
SMART"
...
...
transaction-hub-in/trace-retrieval-microservice/app/db/MongoRepository.py
View file @
fde49aef
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
...
...
transaction-hub-in/trace-retrieval-microservice/app/main.py
View file @
fde49aef
...
...
@@ -8,24 +8,31 @@ if os.path.exists(modules_path):
# init logging to file
import
logging
LOG_FORMAT
=
(
'
%(levelname) -5
s
%(asctime)
s
%(name)
s:
%(funcName) -35
s
%(lineno) -5
d:
%(message)
s'
)
logging
.
basicConfig
(
filename
=
'error.log'
,
level
=
logging
.
WARNING
,
format
=
LOG_FORMAT
)
logging
.
basicConfig
(
level
=
logging
.
INFO
,
format
=
LOG_FORMAT
)
LOGGER
=
logging
.
getLogger
(
__name__
)
#############################
import
connexion
from
messaging.MessageHandler
import
MessageHandler
from
messaging.MessageReceiver
import
MessageReceiver
from
messaging.MessageSender
import
MessageSender
RABBIT_MQ_DNS_NAME
=
'rabbit-mq'
RABBIT_MQ_PORT
=
'5672'
message_sender
=
None
message_rec
:
MessageReceiver
=
None
# init message handler
message_handler
=
MessageHandler
()
def
message_received_callback
(
channel
,
method
,
properties
,
body
):
message_handler
.
handle_message
(
body
)
message_sender
.
send
(
'rest-gateway'
,
str
(
body
)
+
' (sent from trace-retrieval-microservice)'
,
'rest-gateway'
)
LOGGER
.
info
(
f
"Received new message: {body}"
)
message_handler
.
handle_generic
(
body
)
def
pika_error_callback
(
error
):
LOGGER
.
warning
(
f
"RabbitMQ stopped with error: {error}"
)
# restart receiver
message_rec
.
stop
()
init_message_receiver
()
def
init_message_receiver
():
message_rec
=
MessageReceiver
(
exchange_name
=
'inhub'
,
exchange_type
=
'direct'
,
queue_name
=
'trace-retrieval'
,
auto_ack
=
True
)
message_rec
.
start
(
message_received_callback
,
pika_error_callback
)
# load swagger config
app
=
connexion
.
App
(
__name__
,
specification_dir
=
'configs/'
)
...
...
@@ -37,11 +44,6 @@ 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
=
'inhub'
,
exchange_type
=
'direct'
,
queue_name
=
'trace-retrieval'
,
auto_ack
=
True
)
message_rec
.
start
(
message_received_callback
)
message_sender
=
MessageSender
(
rabbit_mq_ip
=
RABBIT_MQ_DNS_NAME
,
rabbit_mq_port
=
RABBIT_MQ_PORT
)
message_sender
.
connect
()
message_sender
.
create_exchange
(
'rest-gateway'
,
'direct'
)
init_message_receiver
()
app
.
run
(
host
=
'0.0.0.0'
,
port
=
5000
,
debug
=
True
,
use_reloader
=
False
)
# disable reloader so only subscribed once to rabbitmq
transaction-hub-in/trace-retrieval-microservice/app/messaging/MessageHandler.py
View file @
fde49aef
...
...
@@ -10,11 +10,11 @@ class MessageHandler:
def
__init__
(
self
):
self
.
_mongo_repo
=
MongoRepository
()
def
handle_
message
(
self
,
body
):
def
handle_
generic
(
self
,
body
):
LOGGER
.
info
(
f
"Received message: {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
-> ignored
"
)
return
if
message
[
'type'
]
==
'blockchain-transaction'
:
...
...
transaction-hub-in/trace-retrieval-microservice/app/blockchain_trace.py
→
transaction-hub-in/trace-retrieval-microservice/app/
rest/
blockchain_trace.py
View file @
fde49aef
File moved
transaction-hub-in/trace-retrieval-microservice/app/debug.py
→
transaction-hub-in/trace-retrieval-microservice/app/
rest/
debug.py
View file @
fde49aef
File moved
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment