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
4cda6e98
Commit
4cda6e98
authored
Jan 19, 2021
by
Luca Braun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implemented publisher side message confirmation
parent
bd115b86
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
4 deletions
+26
-4
MessageManager.py
src/modules/messaging/MessageManager.py
+15
-3
ReconnectingMessageManager.py
src/modules/messaging/ReconnectingMessageManager.py
+10
-0
blockchain_trace.py
src/rest-gateway/app/routes/blockchain_trace.py
+1
-1
No files found.
src/modules/messaging/MessageManager.py
View file @
4cda6e98
import
pika
from
pika
import
spec
from
threading
import
Thread
import
network_constants
as
netconst
...
...
@@ -47,10 +48,18 @@ class MessageManager:
if
self
.
_error_callback
!=
None
:
self
.
_error_callback
(
"Connection closed"
)
def
_message_confirmed_callback
(
self
,
frame
):
if
isinstance
(
frame
.
method
,
spec
.
Basic
.
Ack
):
LOGGER
.
debug
(
"message acknowledged"
)
return
else
:
LOGGER
.
warning
(
"Message was rejected by broker!"
)
def
_channel_created_callback
(
self
,
channel
:
pika
.
channel
.
Channel
):
# Assign both channels
if
self
.
_send_channel
==
None
:
self
.
_send_channel
=
channel
self
.
_send_channel
.
confirm_delivery
(
ack_nack_callback
=
self
.
_message_confirmed_callback
)
else
:
self
.
_receive_channel
=
channel
LOGGER
.
info
(
"RabbitMQ connection established"
)
...
...
@@ -91,8 +100,11 @@ class MessageManager:
def
send_message
(
self
,
exchange_name
,
routing_key
,
message
):
'''Sends a message to the exchange'''
self
.
_send_channel
.
basic_publish
(
exchange_name
,
routing_key
,
message
)
try
:
self
.
_send_channel
.
basic_publish
(
exchange_name
,
routing_key
,
message
,
mandatory
=
True
)
except
pika
.
exceptions
.
UnroutableError
:
raise
pika
.
exceptions
.
UnroutableError
def
disconnect
(
self
):
'''Stops listening for messages and closes the connection'''
try
:
...
...
@@ -100,4 +112,4 @@ class MessageManager:
self
.
_connection
.
close
()
LOGGER
.
info
(
"RabbitMQ connection closed"
)
except
pika
.
exceptions
.
ConnectionWrongStateError
:
LOGGER
.
warning
(
"RabbitMQ connection already closed"
)
LOGGER
.
warning
(
"RabbitMQ connection already closed"
)
\ No newline at end of file
src/modules/messaging/ReconnectingMessageManager.py
View file @
4cda6e98
...
...
@@ -3,6 +3,8 @@ import time
from
messaging.MessageManager
import
MessageManager
import
logging
import
json
import
pika
LOGGER
=
logging
.
getLogger
(
__name__
)
class
ReconnectingMessageManager
:
...
...
@@ -91,5 +93,13 @@ class ReconnectingMessageManager:
'''Sends a message to the exchange'''
try
:
self
.
_message_manager
.
send_message
(
exchange_name
,
routing_key
,
message
)
except
pika
.
exceptions
.
UnroutableError
:
message
=
json
.
loads
(
message
)
if
message
[
"retries"
]
<
10
:
message
[
"retries"
]
+=
1
message
=
json
.
dumps
(
message
)
self
.
send_message
(
exchange_name
,
routing_key
,
message
)
else
:
LOGGER
.
error
(
"Message went through too many send retries and was not delivered"
)
except
:
LOGGER
.
error
(
"Error while sending message"
)
src/rest-gateway/app/routes/blockchain_trace.py
View file @
4cda6e98
...
...
@@ -9,7 +9,7 @@ def receive():
body
=
request
.
json
if
isBlockchainTraceValid
(
body
):
message
=
{
'type'
:
'blockchain-transaction'
,
'content'
:
body
}
message
=
{
'type'
:
'blockchain-transaction'
,
'
retries'
:
0
,
'
content'
:
body
}
message_sender
.
send_message
(
'inhub'
,
'trace-retrieval'
,
json
.
dumps
(
message
))
return
Response
(
status
=
201
)
...
...
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