I’ve tested out a way to capture service event
metrics.
Added the service_interupted
boolean to the service event handler
class:
class SubServiceEventHandler(
ReconnectionListener, ReconnectionAttemptListener, ServiceInterruptionListener
):
def __init__(self):
self.service_interrupted = False
def on_reconnected(self, e: ServiceEvent):
…
…
self.service_interrupted = False
def on_reconnecting(self, e: ServiceEvent):
…
…
self.service_interrupted = True
def on_service_interrupted(self, e: ServiceEvent):
…
…
self.service_interrupted = True
Add a function to check the value of the service_interupted
variable
A thread
to check the status every minute.
receiver.start()
# Set the message handler
message_handler = MyMessageHandler()
receiver.receive_async(message_handler)
# Function to check the service status every minute
def check_service_status():
while True:
if service_event_handler.service_interrupted:
print("Service is interrupted")
else:
print("Service is running normally")
time.sleep(60)
# Start a thread to check the service status every minute
status_thread = threading.Thread(target=check_service_status)
status_thread.daemon = True
status_thread.start()
To test this the Solace docker container has come in handy!
When working:
Publisher
Sent 'Hello, Solace! aANdP' to queue 'foo'
Message published
Sent 'Hello, Solace! DgNsT' to queue 'foo'
Message published
Subscriber
Received message: Hello, Solace! aANdP on queue foo
Service is running normally
Received message: Hello, Solace! DgNsT on queue foo
Service is running normally
When the docker container is stopped/started:
Subscriber
Received message: Hello, Solace! eHWRN on queue foo
2025-01-22 15:50:29,057 [WARNING] solace.messaging.core: [_solace_transport.py:89] [[SERVICE: 0x7f9c8b49ba60] - [APP ID: hq/656553/00000001/geywCErEZj]] {'caller_description': 'From service event callback', 'return_code': 'Ok', 'sub_code': 'SOLCLIENT_SUBCODE_COMMUNICATION_ERROR', 'error_info_sub_code': 14, 'error_info_contents': 'Peer closed socket, fd 8, cannot read'}
on_reconnecting
Attempting to reconnect. Error cause: {'caller_description': 'From service event callback', 'return_code': 'Ok', 'sub_code': 'SOLCLIENT_SUBCODE_COMMUNICATION_ERROR', 'error_info_sub_code': 14, 'error_info_contents': 'Peer closed socket, fd 8, cannot read'}
Message: Peer closed socket, fd 8, cannot read
Service is interrupted
Service is interrupted
Service is interrupted
2025-01-22 15:53:09,865 [WARNING] solace.messaging.core: [_solace_transport.py:89] [[SERVICE: 0x7f9c8b49ba60] - [APP ID: hq/656553/00000001/geywCErEZj]] {'caller_description': 'From service event callback', 'return_code': 'Ok', 'sub_code': 'SOLCLIENT_SUBCODE_COMMUNICATION_ERROR', 'error_info_sub_code': 14, 'error_info_contents': 'Peer closed socket, fd 8, cannot read'}
on_reconnected
Error cause: {'caller_description': 'From service event callback', 'return_code': 'Ok', 'sub_code': 'SOLCLIENT_SUBCODE_COMMUNICATION_ERROR', 'error_info_sub_code': 14, 'error_info_contents': 'Peer closed socket, fd 8, cannot read'}
Message: host 'tcp://localhost:55555', hostname 'localhost:55555' IP [::1]:55555 (host 1 of 1) (host connection attempt 1 of 1) (total reconnection attempt 1 of -1)
Service is running normally
Service is running normally
Received message: Hello, Solace! HIAQw on queue foo
While this has been fun to play around with it perhaps doesn’t add anything that monitoring the bind
count at the broker level?
Still can’t find the docs on the session/flow/active ?️
Cheers