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
fd3515f4
Commit
fd3515f4
authored
Aug 20, 2019
by
Alexander Lercher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Trace Retrieval: More robust message handling
parent
fde49aef
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
7 deletions
+23
-7
MongoRepository.py
...in/trace-retrieval-microservice/app/db/MongoRepository.py
+10
-3
main.py
transaction-hub-in/trace-retrieval-microservice/app/main.py
+2
-1
MessageHandler.py
...ce-retrieval-microservice/app/messaging/MessageHandler.py
+9
-2
deployment.yml
...in/trace-retrieval-microservice/deployment/deployment.yml
+2
-1
No files found.
transaction-hub-in/trace-retrieval-microservice/app/db/MongoRepository.py
View file @
fd3515f4
...
...
@@ -7,11 +7,13 @@ class MongoRepository:
# TODO extract to docker env var
_username
=
'root'
_password
=
'root'
_collection
:
pymongo
.
collection
.
Collection
=
None
_collection
:
pymongo
.
collection
.
Collection
=
None
_mongo_client
:
pymongo
.
MongoClient
=
None
def
__init__
(
self
,
username
=
_username
,
password
=
_password
):
my
client
=
pymongo
.
MongoClient
(
f
"mongodb://{username}:{password}@{MONGO_DB_HOST}:{MONGO_DB_PORT}/"
)
database
=
myclient
[
'traceRetrievalDB'
]
# trace retrieval
self
.
_mongo_
client
=
pymongo
.
MongoClient
(
f
"mongodb://{username}:{password}@{MONGO_DB_HOST}:{MONGO_DB_PORT}/"
)
database
=
self
.
_mongo_client
[
'traceRetrievalDB'
]
self
.
_collection
=
database
[
'traces'
]
def
insert_trace
(
self
,
content
:
dict
):
...
...
@@ -19,3 +21,8 @@ class MongoRepository:
def
get_traces
(
self
,
selection
:
dict
=
{}):
return
self
.
_collection
.
find
(
selection
)
def
close_connection
(
self
):
self
.
_mongo_client
.
close
()
self
.
_collection
=
None
self
.
_mongo_client
=
None
transaction-hub-in/trace-retrieval-microservice/app/main.py
View file @
fd3515f4
...
...
@@ -21,16 +21,17 @@ message_rec: MessageReceiver = None
# init message handler
message_handler
=
MessageHandler
()
def
message_received_callback
(
channel
,
method
,
properties
,
body
):
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
global
message_rec
message_rec
.
stop
()
init_message_receiver
()
def
init_message_receiver
():
global
message_rec
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
)
...
...
transaction-hub-in/trace-retrieval-microservice/app/messaging/MessageHandler.py
View file @
fd3515f4
...
...
@@ -12,9 +12,16 @@ class MessageHandler:
def
handle_generic
(
self
,
body
):
LOGGER
.
info
(
f
"Received message: {body}"
)
message
=
json
.
loads
(
body
)
message
=
None
try
:
message
=
json
.
loads
(
body
)
except
ValueError
:
LOGGER
.
warning
(
f
"Message is not in JSON format and is ignored"
)
return
if
not
'type'
in
message
:
LOGGER
.
warning
(
f
"Message has no type field
->
ignored"
)
LOGGER
.
warning
(
f
"Message has no type field
and is
ignored"
)
return
if
message
[
'type'
]
==
'blockchain-transaction'
:
...
...
transaction-hub-in/trace-retrieval-microservice/deployment/deployment.yml
View file @
fd3515f4
...
...
@@ -20,7 +20,7 @@ kind: Deployment
metadata
:
name
:
trace-retrieval
spec
:
replicas
:
2
replicas
:
1
selector
:
matchLabels
:
app
:
trace-retrieval
...
...
@@ -34,6 +34,7 @@ spec:
image
:
172.16.1.20:5000/trace-retrieval-microservice
ports
:
-
containerPort
:
5000
imagePullPolicy
:
Always
---
apiVersion
:
v1
kind
:
Service
...
...
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