Skip to content

Wiring for NewTopic collections #1725

@StephenFlavin

Description

@StephenFlavin

I've recently started playing around with spring-kafka and I like it so far however I was trying to make use of the programmatic creation of new topics when I hit a blocker.
I was hoping to have an app basically verify a bunch of topics are configured and then produce (or consume) to them but to have those topics be something that's passed in as an environment variable e.g.

    @Bean
    public List<NewTopic> topics(@Value("${ENVIRONMENT.topics:topicA,topicB,topicC}") List<String> topics) {
        return topics.stream()
                .map(this::toTopic)
                .collect(Collectors.toList());
    }

    private NewTopic toTopic(String topic) {
        return TopicBuilder.name(topic)
                .partitions(16)
                .replicas(2)
                .build();
    }

Apologies if there is an existing better way to do what I describe, best I've found as a workaround is to write the code using the org.apache.kafka.clients.admin.AdminClient.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions