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
6d186827
Commit
6d186827
authored
Aug 05, 2021
by
Manuel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[reputation, semantic-linking] added MQ communication
parent
03f0f4a7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
16 deletions
+42
-16
message_handler.py
...calculation-microservice/app/lib/trust/message_handler.py
+20
-14
main.py
src/data-hub/reputation-calculation-microservice/app/main.py
+19
-1
MessageHandler.py
...ce-retrieval-microservice/app/messaging/MessageHandler.py
+3
-1
No files found.
src/data-hub/reputation-calculation-microservice/app/lib/trust/message_handler.py
View file @
6d186827
...
@@ -13,23 +13,29 @@ class MessageHandler:
...
@@ -13,23 +13,29 @@ class MessageHandler:
self
.
user_trust_repository
=
user_trust_repository
self
.
user_trust_repository
=
user_trust_repository
self
.
trust_trace_repository
=
trust_trace_repository
self
.
trust_trace_repository
=
trust_trace_repository
def
handle
(
self
,
body
:
str
):
def
handle_generic
(
self
,
body
:
str
):
# decode the message
LOGGER
.
info
(
f
"Received message: {body}"
)
data
:
Dict
=
None
try
:
data
=
json
.
loads
(
body
)
except
json
.
decoder
.
JSONDecodeError
:
raise
ValueError
(
"Invalid Message: Not in JSON format"
)
if
"type"
not
in
data
.
keys
()
or
"content"
not
in
data
.
keys
():
raise
ValueError
(
"Invalid Message: Missing fields
\"
type
\"
or
\"
content
\"
"
)
if
data
[
"type"
]
!=
"new-trace"
:
message
=
None
try
:
message
=
json
.
loads
(
body
)
except
ValueError
:
LOGGER
.
warning
(
"Message is not in JSON format and is ignored"
)
return
return
content
:
Dict
=
data
[
"content"
]
if
not
'type'
in
message
:
LOGGER
.
warning
(
"Message has no type field and is ignored"
)
return
if
message
[
'type'
]
==
'new-trace'
:
self
.
handle
(
message
)
elif
message
[
'type'
]
==
'new-traces-available'
:
self
.
handle_new_traces_available
()
else
:
LOGGER
.
info
(
"Message Type could not be processed"
)
def
handle
(
self
,
content
:
Dict
):
# decode the message
if
"use_case"
not
in
content
.
keys
()
or
"table"
not
in
content
.
keys
()
or
"properties"
not
in
content
.
keys
():
if
"use_case"
not
in
content
.
keys
()
or
"table"
not
in
content
.
keys
()
or
"properties"
not
in
content
.
keys
():
raise
ValueError
(
raise
ValueError
(
"Invalid Message: Missing fields
\"
use_case
\"
or
\"
table
\"
or
\"
properties
\"
"
)
"Invalid Message: Missing fields
\"
use_case
\"
or
\"
table
\"
or
\"
properties
\"
"
)
...
...
src/data-hub/reputation-calculation-microservice/app/main.py
View file @
6d186827
# add modules folder to interpreter path
# add modules folder to interpreter path
from
lib.trust.message_handler
import
MessageHandler
import
sys
import
sys
import
os
import
os
from
pathlib
import
Path
from
pathlib
import
Path
...
@@ -18,6 +19,7 @@ import connexion
...
@@ -18,6 +19,7 @@ import connexion
from
security
import
swagger_util
from
security
import
swagger_util
from
pathlib
import
Path
from
pathlib
import
Path
import
env_info
import
env_info
from
messaging.ReconnectingMessageManager
import
ReconnectingMessageManager
from
flask
import
request
from
flask
import
request
from
flask
import
redirect
from
flask
import
redirect
...
@@ -47,7 +49,23 @@ else:
...
@@ -47,7 +49,23 @@ else:
app
.
add_api
(
swagger_util
.
get_bundled_specs
(
Path
(
swagger_path
)),
app
.
add_api
(
swagger_util
.
get_bundled_specs
(
Path
(
swagger_path
)),
resolver
=
connexion
.
RestyResolver
(
"cms_rest_api"
))
resolver
=
connexion
.
RestyResolver
(
"cms_rest_api"
))
from
lib.database.repositories.trust_adapter_repository
import
TrustAdapterRepository
from
lib.database.repositories.trust_trace_repository
import
TrustTraceRepository
from
lib.database.repositories.user_repository
import
UserRepository
from
lib.database.repositories.user_trust_repository
import
UserTrustRepository
message_handler
:
MessageHandler
=
MessageHandler
(
trust_adapter_repository
=
TrustAdapterRepository
(),
trust_trace_repository
=
TrustTraceRepository
(),
user_repository
=
UserRepository
(),
user_trust_repository
=
UserTrustRepository
()
)
def
message_received_callback
(
channel
,
method
,
properties
,
body
):
message_handler
.
handle_generic
(
body
)
# start app
# start app
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
app
.
run
(
host
=
'0.0.0.0'
,
port
=
5000
,
ssl_context
=
context
)
#, debug=True)
message_manager
=
ReconnectingMessageManager
.
getInstance
()
\ No newline at end of file
message_manager
.
start_consuming
(
'datahub'
,
'direct'
,
'reputation-calculation'
,
True
,
message_received_callback
)
app
.
run
(
host
=
'0.0.0.0'
,
port
=
5000
,
ssl_context
=
context
)
\ No newline at end of file
src/transaction-hub-in/trace-retrieval-microservice/app/messaging/MessageHandler.py
View file @
6d186827
...
@@ -70,7 +70,6 @@ class MessageHandler:
...
@@ -70,7 +70,6 @@ class MessageHandler:
mappings - Required: contains string->path mappings, describing how the flattened object is built
mappings - Required: contains string->path mappings, describing how the flattened object is built
'''
'''
print
(
"yey new trace ^.^"
)
flattened
=
{}
flattened
=
{}
# iterate over schema mappings and resolve paths
# iterate over schema mappings and resolve paths
...
@@ -245,3 +244,6 @@ class MessageHandler:
...
@@ -245,3 +244,6 @@ class MessageHandler:
# inform semantic linking microservice
# inform semantic linking microservice
self
.
_message_sender
.
send_message
(
self
.
_message_sender
.
send_message
(
'datahub'
,
'semantic-linking'
,
msg_string
)
'datahub'
,
'semantic-linking'
,
msg_string
)
# inform reputation-calculation microservice
self
.
_message_sender
.
send_message
(
'datahub'
,
'reputation-calculation'
,
msg_string
)
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