spring-kafka - 使用 Spring Boot 2.1.12 和 Spring for Apache Kafka 2.2.12 进行 JUnit 测试
问题描述
只是想找出一个简单的例子,使用 Spring Boot 2.1.12 和 Spring for Apache Kafka 2.2.12 与 KafkaListener 一起工作,以重试最后一条失败的消息。如果消息失败,则应将消息重定向到将进行重试的另一个主题。我们将有 4 个主题。topic, retryTopic, sucessTopic 和 errorTopic 如果 topic 失败,应该重定向到 retryTopic,在那里进行 3 次重试尝试。如果这些尝试失败,则必须重定向到 errorTopic。如果主题和重试主题都成功,则应重定向到成功主题。我需要用JUnit Test 覆盖 90% 的案例。
解决方案
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
// this package must match the package in the <generatePackage>
// specified in
// pom.xml
marshaller.setContextPath("br.com.company.ws");
return marshaller;
}
@Bean
public CountryClient countryClient(Jaxb2Marshaller marshaller) {
CountryClient client = new CountryClient();
client.setDefaultUri(link);
WebServiceTemplate template = client.getWebServiceTemplate();
template.setMessageSender(new WebServiceMessageSenderWithAuth(username, password));
client.setMarshaller(marshaller);
client.setUnmarshaller(marshaller);
return client;
}
@Service 公共类 CountryClient 扩展 WebServiceGatewaySupport {
@Value("${spring.link.consumer.link}")
private String link;
public ZfifNfMaoResponse getCountry(ZfifNfMao zfifNfMao) {
zfifNfMao = new ZfifNfMao();
ZfifNfMaoResponse response = (ZfifNfMaoResponse)getWebServiceTemplate().marshalSendAndReceive(link, zfifNfMao);
return response;
}
}
推荐阅读
- mongodb - MongoDB 不使用我的索引(数组,布尔值)
- mysql - 使用 MySQL 中的过程将多个条目插入表中
- .net - nuke-build nuke .tmp\shell-completion.yml 被另一个进程阻止
- visual-studio-code - 有没有办法在 VSCode 中跟踪构建时间并将其记录到文本文件中
- r - 如何将数值转换为 R 中的日期(与 excel 中的短日期相同)?
- python - Python 中 SVM 的可视化(2D)
- python - 使用pyodbc将python连接到sql server
- javascript - 如何从它的 p:inputNumber 更新 ap:slider?
- javascript - 访问 javascript 对象时未定义
- arrays - 为每个循环添加越来越多数据的数组循环