To Commit or accept a message before executing your business logic you need to expilicitly acknowledge the message to the broker .
Exemple: ( Kafka, RabbitaMQ )
Before you run you code.
However this approach is not recommended in most systems.
if your code fails after the message is acknowledge ,the message lost and wont be reprocessed.
it breaks message reliability and fault tolerance.
in most cases , the best pratic is to:
Cousume the message
Process your logic, and them
Acknowledge the message only after sucessfull excution.
Why is risky : If you acknowledge commit the message first , and your code afterward, you will lose the message -because the broker thinks it was handle sucessfully.