使用testchannelbinderconfiguration,但是注册了两个处理程序

cunj1qz1  于 2021-07-24  发布在  Java
关注(0)|答案(0)|浏览(350)

我有一个SpringCloudStream应用程序,它处理(信用卡)事件——其中一些是同步处理的,另一些是异步处理的。我在Kotlin大致得出了以下结论:
Spring Cloud始流兔=3.1.0

@Service
class CardEventProcessor(
    private val streamBridge: StreamBridge,
) : Consumer<AsyncCardEvent> {

    fun process(cardEvent: SyncCardEvent): Result { return businessLogic() }

    fun processAsynchronously(cardEvent: AsyncCardEvent) {
        streamBridge.send("cardEventProcessor-out-0", cardEvent)
    }

    override fun accept(cardEvent: AsyncCardEvent) { businessLogic() }
}

并将其配置为:

rabbitmq: ...
  cloud:
    stream:
      bindings:
        cardEventProcessor-in-0:
          destination: cardevents
          group: CardEventProcessor
        cardEventProcessor-out-0:
          destination: cardevents

这一切似乎都很正常,除了在集成测试中,处理在第二个异步卡事件之后失败。我能够调试/将问题减少到在中注册两个处理程序 UnicastingDispatcher ,它有一个循环策略:一个用于testchannelbinder,另一个用于outputdestination$lamdba。
这就是我的集成测试类的样子:

@SpringBootTest
@Transactional
@AutoConfigureMockMvc
@AutoConfigureEmbeddedDatabase
@Import(TestChannelBinderConfiguration::class)
class IntegrationTests {

    @Test
    fun `Use case one`() {
        sendFirstAsyncRequest()  // processed correctly in CardEventProcessor.accept()
        sendSecondAsyncRequest() // message never arrives in CardEventProcessor.accept()
    }
}

我一直在关注springcloudstreamdocs中的测试部分,但是我不知道我缺少了什么来让它工作。示例中有一个函数<>不是使用者<>并且我在与使用者相同的@service类中生成(因为队列只是解决异步问题的一个实现细节,而不是微服务之间队列的典型用例),但据我所知,它应该可以工作,而且实际上在不作为集成测试运行时也可以工作。
我看到禁用springcloudstreamrabbit进行测试,但不想依赖于弃用的 spring-cloud-stream-test-support 另外两个建议也不管用。有什么想法吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题