我正在尝试测试配置了以下绑定的应用程序:
spring:
cloud:
stream:
bindings:
accountSource:
destination: account
producer:
useNativeEncoding: true
kafka:
binder:
brokers: ${KAFKA_BOOTSTRAP_ADDRESSES}
producer-properties:
schema.registry.url: ${KAFKA_SCHEMA_REGISTRY_URL}
value.subject.name.strategy: io.confluent.kafka.serializers.subject.RecordNameStrategy
bindings:
accountSource:
producer:
configuration:
key:
serializer: org.apache.kafka.common.serialization.StringSerializer
value:
serializer: io.confluent.kafka.streams.serdes.avro.SpecificAvroSerializer
正常运行应用程序时,AbstractMessageChannel.interceptorList
为空,并且向代理发送消息正常。
运行测试(使用spring-cloud-stream-test-support
活页夹)时,AbstractMessageChannel.interceptorList
填充了MessageConverterConfigurer
,并且正在使用内容类型序列化机制转换消息(Avro对象转换为JSON)。这是测试代码:
@RunWith(SpringRunner.class)
public class AccountServiceImplTest {
@Autowired
private AccountService accountService;
@Autowired
private MessageCollector messageCollector;
@Autowired
private MessageChannel accountSource;
@Test
public void create() {
// Simplified code
AccountCreationRequest accountCreationRequest = AccountCreationRequest.builder().company(company).subscription(subscription).user(user).build();
accountCreationRequest = accountService.create(accountCreationRequest);
Message<?> message = messageCollector.forChannel(accountSource).poll();
// execute asserts on message
}
@TestConfiguration
@ComponentScan(basePackageClasses = TestSupportBinderAutoConfiguration.class)
static protected class AccountServiceImplTestConfiguration {
@EnableBinding({KafkaConfig.AccountBinding.class})
public interface AccountBinding {
@Output("accountSource")
MessageChannel accountSource();
}
}
我是否缺少一些禁用spring-cloud-stream流序列化机制的东西?
答案 0 :(得分:0)
不要使用测试粘合剂;而是将Kafka活页夹与嵌入式kafka代理结合使用。