@KafkaListener(topics="tacocloud.orders.topic")publicvoidhandle(Order order,ConsumerRecord<Order> record) {log.info("Received from partition {} with timestamp {}",record.partition(),record.timestamp());ui.displayOrder(order);}
类似地,可以使用 Message 而不是 ConsumerRecord,并达到同样的效果:
@KafkaListener(topics="tacocloud.orders.topic")publicvoidhandle(Order order,Message<Order> message) {MessageHeaders headers =message.getHeaders();log.info("Received from partition {} with timestamp {}",headers.get(KafkaHeaders.RECEIVED_PARTITION_ID)headers.get(KafkaHeaders.RECEIVED_TIMESTAMP));ui.displayOrder(order);}