GithubHelp home page GithubHelp logo

Error consuming sqs messages about loafer HOT 4 CLOSED

d3btech avatar d3btech commented on June 15, 2024
Error consuming sqs messages

from loafer.

Comments (4)

lamenezes avatar lamenezes commented on June 15, 2024

@debjitk can you provide more information about the following error? e.g. what was the message? the source code of the handler? etc.

from loafer.

d3btech avatar d3btech commented on June 15, 2024

handlers.py

`#!/usr/bin/env python

import asyncio
from loafer.ext.aws.handlers import SQSHandler

"""
MessageHandler class
"""

class MessageHandler(SQSHandler):
def init(self):
pass

async def handle(self, message, *metadata):
    print("Message received\n")
    # print('message id is {}\n'.format(message["MessageId"]))
    # print('message body is {}\n'.format(message["Body"]))
    # print('args is {}\n\n'.format(args))

    # mimic IO processing
    await asyncio.sleep(0.1)
    return True

"""
ErrorHandler class
"""

class ErrorHandler:
def init(self):
pass

async def handle(self, err, message):
    print('exception {} received\n'.format(err))
    # do not delete the message that originated the error
    return False

`

routes.py

`#!/usr/bin/env python

from loafer.ext.aws.routes import SQSRoute
from handlers import MessageHandler, ErrorHandler

"""
Routes
"""

class Route(SQSRoute):
def init(self):
super(Route, self).init('queue-test', {'options': {'WaitTimeSeconds': 3}},
handler=MessageHandler(),
error_handler=ErrorHandler().handle, )
`

main.py

`#!/usr/bin/env python3

from loafer.managers import LoaferManager
from routes import Route

"""
Main
"""
if name == "main":
manager = LoaferManager(routes=Route())
manager.run(forever=True)
`

from loafer.

georgeyk avatar georgeyk commented on June 15, 2024

hey @debjitk,

In your Route definition, add something like:

from loafer.message_translators import StringMessageTranslator

[...]
super(Route, self).init('queue-test', {'options': {'WaitTimeSeconds': 3}},
handler=MessageHandler(),
error_handler=ErrorHandler().handle, 
message_translator=StringMessageTranslator(),
)
[...]

By default it expects the Body content to be a valid json string.
Also, I would suggest not to inherit fromSQSHandler unless you really need it.

~ ✌️

from loafer.

georgeyk avatar georgeyk commented on June 15, 2024

I'll close this issue, but feel free to reopen it if the suggestion failed in any way.

from loafer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.