Refactored code that sends the message in a function that can be used by other consumers