spring-kafka

How do I use Spring Expression Language for an Array in an annotation with Scala

别来无恙 提交于 2020-02-08 02:32:21
问题 I have a simple Scala project that looks like this... @Configuration public class CommonConfiguration{ ... @Value("${spring.kafka.topic}") public String topic; ... } @Service class KafkaService @Autowired()(producer: KafkaTemplate[String, Array[Byte]], config: CommonConfiguration){ def sendMessage(msg: String): Unit = { println(s"Writing the message $msg ${config.topic}") producer.send(config.topic, msg.getBytes()); } @KafkaListener(id="test", topics="#{'${spring.kafka.topic}'.split(',')}")

How do I use Spring Expression Language for an Array in an annotation with Scala

♀尐吖头ヾ 提交于 2020-02-08 02:32:12
问题 I have a simple Scala project that looks like this... @Configuration public class CommonConfiguration{ ... @Value("${spring.kafka.topic}") public String topic; ... } @Service class KafkaService @Autowired()(producer: KafkaTemplate[String, Array[Byte]], config: CommonConfiguration){ def sendMessage(msg: String): Unit = { println(s"Writing the message $msg ${config.topic}") producer.send(config.topic, msg.getBytes()); } @KafkaListener(id="test", topics="#{'${spring.kafka.topic}'.split(',')}")

Hooks in Kafka Listener

强颜欢笑 提交于 2020-02-06 07:38:41
问题 Is there any sort of hooks available before / after kafka listen a message ? Use case : MDC co-relation id has to be set for to perform the log traceability What I am looking for ? A before/after call back method so that MDC co-relation id can be set on entry and eventually clean MDC upon exit. Edited Scenario: I am getting co-relation id as a part of Kafka Headers and I want to set the same in MDC as soon as I receive a message in Kafka Listener Appreciated for help 回答1: You can add an

Spring cloud streams could not autowire Source.class

痴心易碎 提交于 2020-02-02 15:42:50
问题 I am learning Spring Cloud Streams from scratch. I tried to create a Source application like this: import org.springframework.cloud.stream.messaging.Source; //etc @RestController @SpringBootApplication @CrossOrigin @EnableBinding(Source.class) public class StreamsProducerApplication { @Autowired Source source; @GetMapping(value="/send/{message}") public void sendMessage(@PathVariable String message){ if(message != null){ source.output().send(MessageBuilder.withPayload(message).build());} }

Kafka consumer exception and offset commits

谁说我不能喝 提交于 2020-01-31 22:56:06
问题 I've been trying to do some POC work for Spring Kafka. Specifically, I wanted to experiment with what are the best practices in terms of dealing with errors while consuming messages within Kafka. I am wondering if anyone is able to help with: Sharing best practices surrounding what Kafka consumers should do when there is a failure Help me understand how AckMode Record works, and how to prevent commits to the Kafka offset queue when an exception is thrown in the listener method. The code

How to check if @KafkaListener was invoked in integration test?

拟墨画扇 提交于 2020-01-25 08:32:06
问题 I would like to write an integration test for whole kafka flow. In my production code I have: @KafkaListener(topics = "myTopic") public void listen(@Payload String payload) { log.debug("processing payload: '{}' ", payload); // business logic here } In my test code I use KafkaProducer<String, String> producer; to send messages to specific topic. I would like to have a hook that would indicate that @KafkaListener was called. I could insert some delay into test but it's a bad practice and I want

Spring Boot Microservice depends on another Microservice in Jenkins

落花浮王杯 提交于 2020-01-25 06:52:33
问题 I have developed two Springboot michroservices ex- service1 and service2. service2 microservice having dependency of service1. I've added dependency of service1 in service2 pom file and working expected in eclipse while running service2. but when I deployed in Jenkins and I've created project(Jenkins Job) for service1 and ran with maven goal 'clean install', project builds successfully. When I created project(Jenkins Job) for service2 and running the Jenkins Job, build is failing because

How to choose Kafka transaction id for several applications, hosted in Kubernetes?

那年仲夏 提交于 2020-01-25 01:06:11
问题 I have a classic microservice architecture. So, there are differ applications. Each application may have 1..N instances. The system is deployed to Kubernetes. So, we have many differ PODs , which can start and stop in any time. I want to implement read-process-write pattern, so I need Kafka transactions. To configure transactions, I need to set some transaction id for each Kafka producer. (Actually, I need transaction-id-prefix , because of I use Spring for my applications, and it has such

Determine the Kafka-Client compatibility with kafka-broker

纵然是瞬间 提交于 2020-01-24 22:14:41
问题 Within the remote kafka cloud cluster, the kafka brokers will be updated to a new version (5.1) and therefore a new kafka protocol applies. Now I should update my kafka client to being able to connect. Right now I am using following kafka relevant dependencies in my spring-boot application: <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-parent</artifactId> <version>1.3.8.RELEASE</version> <groupId>org.springframework.integration</groupId> <artifactId>spring-integration

Kafka - Deserializing the object in Consumer

↘锁芯ラ 提交于 2020-01-23 16:21:30
问题 We are considering to use Kafka in our for messaging and our applications are developed using Spring. So, we have planned to use spring-kafka. The producer puts the message as HashMap object into the queue. We have JSON serializer and we assumed that the map will be serialized and put into the queue. And here is the producer config. spring: kafka: bootstrap-servers: localhost:9092 producer: key-serializer: org.springframework.kafka.support.serializer.JsonSerializer value-serializer: org