spring-kafka

How to test ListenableFuture Callbacks in spock

别说谁变了你拦得住时间么 提交于 2020-05-09 10:49:05
问题 I asked a question a few days ago regarding stubbing the future response from the kafka.send() method. this was answered and explained correctly by @kriegaex here Though I faced another issue, on how can i test the onSuccess and onFailure callbacks of this future response. here's the code under testing. import org.springframework.kafka.core.KafkaTemplate; import org.springframework.kafka.support.SendResult; import org.springframework.util.concurrent.ListenableFuture; import org

Stop consume message for Stream listener

为君一笑 提交于 2020-05-06 19:12:32
问题 I am looking for a way to stop consume messages with stream listener. @StreamListener(MBinding.M_INPUT) public void consumeMessage(Message<MerchantEvent> message) { //handle when receive message } cloud: stream: bindings: MInput: destination: topicName group: groupName I have googled it but right now still have no idea how to stop consuming. Is there anyone who know it? 回答1: You can do it using the actuator (see Binding Visualization and Control). Or you can invoke the endpoint

How to write Unit test case for adding callback for ListenableFuture

百般思念 提交于 2020-04-28 09:48:02
问题 I am trying to write the unit test case for ListenableFuture adding Callback but I am not sure how to do it. Didn`t get anything useful on internet. @Test public void can_publish_data_to_kafka() { String topic = someString(10); String key = someAlphanumericString(5); String data = someString(50); SendResult sendResult = mock(SendResult.class); ListenableFuture<SendResult<String, Object>> future = mock(ListenableFuture.class); given(kafkaTemplate.send(topic, key, data)).willReturn(future);

How to write Unit test case for adding callback for ListenableFuture

北战南征 提交于 2020-04-28 09:46:27
问题 I am trying to write the unit test case for ListenableFuture adding Callback but I am not sure how to do it. Didn`t get anything useful on internet. @Test public void can_publish_data_to_kafka() { String topic = someString(10); String key = someAlphanumericString(5); String data = someString(50); SendResult sendResult = mock(SendResult.class); ListenableFuture<SendResult<String, Object>> future = mock(ListenableFuture.class); given(kafkaTemplate.send(topic, key, data)).willReturn(future);

unit testing ListenableFuture kafkaTemplate.send always returns null

吃可爱长大的小学妹 提交于 2020-04-18 05:50:54
问题 I'm trying to unit test the callbacks from the kafkaTemplate.send() but its not working as expected. here's the code snippet of the code im trying to test. @Override public void sendMessage(String topicName, String message) { ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send(topicName, message); future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() { @Override public void onSuccess(SendResult<String, String> result) { System.out.print("Success")

unit testing ListenableFuture kafkaTemplate.send always returns null

我的未来我决定 提交于 2020-04-18 05:50:39
问题 I'm trying to unit test the callbacks from the kafkaTemplate.send() but its not working as expected. here's the code snippet of the code im trying to test. @Override public void sendMessage(String topicName, String message) { ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send(topicName, message); future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() { @Override public void onSuccess(SendResult<String, String> result) { System.out.print("Success")

how to set concurrency (or other configurations) for ConcurrentKafkaListenerContainerFactory per StreamListener

青春壹個敷衍的年華 提交于 2020-04-18 00:49:40
问题 We have scenario where our application(spring boot, spring-cloud-stream based) listens to multiple Kafka topics (TOPIC_A with 3 partitions, TOPIC_B with 1 partition,TOPIC_C with 10 partitions) i.e. 3 @StreamListener methods. @StreamListener(TopicASink.INPUT) public void processTopicA(Message<String> msg) { logger.info("** recieved message: {} ", msg.getPayload()); // do some processing } @StreamListener(TopicBSink.INPUT) public void processTopicB(Message<String> msg) { logger.info("**

Not able to poll / fetch all records from kafka topic

穿精又带淫゛_ 提交于 2020-04-17 20:28:09
问题 I am trying to poll data from a specific topic like kafka is receiving 100 records/s but most of the time it does not fetch all records. I am using timeout as 5000ms and I am calling this method every 100ms Note : I am subscribing to the specific topic too @Scheduled(fixedDelayString = "100") public void pollRecords() { ConsumerRecords<String, String> records = leadConsumer.poll("5000"); How can I fetch all the data from kafka ? 回答1: Maximum number of records returned from poll() is specified

Not able to poll / fetch all records from kafka topic

笑着哭i 提交于 2020-04-17 20:27:43
问题 I am trying to poll data from a specific topic like kafka is receiving 100 records/s but most of the time it does not fetch all records. I am using timeout as 5000ms and I am calling this method every 100ms Note : I am subscribing to the specific topic too @Scheduled(fixedDelayString = "100") public void pollRecords() { ConsumerRecords<String, String> records = leadConsumer.poll("5000"); How can I fetch all the data from kafka ? 回答1: Maximum number of records returned from poll() is specified

Deserialize kafka messages in KafkaConsumer using springboot

馋奶兔 提交于 2020-04-16 04:14:41
问题 I have a springboot app that listen kafka messages and convert them to object @KafkaListener(topics = "test", groupId = "group_id") public void consume(String message) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); Hostel hostel = objectMapper.readValue(message, Hostel.class); } I woder if it is possible to do ti directly @KafkaListener(topics = "test", groupId = "group_id") public void consume(Hostel hostel) throws IOException { } 回答1: You can do it using spring-kafka .