当前位置: 首页>>代码示例>>Java>>正文


Java ContainerProperties.setMessageListener方法代码示例

本文整理汇总了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");
}
 
开发者ID:rmap-project,项目名称:rmap,代码行数:26,代码来源:SimpleKafkaIT.java

示例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);
}
 
开发者ID:SpringOnePlatform2016,项目名称:grussell-spring-kafka,代码行数:10,代码来源:S1pKafkaApplication.java

示例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);
}
 
开发者ID:SpringOnePlatform2016,项目名称:grussell-spring-kafka,代码行数:9,代码来源:S1pKafkaApplication.java

示例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));
}
 
开发者ID:rmap-project,项目名称:rmap,代码行数:47,代码来源:SimpleKafkaIT.java


注:本文中的org.springframework.kafka.listener.config.ContainerProperties.setMessageListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。