Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avro #22

Open
aeldaly-tc opened this issue Oct 20, 2020 · 1 comment
Open

Avro #22

aeldaly-tc opened this issue Oct 20, 2020 · 1 comment

Comments

@aeldaly-tc
Copy link

Hello. Thanks so much for this nice project.

I was wondering what's the best way to use avro with this project?

Here's what I did:

async def produce_to_kafka_connect(params: CreateSearchParams):
    system_name = params.system_name
    topic = KafkaTopicsEnum.find_by_system_name(system_name)
    data = CreateSearchDocumentSchema.parse_obj(params.dict()).to_avro()

    await KAFKA_APP.publish(topic.value, data=data)
from typing import Any, Dict, List

from avro.schema import Schema, parse

from .model import BaseModel


class SchemaField(BaseModel):
    name: str
    type: Any


class BaseSchema(BaseModel):
    namespace: str = "ss.message_type.avro"
    type = "record"

    name: str
    fields_list: List[SchemaField]

    def json(
        self, *args: List[Any], **kwargs: Dict[str, Any]
    ):  # pyright: reportIncompatibleMethodOverride=false
        return super().json(*args, **kwargs).replace("fields_list", "fields")

    def to_avro(self) -> Schema:
        return parse(self.json())

the problem is publish assumes that data is a Pydantic model

    async def publish(
        self, stream_id: str, data: BaseModel, key: Optional[bytes] = None
    ) -> Awaitable[aiokafka.structs.ConsumerRecord]:
        if not self._intialized:
            async with self.get_lock("_"):
                await self.initialize()

        schema_key = getattr(data, "__key__", None)

Any suggestions on what we can do here?

@vangheem
Copy link
Contributor

The project does not support avro. It might be interesting to provide support for it though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants