Home > Mobile >  How do I connect my sample kafka producer application to a remote kafka server?
How do I connect my sample kafka producer application to a remote kafka server?

Time:11-10

https://www.javainuse.com/spring/spring-boot-apache-kafka-hello-world

I followed this example to build a simple Kafka producer for some testing. However, my Kafka instance is not local and is managed by my company's infrastructure team, so it is running on a remote server. I have the address and port it is running on, but I am unsure how to configure my application to connect to it. Do I need to use an application.properties file to define the kafka address pool or something like this?

spring.kafka.bootstrap-servers=[kafka-server-1:port],[kafka-server-2:port]
spring.kafka.consumer.group-id=my-sample-group
spring.kafka.security.protocol=SSL

In the tutorial I was following for the consumer I have something like this in my application.properties but I'm not sure if it's the same for the producer or should be different. The second value here seems to be specific to the consumer and based on the autocomplete in my IDE I'm not seeing a similar value for producers.

Any help is appreciated

CodePudding user response:

The tutorial you followed is highly outdated. I would recommend to look at the official docs: https://docs.spring.io/spring-kafka/reference/html/#spring-boot-producer-app. Depending on your setup, the config could just be one bootstrap server.

spring.kafka.bootstrap-servers=kafka.your-company.com:9092

I would ask the Kafka ops team how to connect, as this can get complex with jaas and ssl.

Spring Boot Kafka config settings can be found here: https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html#application-properties.integration.spring.kafka.admin.client-id

CodePudding user response:

spring.kafka.bootstrap-servers is the same property for both consumers and producers (and admin clients), yes.

Do I need to use an application.properties file

It's not required for a SpringBoot application, no.

  • Related