Coder Social home page Coder Social logo

Comments (4)

trentbitterman avatar trentbitterman commented on September 25, 2024 2

@davidhuser I had the same problem as you, but I realized I never called the admin_client.start method. Once I added that to my context manager function it started working. Hopefully that helps you too.

@asynccontextmanager
async def get_admin_client():
    admin_client = AIOKafkaAdminClient(
        bootstrap_servers=settings.KAFKA_BOOTSTRAP_SERVERS
    )
    try:
        await admin_client.start()
        yield admin_client
    finally:
        await admin_client.close()

from aiokafka.

davidhuser avatar davidhuser commented on September 25, 2024 1

works now, thanks @trentbitterman !

from aiokafka.

ods avatar ods commented on September 25, 2024

AIOKafkaAdminClient must be bootstrapped before use, the preferred way is

async with AIOKafkaAdminClient(...) as client:
    ...

from aiokafka.

davidhuser avatar davidhuser commented on September 25, 2024

I have the same issue as OP. If I use the suggested context manager I get

TypeError: 'AIOKafkaAdminClient' object does not support the asynchronous context manager protocol

so I wrap it into a asynccontextmanager:

from contextlib import asynccontextmanager
from aiokafka.admin import AIOKafkaAdminClient, NewTopic

@asynccontextmanager
async def get_admin_client():
    admin_client = AIOKafkaAdminClient(
        bootstrap_servers=settings.KAFKA_BOOTSTRAP_SERVERS
    )
    try:
        yield admin_client
    finally:
        await admin_client.close()


async def create_topic():
    async with get_admin_client() as admin_client:
        try:
            await admin_client.create_topics(
                [
                    NewTopic(
                        name='mytopic',
                        num_partitions=1,
                        replication_factor=1,
                    )
                ]
            )
        except Exception as e:
            print("oh no")

Still get the error as OP:

2024-07-16 15:34:23.329 | ERROR    | kafka_utils:create_topic:70 - Failed to create topic 'costs': IncompatibleBrokerVersion: Kafka broker does not support the 'CreateTopicsRequest_v0' Kafka protocol.

How can we create topics with aiokafka?


Version 0.11.0

from aiokafka.

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.