我有一个spring云项目,它有一个绑定到messagebus kafka和rabbitmq的模块。在本单元中,我对Kafka进行了测试:
@ActiveProfiles("test")
@DirtiesContext
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = MessageReceiverTestConfiguration.class,
initializers = ConfigFileApplicationContextInitializer.class)
@EnableBinding(MessageReceivingChannel.class)
public class MessageReceiverITest {
@Autowired
private MessageReceivingChannel messageReceivingChannel;
@MockBean
private MessageConsumerService messageConsumerService;
@Autowired
private MessageConverter messageConverter;
@Autowired
private MessageReceiverTestConfiguration receiverTestConfiguration;
@Captor
private ArgumentCaptor<ImportantMessage> captorMessage;
@Captor
private ArgumentCaptor<MessageHeaders> captorHeaders;
@Test
public void testLoanApplicationChannelInput() throws Throwable {
final ImportantMessage sentMessage = new ImportantMessage("qwer124asdf");
final Map<String, Object> headerMap = new HashMap<>(1);
headerMap.put(MessageHeaders.CONTENT_TYPE, receiverTestConfiguration.getContentType());
MessageHeaders sentHeaders = new MessageHeaders(headerMap);
final Message<?> message = messageConverter.toMessage(sentMessage, sentHeaders);
messageReceivingChannel.input().send(message);
TimeUnit.SECONDS.sleep(1);
verify(messageConsumerService).takeActionOn(captorMessage.capture(), captorHeaders.capture());
final Object receivedMessage = captorMessage.getValue();
Assertions.assertThat(receivedMessage).isNotNull();
Assertions.assertThat(receivedMessage).isEqualTo(sentMessage);
MessageHeaders receivedHeaders = captorHeaders.getValue();
Assertions.assertThat(receivedHeaders).isNotNull();
Assertions.assertThat(receivedHeaders.get(MessageHeaders.CONTENT_TYPE).toString())
.isEqualTo(sentHeaders.get(MessageHeaders.CONTENT_TYPE));
}
}
在ide(idea)中运行很好。
问题是,当我尝试安装maven artifact时,它没有通过验证阶段,因为:
org.springframework.context.ApplicationContextException: Failed to start bean 'inputBindingLifecycle'; nested exception is java.lang.IllegalStateException: A default binder has been requested, but there is more than one binder available for 'org.springframework.cloud.stream.messaging.DirectWithAttributesChannel' : kafka,rabbit, and no default binder has been set.
这就是我设置默认活页夹的方法 test/resources/application-test.yml
:
logging:
config: classpath:logback-local.xml
spring:
cloud:
stream:
default:
contentType: application/*+avro
producer:
headerMode: embeddedHeaders
bindings:
messagereceived:
binder: kafka
contentType: "application/json"
default-binder: kafka
kafka:
binder:
configuration:
security:
protocol: SSL
ssl:
truststore:
location: ${JAVA_HOME}\lib\security\cacerts
password:***
type: JKS
kafka:
properties:
max.in.flight.requests.per.connection: 1
request.timeout.ms: 30000
max.block.ms: 3000
producer:
retries: 3
所以我的问题是如何设置 spring-cloud-starter-parent:Hoxton.SR9
合适吗?
谢谢你的建议!
暂无答案!
目前还没有任何答案,快来回答吧!