Skip to content

Conversation

timonback
Copy link
Member

Use spring properties instead

Use spring properties instead

Co-authored-by: sam0r040 <[email protected]>
@netlify
Copy link

netlify bot commented Oct 27, 2023

Deploy Preview for springwolf-ui canceled.

Name Link
🔨 Latest commit 159c97e
🔍 Latest deploy log https://app.netlify.com/sites/springwolf-ui/deploys/653bc2a94e4fbb00084e1fa2

@timonback timonback merged commit 6e61df1 into springwolf:master Oct 27, 2023
@timonback timonback deleted the chore/deprecated-async-api-docket branch October 27, 2023 14:10
@maksymgendin
Copy link

maksymgendin commented Nov 10, 2023

@timonback Couldn't find a better place for commenting on this.

We're currently using manual configuration via AsyncApiDocket and I'm not sure what should be an alternative for our use case because we don't use the default Spring Kafka integration where method signature and annotations are used to configure the Kafka consumers, producers and payloads.

We have a fully reactive application with io.projectreactor.kafka:reactor-kafka where the entry point in consuming Kafka records is a ReactiveKafkaConsumerTemplate:

private <T> ReactiveKafkaConsumerTemplate<String, T> buildReactiveKafkaConsumerTemplate(Class<T> eventClass,
                                                                                        KafkaProperties kafkaProperties,
                                                                                        String topicName,
                                                                                        MeterRegistry meterRegistry) {
    return new ReactiveKafkaConsumerTemplate<>(
            ReceiverOptions.<String, T>create(kafkaProperties.buildConsumerProperties())
                    .withKeyDeserializer(new ErrorHandlingDeserializer<>(new StringDeserializer()))
                    .withValueDeserializer(new ErrorHandlingDeserializer<>(new JsonDeserializer<>(eventClass, false)))
                    .consumerListener(new MicrometerConsumerListener(meterRegistry))
                    .subscription(Collections.singleton(topicName))
    );
}

ReceiverOptions is a class from reactor-kafka as well.

Could you please give me any hints how Springwolf is supposed to work with configuration only in our case?

Update: I found a working solution for us:

@Configuration
@Profile("local")
class LocalSpringwolfConfiguration {

    @AsyncListener(
            operation = @AsyncOperation(
                    channelName = "${kafka.topics.my-topic.topic-name}",
                    payloadType = MyEvent.class
            )
    )
    @KafkaAsyncOperationBinding
    void myTopicConfiguration() {

    }
}

and

springwolf:
  enabled: true
  use-fqn: true # has to be set, otherwise an HTTP 400 is thrown when publishing from browser
  docket:
    base-package: local
    info:
      title: ${spring.application.name}
      version: dummy
    servers:
      local:
        url: ${spring.kafka.bootstrap-servers}
        protocol: kafka
  plugin:
    kafka:
      publishing:
        enabled: true
        producer:
          client-id: ${spring.application.name}
          bootstrap-servers: ${spring.kafka.bootstrap-servers}
          key-serializer: org.apache.kafka.common.serialization.StringSerializer
          value-serializer: org.springframework.kafka.support.serializer.JsonSerializer

@maksymgendin
Copy link

maksymgendin commented Nov 10, 2023

One more problem is that we're using Springwolf mainly for local development with Testcontainers and the servers property is currently set dynamically on startup when constructing the AsyncApiDocket bean. How this can work with Spring properties?

Update: This problem is actually solvable like this:

springwolf:
  servers:
    local:
      url: ${spring.kafka.bootstrap-servers}
      protocol: kafka

@timonback
Copy link
Member Author

Hi @maksymgendin,
feel free to comment in #445 in case you run into issue. We improved our migration guide.

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

Successfully merging this pull request may close these issues.

2 participants