Comments (4)
@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.
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.
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.
I'll close this issue, but feel free to reopen it if the suggestion failed in any way.
from loafer.
Related Issues (20)
- Check usage of .env files from prettyconf HOT 1
- Add meta attributes to message handler
- Add retrying feature HOT 1
- Support error handlers
- use internal asyncio.Queue
- enable parametrized credentials
- parametrize max_workers in LoaferManager HOT 1
- Enable creation of multiple instances of the same route/handler
- concurrent and multithreaded HOT 1
- Provide HTTP factories
- Refactor message translations
- Route switcher flag HOT 1
- circleci 2 + tox + pyenv HOT 1
- Are you still very experimental? HOT 1
- loafer stops unexpectedly the receive of the poll of messages after time
- The library does not work with aiobotocore v0.12.0 HOT 4
- Support sentry_sdk HOT 4
- Support for aiobotocore >= 1.0.0 HOT 1
- with await lock Deprecation on python 3.7 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from loafer.