Java Code Examples for org.springframework.kafka.support.KafkaHeaders#RECEIVED_PARTITION_ID
The following examples show how to use
org.springframework.kafka.support.KafkaHeaders#RECEIVED_PARTITION_ID .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BatchMessageConsumer.java From kafka-with-springboot with Apache License 2.0 | 5 votes |
@KafkaListener(topics = "${kafka.topic.batchConsumerTopic}", containerFactory = "kafkaListenerContainerFactoryForBatchConsumer", groupId = "batchConsumer") public void receive(@Payload List<String> payloads, @Header(KafkaHeaders.RECEIVED_PARTITION_ID) List<Long> partitionIds, @Header(KafkaHeaders.OFFSET) List<Long> offsets) { LOGGER.info("Received group=batchConsumer with batch group data: "); for (int i = 0; i< payloads.size(); ++i) { LOGGER.info("---------------- payload='{}' from partitionId@offset='{}'", payloads.get(i), partitionIds.get(i)+"@"+offsets.get(i)); } }
Example 2
Source File: Receiver.java From spring-kafka with MIT License | 5 votes |
@KafkaListener(id = "batch-listener", topics = "${kafka.topic.batch}") public void receive(List<String> data, @Header(KafkaHeaders.RECEIVED_PARTITION_ID) List<Integer> partitions, @Header(KafkaHeaders.OFFSET) List<Long> offsets) { LOGGER.info("start of batch receive"); for (int i = 0; i < data.size(); i++) { LOGGER.info("received message='{}' with partition-offset='{}'", data.get(i), partitions.get(i) + "-" + offsets.get(i)); // handle message latch.countDown(); } LOGGER.info("end of batch receive"); }
Example 3
Source File: MultiPartitionMessageConsumer.java From kafka-with-springboot with Apache License 2.0 | 4 votes |
@KafkaListener(topics = "${kafka.topic.multiPartitionTopic}", groupId = "multiPartitionWith2Consumer") public void receiver1a(@Payload String payload, @Header(KafkaHeaders.RECEIVED_PARTITION_ID)Long partitionId, @Header(KafkaHeaders.OFFSET)Long offset) { LOGGER.info("Received consumer=1a group=multiPartitionWith2Consumer payload='{}' from partitionId@offset='{}'", payload, partitionId+"@"+offset); }
Example 4
Source File: MultiPartitionMessageConsumer.java From kafka-with-springboot with Apache License 2.0 | 4 votes |
@KafkaListener(topics = "${kafka.topic.multiPartitionTopic}", groupId = "multiPartitionWith2Consumer") public void receiver1b(@Payload String payload, @Header(KafkaHeaders.RECEIVED_PARTITION_ID)Long partitionId, @Header(KafkaHeaders.OFFSET)Long offset) { LOGGER.info("Received consumer=1b group=multiPartitionWith2Consumer payload='{}' from partitionId@offset='{}'", payload, partitionId+"@"+offset); }
Example 5
Source File: MultiPartitionMessageConsumer.java From kafka-with-springboot with Apache License 2.0 | 4 votes |
@KafkaListener(topics = "${kafka.topic.multiPartitionTopic}", containerFactory = "kafkaListenerContainerFactoryWith6Consumer", groupId = "multiPartitionWithSingleConsumer6Thread") public void receive2(@Payload String payload, @Header(KafkaHeaders.RECEIVED_PARTITION_ID)Long partitionId, @Header(KafkaHeaders.OFFSET)Long offset) { LOGGER.info("Received consumer=2 group=multiPartitionWithSingleConsumer6Thread payload='{}' from partitionId@offset='{}'", payload, partitionId+"@"+offset); }
Example 6
Source File: S1pKafkaApplication.java From grussell-spring-kafka with Apache License 2.0 | 4 votes |
@KafkaListener(topics = "${kafka.topic}") public void listen(@Payload String foo, @Header(KafkaHeaders.RECEIVED_PARTITION_ID) int partition) { System.out.println("Received: " + foo + " (partition: " + partition + ")"); this.latch.countDown(); }
Example 7
Source File: KafkaApplication.java From tutorials with MIT License | 4 votes |
@KafkaListener(topics = "${message.topic.name}", containerFactory = "headersKafkaListenerContainerFactory") public void listenWithHeaders(@Payload String message, @Header(KafkaHeaders.RECEIVED_PARTITION_ID) int partition) { System.out.println("Received Messasge: " + message + " from partition: " + partition); latch.countDown(); }
Example 8
Source File: KafkaApplication.java From tutorials with MIT License | 4 votes |
@KafkaListener(topicPartitions = @TopicPartition(topic = "${partitioned.topic.name}", partitions = { "0", "3" }), containerFactory = "partitionsKafkaListenerContainerFactory") public void listenToParition(@Payload String message, @Header(KafkaHeaders.RECEIVED_PARTITION_ID) int partition) { System.out.println("Received Message: " + message + " from partition: " + partition); this.partitionLatch.countDown(); }