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


Java ContainerTestUtils类代码示例

本文整理汇总了Java中org.springframework.kafka.test.utils.ContainerTestUtils的典型用法代码示例。如果您正苦于以下问题:Java ContainerTestUtils类的具体用法?Java ContainerTestUtils怎么用?Java ContainerTestUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ContainerTestUtils类属于org.springframework.kafka.test.utils包,在下文中一共展示了ContainerTestUtils类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUp

import org.springframework.kafka.test.utils.ContainerTestUtils; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  // set up the Kafka producer properties
  Map<String, Object> senderProperties =
      KafkaTestUtils.senderProps(AllSpringKafkaTests.embeddedKafka.getBrokersAsString());

  // create a Kafka producer factory
  ProducerFactory<String, String> producerFactory =
      new DefaultKafkaProducerFactory<String, String>(senderProperties);

  // create a Kafka template
  template = new KafkaTemplate<>(producerFactory);
  // set the default topic to send to
  template.setDefaultTopic(AllSpringKafkaTests.RECEIVER_TOPIC);

  // wait until the partitions are assigned
  for (MessageListenerContainer messageListenerContainer : kafkaListenerEndpointRegistry
      .getListenerContainers()) {
    ContainerTestUtils.waitForAssignment(messageListenerContainer,
        AllSpringKafkaTests.embeddedKafka.getPartitionsPerTopic());
  }
}
 
开发者ID:code-not-found,项目名称:spring-kafka,代码行数:23,代码来源:SpringKafkaReceiverTest.java

示例2: setUp

import org.springframework.kafka.test.utils.ContainerTestUtils; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  // set up the Kafka producer properties
  Map<String, Object> senderProperties =
      KafkaTestUtils.senderProps(embeddedKafka.getBrokersAsString());

  // create a Kafka producer factory
  ProducerFactory<String, String> producerFactory =
      new DefaultKafkaProducerFactory<String, String>(senderProperties);

  // create a Kafka template
  template = new KafkaTemplate<>(producerFactory);
  // set the default topic to send to
  template.setDefaultTopic(RECEIVER_TOPIC);

  // wait until the partitions are assigned
  for (MessageListenerContainer messageListenerContainer : kafkaListenerEndpointRegistry
      .getListenerContainers()) {
    ContainerTestUtils.waitForAssignment(messageListenerContainer,
        embeddedKafka.getPartitionsPerTopic());
  }
}
 
开发者ID:code-not-found,项目名称:spring-kafka,代码行数:23,代码来源:SpringKafkaReceiverTest.java

示例3: setUp

import org.springframework.kafka.test.utils.ContainerTestUtils; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  // wait until the partitions are assigned
  for (MessageListenerContainer messageListenerContainer : kafkaListenerEndpointRegistry
      .getListenerContainers()) {
    ContainerTestUtils.waitForAssignment(messageListenerContainer,
        embeddedKafka.getPartitionsPerTopic());
  }
}
 
开发者ID:code-not-found,项目名称:spring-kafka,代码行数:10,代码来源:SpringKafkaApplicationTest.java

示例4: setup

import org.springframework.kafka.test.utils.ContainerTestUtils; //导入依赖的package包/类
@Before
public void setup() throws Exception {
	for (MessageListenerContainer messageListenerContainer : kafkaListenerEndpointRegistry
			.getListenerContainers()) {
		ContainerTestUtils.waitForAssignment(messageListenerContainer, embeddedKafka.getPartitionsPerTopic());
	}
}
 
开发者ID:italia,项目名称:daf-replicate-ingestion,代码行数:8,代码来源:SenderTest.java

示例5: setup

import org.springframework.kafka.test.utils.ContainerTestUtils; //导入依赖的package包/类
@Before
public void setup() throws Exception {
	Map<String, Object> consumerProps = KafkaTestUtils.consumerProps("testT", "false", embeddedKafka);
	DefaultKafkaConsumerFactory<String, String> cf =
		new DefaultKafkaConsumerFactory<>(consumerProps);
	ContainerProperties containerProperties = new ContainerProperties(TEST_TOPIC);
	container = new KafkaMessageListenerContainer<>(cf, containerProperties);
	final BlockingQueue<ConsumerRecord<String, String>> records = new LinkedBlockingQueue<>();
	container.setupMessageListener((MessageListener<String, String>) record -> {
           log.error("Message received: " + record);
           records.add(record);
       });
	container.start();
	ContainerTestUtils.waitForAssignment(container, embeddedKafka.getPartitionsPerTopic());
	Map<String, Object> senderProps = KafkaTestUtils.senderProps(embeddedKafka.getBrokersAsString());
	ProducerFactory<String, String> pf =
		new DefaultKafkaProducerFactory<>(senderProps);
	template = new KafkaTemplate<>(pf);
	template.setDefaultTopic(TEST_TOPIC);
}
 
开发者ID:underscorenico,项目名称:skeleton-oms-java,代码行数:21,代码来源:HelloProcessTest.java

示例6: setUp

import org.springframework.kafka.test.utils.ContainerTestUtils; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  // wait until the partitions are assigned
  for (MessageListenerContainer messageListenerContainer : kafkaListenerEndpointRegistry
      .getListenerContainers()) {
    ContainerTestUtils.waitForAssignment(messageListenerContainer,
        AllSpringKafkaTests.embeddedKafka.getPartitionsPerTopic());
  }
}
 
开发者ID:code-not-found,项目名称:spring-kafka,代码行数:10,代码来源:SpringKafkaApplicationTest.java

示例7: setUp

import org.springframework.kafka.test.utils.ContainerTestUtils; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  // set up the Kafka consumer properties
  Map<String, Object> consumerProperties =
      KafkaTestUtils.consumerProps("sender", "false", embeddedKafka);

  // create a Kafka consumer factory
  DefaultKafkaConsumerFactory<String, String> consumerFactory =
      new DefaultKafkaConsumerFactory<String, String>(consumerProperties);

  // set the topic that needs to be consumed
  ContainerProperties containerProperties = new ContainerProperties(SENDER_TOPIC);

  // create a Kafka MessageListenerContainer
  container = new KafkaMessageListenerContainer<>(consumerFactory, containerProperties);

  // create a thread safe queue to store the received message
  records = new LinkedBlockingQueue<>();

  // setup a Kafka message listener
  container.setupMessageListener(new MessageListener<String, String>() {
    @Override
    public void onMessage(ConsumerRecord<String, String> record) {
      LOGGER.debug("test-listener received message='{}'", record.toString());
      records.add(record);
    }
  });

  // start the container and underlying message listener
  container.start();

  // wait until the container has the required number of assigned partitions
  ContainerTestUtils.waitForAssignment(container, embeddedKafka.getPartitionsPerTopic());
}
 
开发者ID:code-not-found,项目名称:spring-kafka,代码行数:35,代码来源:SpringKafkaSenderTest.java

示例8: setUp

import org.springframework.kafka.test.utils.ContainerTestUtils; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  // set up the Kafka consumer properties
  Map<String, Object> consumerProperties =
      KafkaTestUtils.consumerProps("sender_group", "false", AllSpringKafkaTests.embeddedKafka);

  // create a Kafka consumer factory
  DefaultKafkaConsumerFactory<String, String> consumerFactory =
      new DefaultKafkaConsumerFactory<String, String>(consumerProperties);

  // set the topic that needs to be consumed
  ContainerProperties containerProperties =
      new ContainerProperties(AllSpringKafkaTests.SENDER_TOPIC);

  // create a Kafka MessageListenerContainer
  container = new KafkaMessageListenerContainer<>(consumerFactory, containerProperties);

  // create a thread safe queue to store the received message
  records = new LinkedBlockingQueue<>();

  // setup a Kafka message listener
  container.setupMessageListener(new MessageListener<String, String>() {
    @Override
    public void onMessage(ConsumerRecord<String, String> record) {
      LOGGER.debug("test-listener received message='{}'", record.toString());
      records.add(record);
    }
  });

  // start the container and underlying message listener
  container.start();
  // wait until the container has the required number of assigned partitions
  ContainerTestUtils.waitForAssignment(container,
      AllSpringKafkaTests.embeddedKafka.getPartitionsPerTopic());
}
 
开发者ID:code-not-found,项目名称:spring-kafka,代码行数:36,代码来源:SpringKafkaSenderTest.java


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