本文整理汇总了Java中org.springframework.integration.kafka.outbound.KafkaProducerMessageHandler类的典型用法代码示例。如果您正苦于以下问题:Java KafkaProducerMessageHandler类的具体用法?Java KafkaProducerMessageHandler怎么用?Java KafkaProducerMessageHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
KafkaProducerMessageHandler类属于org.springframework.integration.kafka.outbound包,在下文中一共展示了KafkaProducerMessageHandler类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSyncProducerMetadata
import org.springframework.integration.kafka.outbound.KafkaProducerMessageHandler; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testSyncProducerMetadata() throws Exception {
Binder binder = getBinder(createConfigurationProperties());
DirectChannel output = new DirectChannel();
String testTopicName = UUID.randomUUID().toString();
ExtendedProducerProperties<KafkaProducerProperties> properties = createProducerProperties();
properties.getExtension().setSync(true);
Binding<MessageChannel> producerBinding = binder.bindProducer(testTopicName, output, properties);
DirectFieldAccessor accessor = new DirectFieldAccessor(extractEndpoint(producerBinding));
KafkaProducerMessageHandler wrappedInstance = (KafkaProducerMessageHandler) accessor.getWrappedInstance();
assertThat(new DirectFieldAccessor(wrappedInstance).getPropertyValue("sync").equals(Boolean.TRUE))
.withFailMessage("Kafka Sync Producer should have been enabled.");
producerBinding.unbind();
}
示例2: kafkaHandler
import org.springframework.integration.kafka.outbound.KafkaProducerMessageHandler; //导入依赖的package包/类
@ServiceActivator(inputChannel = "toKafka")
@Bean
public MessageHandler kafkaHandler() throws Exception {
KafkaProducerMessageHandler<String, String> handler =
new KafkaProducerMessageHandler<>(kafkaTemplate());
handler.setTopicExpression(new LiteralExpression(KafkaConfig.getTopic()));
handler.setMessageKeyExpression(new LiteralExpression(KafkaConfig.getMessageKey()));
return handler;
}
示例3: kafkaMessageHandler
import org.springframework.integration.kafka.outbound.KafkaProducerMessageHandler; //导入依赖的package包/类
@Bean
@ServiceActivator(inputChannel = "producingChannel")
public MessageHandler kafkaMessageHandler() {
KafkaProducerMessageHandler<String, String> handler =
new KafkaProducerMessageHandler<>(kafkaTemplate());
handler.setMessageKeyExpression(new LiteralExpression("kafka-integration"));
return handler;
}