spring-boot-kafka | Simple Spring Boot demo project with Apache Kafka | Pub Sub library
kandi X-RAY | spring-boot-kafka Summary
kandi X-RAY | spring-boot-kafka Summary
Simple Spring Boot demo project with Apache Kafka
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Send message to Kafka topic
- Sends a message to the Kafka topic
- Entry point for spring application
- Consume messages
spring-boot-kafka Key Features
spring-boot-kafka Examples and Code Snippets
Community Discussions
Trending Discussions on spring-boot-kafka
QUESTION
A simple spring-boot-kafka which consumes from a topic on a network cluster:
Errors:
Bootstrap broker localhost:9092 (id: -1 rack: null) disconnected
Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available.
Puzzle:
The configured broker is not local, it's BROKER_1.FOO.NET:9094, and it is available.
pom.xml
...ANSWER
Answered 2021-Jun-10 at 17:33it's BROKER_1.FOO.NET:9094, and it is available.
The bootstrap port may be available and responding to requests, but that broker then returned it's configured advertised.listeners
.
Based on your error, either
- that's set to be localhost/127.0.0.1:9092
- or you're getting the default Spring property for the bootstrap servers config
QUESTION
I've written a basic spring boot service that consumes some data via rest API and publishes it to rabbitmq and kafka.
To test the service class handling kafka producing, I followed this guide: https://www.baeldung.com/spring-boot-kafka-testing
In isolation, the test (KafkaMessagingServiceImplTest) works perfectly both in intellij idea and via mvn on the command line. Running all project tests in idea works fine. However, when I run all project tests via maven on the command line, this test fails with an NPE when trying to make the assertion on the payload String.
I've narrowed down the location of the root problem to another test class (AppPropertiesTest) which is solely testing my AppProperties component (which is a component I use to pull config from application.properties in a tidy way). When, and only when, the tests within that test class are run alongside the failing test using 'mvn clean install' in project root, does the NPE show up. Commenting out the tests in this class or annotating it with @DirtiesContext fixes the problem. Apparently something loaded into the spring context by this test class causes an issue with the timing/order of events/countdownlatch in the other test. Of course, I don't want to use @DirtiesContext as it can lead to a much slower build as the project increases in complexity. It also does not explain the problem.. and I can't handle that :)
AppPropertiesTest uses constructor injection to inject the AppProperties component. It also extends a abstract class 'GenericServiceTest' which is annotated by:
...ANSWER
Answered 2021-Apr-21 at 18:25The problem is that TestListener
is a @Component
so it is being added twice - the record is going to the other instance.
I added more debugging to verify the getter is called on a different instance.
QUESTION
I have implemented a simple application for streaming logs to apache kafka.In the producer, I have implemented log4j2.xml
file for the configuration and now I have to convert .xml
file into properties
file. It is working properly with .xml
but when I use properties
file then following error has occurred.
ANSWER
Answered 2020-Oct-28 at 11:42You should configure your kafka
logger following the appenders configuration:
QUESTION
I am facing an issue in my spring-boot(2.1.7.RELEASE) app server which uses spring-boot-Kafka('spring-Kafka' -'2.2.7.RELEASE') integration library to access my Kafka topics.
When my Kafka brokers are down, my application is unable to start.
This is what I get:
...ANSWER
Answered 2019-Oct-05 at 21:42There is a container property missingTopicsFatal
:
https://docs.spring.io/spring-kafka/api/org/springframework/kafka/listener/ContainerProperties.html#isMissingTopicsFatal--
that allows an application to start even if the topic is not available.
QUESTION
I'm trying to commit a message just after reading it from the topic. I've followed this link (https://www.confluent.io/blog/apache-kafka-spring-boot-application) to create a Kafka consumer with spring. Normally it works perfect and the consumer gets the message and waits till anotherone enters in the queue. But the problem is that when I process this messages it takes a lot of time (circa 10 minutes) the kafka queue thinks that the message is not consumed (commited) and the consumers reads it again and again. I have to say that when my process time is less than 5 minutes it works well but when it lastas longer it doesn't commit the message.
I've looked for some answers around but it doesn't help me because I'm not using the same source code (and of course a different structure). I've tried to send asynchronous methods and also to commit asynchronously the message but I've failed. Some of the sources are:
Spring Boot Kafka: Commit cannot be completed since the group has already rebalanced
https://dzone.com/articles/kafka-clients-at-most-once-at-least-once-exactly-o
Kafka 0.10 Java consumer not reading message from topic
https://github.com/confluentinc/confluent-kafka-dotnet/issues/470
The main class is here :
...ANSWER
Answered 2019-Jul-15 at 13:04You have to modify your consumer configuation with property enable.auto.commit
set to false :
QUESTION
I am writing a demo application to create a Kafka Producer. I created a topic and ran a producer and consumer on Kafka, it seems to be working. I am writing a spring application to create a producer.I'm passing the name as part of the call. When I go to "http://localhost:8080/kafka/publish/Peter", I'm getting a whitelabel error "Failed to construct kafka producer". Please help.
The main application is: SpringBootKafkaProducerApplication.java
...ANSWER
Answered 2019-Aug-22 at 18:53From your console logs value.serializer = class com.fasterxml.jackson.databind.JsonSerializer
Instead of the serializer from jackson use org.springframework.kafka.support.serializer.JsonSerializer
An exception is occurring when trying to construct the instance of the class corresponding to VALUE_SERIALIZER_CLASS_CONFIG property.
The value of VALUE_SERIALIZER_CLASS_CONFIG must be a class which implements the org.apache.kafka.common.serialization.Serializer interface.
jackson.databind.JsonSerializer doesn't satisfy this criteria and results in an InstantiationException. So use org.springframework.kafka.support.serializer.JsonSerializer which implements the above mentioned Serializer interface.
QUESTION
pom.xml
...ANSWER
Answered 2018-Nov-15 at 14:24If you use Spring Boot, you don't need that custom ConsumerFactory
, neither ConcurrentKafkaListenerContainerFactory
. You should fully rely on the auto-configuration and appropriate configuration properties from the spring.kafka
namespace: https://docs.spring.io/spring-boot/docs/2.1.0.RELEASE/reference/htmlsingle/#boot-features-kafka
If you still insist to exclude KafkaAutoConfiguration
and do everything manually, you really need to name your ConcurrentKafkaListenerContainerFactory
with the requested kafkaListenerContainerFactory
bean name: https://docs.spring.io/spring-kafka/docs/2.2.0.RELEASE/reference/html/_reference.html#kafka-listener-annotation
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install spring-boot-kafka
You can use spring-boot-kafka like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the spring-boot-kafka component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page