stomp

What is stomp.py on_before_message method used for?


I am using the Class - PrintingListener from stomp.py, and it has the method: on_before_message.

I am not sure why this method is called. I cannot understand the definition. Could someone clarify the use of this method and when it is called?


Solution

  • According to the stomp.py documentation, the PrintingListener "just prints all interactions between the client and server." The on_before_message is one of the methods defined by stomp.py therefore the PrintingListener invokes it.

    The stomp.py API documentation says this about on_before_message:

    Called by the STOMP connection before a message is returned to the client app. Returns a tuple containing the headers and body (so that implementing listeners can pre-process the content).

    Parameters:

    • headers (dict) – the message headers
    • body – the message body

    As stated here, on_before_message is invoked "so that implementing listeners can pre-process the content." If you don't need to pre-process the content of the message (i.e. the headers or the body) then you can ignore this method.

    As the name indicates on_before_message is invoked immediately before on_message.