This module can be used for listening to the messages from aws sqs.
- install module
pip install py-message-listener
Follow bellow steps for using this module
- Add
@Listenerdecorator to method or function where do you want to receive the message, for that method/function add single parameter, This parameter is set whenever the message is received and method will be called and message will be passed as argument. - In decorator pass queue name in
destinationargument - set these environment variables:
AWS_REGION,AWS_ACCOUNT_ID,AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEY - Added kwargs for configuring listener
visibility_timeout,wait_time_secondsandmax_number_of_messages poll_after_secondsthis argument specify how much time to wait before requesting for the messagesdelete_on_exceptionthis argument specifies , whether to delete the message if any exception occurs while processing the message- To delete the message return
Truefrom the message processing method
AWS_ACCOUNT_IDthis will be used for generating the queue url
from listener import Listener
@Listener(destination='test.fifo')
def fun(msg: str):
print(msg)
return True