GithubHelp home page GithubHelp logo

Comments (3)

Lancetnik avatar Lancetnik commented on June 1, 2024 1

@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.

Lancetnik avatar Lancetnik commented on June 1, 2024 1

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.

shouldsee avatar shouldsee commented on June 1, 2024

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)

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.