我有一个用于测试某些实体的模板
@Component
public class TestEntityXListener extends TestAbstractConsumer<EntityX> {
@Override
@KafkaListener(id = "entity1Listener", topicPattern = "company.v1.cqrs.entityX", containerFactory = "kafkaListenerContainerFactory")
public void onMessage(final ConsumerRecord<MessageKey, GenericRecord> consumerRecord) {
log.info("XListener HashCode:"+System.identityHashCode(this));
super.onMessage(consumerRecord);
}
}
最后,我的实体测试如下:
public class EntityXIntegrationTestIT extends AbstractIntegrationTestIT {
@Autowired private TestEntityXListener entityXListener;
@Test
public void doTest() throws InterruptedException {
log.info("XListener HashCode:"+System.identityHashCode(this.entityXListener));
//Execute service that produces Kafka events (logs show correct sending and consumption)
}
}
当我在本地(Win10)上进行mvn测试时,此代码通过绿色,并且侦听器的所有注入都具有相同的identityHashcode。但是,当我在远程管道中执行此操作时,似乎在测试中注入的侦听器实例与事件到达时正在处理的侦听器实例不同