Skip to content

Spring boot auto-configure transaction id prefix #11067

@nklmish

Description

@nklmish

As per docs, we need to provide transactionIdPrefix in order to enable transaction support. It will be nice if we can add a field like transactionIdPrefix in Producer and use it in DefaultKafkaProducerFactory to support properties based configuration like spring.kafka.producer.transaction-id-prefix in application.properties .
Current Situation:
ATM, we have to manually create a bean just to enable the transaction support. E.g. (the code below is in Kotlin, but we have to do the same thing in Java)

    @Bean
    fun kafkaProducerFactory(properties : KafkaProperties): ProducerFactory<*, *> {
        val defaultKafkaProducerFactory = DefaultKafkaProducerFactory<Any, Any>(properties.buildProducerProperties())
        defaultKafkaProducerFactory.setTransactionIdPrefix("txn-ingestor") // transaction-id can be application name or something in that line
        return defaultKafkaProducerFactory
    }

    @Bean
    fun transactionManager(producerFactory : ProducerFactory<*, *>) : KafkaTransactionManager<*, *> {
        return KafkaTransactionManager(producerFactory)
    }

I am using:
Spring-KafkaVersion 2.0.1.RELEASE
SpringBootVersion 2.0.0.M6

If it sounds good than I can submit a PR, more details here spring-kafka-482

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: supersededAn issue that has been superseded by another

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions