List of usage examples for org.springframework.kafka.support KafkaHeaders TOPIC
String TOPIC
To view the source code for org.springframework.kafka.support KafkaHeaders TOPIC.
Click Source Link
From source file:org.springframework.kafka.support.converter.MessagingMessageConverter.java
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override/*from w ww .j a v a 2s.co m*/ public ProducerRecord<?, ?> fromMessage(Message<?> message, String defaultTopic) { MessageHeaders headers = message.getHeaders(); Object topicHeader = headers.get(KafkaHeaders.TOPIC); String topic = null; if (topicHeader instanceof byte[]) { topic = new String(((byte[]) topicHeader), StandardCharsets.UTF_8); } else if (topicHeader instanceof String) { topic = (String) topicHeader; } else if (topicHeader == null) { Assert.state(defaultTopic != null, "With no topic header, a defaultTopic is required"); } else { throw new IllegalStateException( KafkaHeaders.TOPIC + " must be a String or byte[], not " + topicHeader.getClass()); } Integer partition = headers.get(KafkaHeaders.PARTITION_ID, Integer.class); Object key = headers.get(KafkaHeaders.MESSAGE_KEY); Object payload = convertPayload(message); Long timestamp = headers.get(KafkaHeaders.TIMESTAMP, Long.class); Headers recordHeaders = initialRecordHeaders(message); if (this.headerMapper != null) { this.headerMapper.fromHeaders(headers, recordHeaders); } return new ProducerRecord(topic == null ? defaultTopic : topic, partition, timestamp, key, payload, recordHeaders); }