org.springframework.integration.kafka.outbound.KafkaProducerMessageHandler Java Examples

The following examples show how to use org.springframework.integration.kafka.outbound.KafkaProducerMessageHandler. 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: KafkaBinderTests.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #2
Source File: KafkaBinderTests.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testSendTimeoutExpressionProducerMetadata() throws Exception {
	Binder binder = getBinder(createConfigurationProperties());
	DirectChannel output = new DirectChannel();
	String testTopicName = UUID.randomUUID().toString();
	ExtendedProducerProperties<KafkaProducerProperties> properties = createProducerProperties();
	properties.getExtension().setSync(true);
	SpelExpressionParser parser = new SpelExpressionParser();
	Expression sendTimeoutExpression = parser.parseExpression("5000");
	properties.getExtension().setSendTimeoutExpression(sendTimeoutExpression);
	Binding<MessageChannel> producerBinding = binder.bindProducer(testTopicName,
			output, properties);
	DirectFieldAccessor accessor = new DirectFieldAccessor(
			extractEndpoint(producerBinding));
	KafkaProducerMessageHandler wrappedInstance = (KafkaProducerMessageHandler) accessor
			.getWrappedInstance();
	assertThat(new DirectFieldAccessor(wrappedInstance).getPropertyValue("sendTimeoutExpression")
			.equals(sendTimeoutExpression));
	producerBinding.unbind();
}
 
Example #3
Source File: HerokuReplayApplication.java    From heroku-metrics-spring with MIT License 5 votes vote down vote up
@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;
}
 
Example #4
Source File: ProducingChannelConfig.java    From spring-kafka with MIT License 5 votes vote down vote up
@Bean
@ServiceActivator(inputChannel = "producingChannel")
public MessageHandler kafkaMessageHandler() {
  KafkaProducerMessageHandler<String, String> handler =
      new KafkaProducerMessageHandler<>(kafkaTemplate());
  handler.setMessageKeyExpression(new LiteralExpression("kafka-integration"));

  return handler;
}
 
Example #5
Source File: KafkaBinderActuatorTests.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 4 votes vote down vote up
@Bean
public ProducerMessageHandlerCustomizer<KafkaProducerMessageHandler<?, ?>> handlerCustomizer() {
	return (handler, destinationName) -> handler.setBeanName("setByCustomizer:" + destinationName);
}