Comments (3)
@shouldsee, hi there! Thanks for you kind feedback
Unfotunatelly, I can't support all serialization libraries, but you have a way to integrate your custom one
Just use the decode_message
argument
from marshmallow import Schema, fields
from propan import RabbitBroker
from propan.brokers.rabbit import RabbitMessage
from propan.annotations import Logger
broker = RabbitBroker()
app = PropanApp(broker)
class User(Schema):
name = fields.Str()
async def decode(msg: RabbitMessage, original):
return User().loads(msg.body)
@broker.handle("test", decode_message=decode_marshmallow)
async def handle(msg, logger: Logger):
logger.info(msg)
Or you can scale this code to any Schema via a closure
from marshmallow import Schema, fields
from propan import PropanApp, RabbitBroker
from propan.brokers.rabbit import RabbitMessage
from propan.annotations import Logger
broker = RabbitBroker()
app = PropanApp(broker)
class User(Schema):
name = fields.Str()
def decode_marshmallow(schema: Schema):
async def decode(msg: RabbitMessage, original):
return schema.loads(msg.body)
return decode
@broker.handle("test", decode_message=decode_marshmallow(User()))
async def handle(msg, logger: Logger):
logger.info(msg)
@app.after_startup
async def test():
await broker.publish({
"name": "john"
}, "test")
from propan.
I am using pydantic '.json_schema()' to get information about payloads
Other staff is generated by Propan: servers information, channels, bindings, etc
BTW, I will add an ability to set schema manually in custom serialization case in the PropanV2
from propan.
Many thanks! BTW may I ask how the api documentation is generated from pydantic models? My main objective is to auto-generate api doc....
from propan.
Related Issues (20)
- RabbitQueue as a parameter for a router handle HOT 5
- Generator-based dependency functions fail with Propan HOT 4
- Split FastAPI tests
- weird package imports HOT 1
- Separate dev distributions to different requirements files
- Update CI to use required dependencies versions
- Fix all mkdocs inner links warnings
- Bug: propan run chokes on relative imports in the main script HOT 3
- Refactor project templates HOT 2
- [Question] - How check worker run without errors HOT 11
- Feature/Question: consume a batch of messages HOT 3
- Bug: Pydantic v1 'RabbitQueue' object has no attribute 'routing_key' HOT 2
- Bug: SQSBroker not consuming when Queue is empty on startup. HOT 2
- BrokerRouter can't be called with `build_message` in tests
- 0.1.6.0 ZeroMQ (Brokerless Messaging)
- Implement an Exception to stop consuming from handler
- Scheduling Docs page
- Add `New feature` Issue template
- Relative imports and non-root import paths crash the app HOT 8
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 propan.