本文整理汇总了Java中org.springframework.kafka.listener.config.ContainerProperties.setMessageListener方法的典型用法代码示例。如果您正苦于以下问题:Java ContainerProperties.setMessageListener方法的具体用法?Java ContainerProperties.setMessageListener怎么用?Java ContainerProperties.setMessageListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.kafka.listener.config.ContainerProperties
的用法示例。
在下文中一共展示了ContainerProperties.setMessageListener方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAutoCommit
import org.springframework.kafka.listener.config.ContainerProperties; //导入方法依赖的package包/类
@Test
public void testAutoCommit() throws Exception {
LOG.info("Start testAutoCommit");
ContainerProperties containerProps = new ContainerProperties("topic3", "topic4");
final CountDownLatch latch = new CountDownLatch(4);
containerProps.setMessageListener((MessageListener<Integer, String>) message -> {
LOG.info("received: " + message);
latch.countDown();
});
KafkaMessageListenerContainer<Integer, String> container = createContainer(containerProps,
IntegerDeserializer.class, StringDeserializer.class);
container.setBeanName("testAutoCommit");
container.start();
Thread.sleep(5000); // wait a bit for the container to start
KafkaTemplate<Integer, String> template = createTemplate(IntegerSerializer.class, StringSerializer.class);
template.setDefaultTopic("topic3");
template.sendDefault(0, "foo");
template.sendDefault(2, "bar");
template.sendDefault(0, "baz");
template.sendDefault(2, "qux");
template.flush();
assertTrue(latch.await(60, TimeUnit.SECONDS));
container.stop();
LOG.info("Stop testAutoCommit");
}
示例2: container
import org.springframework.kafka.listener.config.ContainerProperties; //导入方法依赖的package包/类
@Bean
public KafkaMessageListenerContainer<String, String> container(
ConsumerFactory<String, String> consumerFactory,
ConfigProperties config) {
ContainerProperties containerProperties = new ContainerProperties(config.getTopic());
containerProperties.setMessageListener(listener());
containerProperties.setAckMode(AckMode.MANUAL_IMMEDIATE);
return new KafkaMessageListenerContainer<>(consumerFactory, containerProperties);
}
示例3: container
import org.springframework.kafka.listener.config.ContainerProperties; //导入方法依赖的package包/类
@Bean
public KafkaMessageListenerContainer<String, String> container(
ConsumerFactory<String, String> consumerFactory,
ConfigProperties config) {
ContainerProperties containerProperties = new ContainerProperties(config.getTopic());
containerProperties.setMessageListener(listener());
return new KafkaMessageListenerContainer<>(consumerFactory, containerProperties);
}
示例4: testSendIndexDTO
import org.springframework.kafka.listener.config.ContainerProperties; //导入方法依赖的package包/类
@Test
public void testSendIndexDTO() throws Exception {
LOG.info("Start testSendIndexDTO");
ContainerProperties containerProps = new ContainerProperties("topic1", "topic2");
List<IndexDTO> dtos = prepareIndexableDtos(rdfHandler, "/data/discos/rmd18mddcw", null)
.collect(Collectors.toList());
Queue<IndexDTO> expectedDtos = new ArrayDeque<>(dtos);
Queue<ExpectedActualDTOPair> receivedDtos = new ArrayDeque<>();
final CountDownLatch latch = new CountDownLatch(3);
containerProps.setMessageListener((MessageListener<Integer, IndexDTO>) message -> {
LOG.info("received: " + message);
IndexDTO expected = expectedDtos.remove();
LOG.debug("expected: " + expected);
IndexDTO actual = message.value();
LOG.debug("actual: " + actual);
receivedDtos.add(new ExpectedActualDTOPair(expected, actual));
LOG.debug("Decrementing latch.");
latch.countDown();
});
KafkaMessageListenerContainer<Integer, IndexDTO> container = createContainerForDto(containerProps, IntegerDeserializer.class, GenericJvmObjectDeserializer.class);
container.setBeanName("testSendIndexDTO");
container.start();
Thread.sleep(5000); // wait a bit for the container to start
KafkaTemplate<Integer, IndexDTO> template = createTemplate(IntegerSerializer.class, GenericJvmObjectSerializer.class);
template.setDefaultTopic("topic1");
prepareIndexableDtos(rdfHandler, "/data/discos/rmd18mddcw", null)
.peek(dto -> LOG.debug("Prepared DTO {}", dto))
.forEach(template::sendDefault);
// do anything with the completablefuture returned by the template?
template.flush();
assertTrue(latch.await(120, TimeUnit.SECONDS));
container.stop();
LOG.info("Stop testSendIndexDTO");
receivedDtos.forEach(pair -> assertEquals(pair.expected, pair.actual));
}