Joh*_*han 2 java spring integration-testing rabbitmq spring-amqp
我有一个发布事件E1的A类.在使用注释的同一应用程序中,B类消耗E1 @RabbitListener.B做了一些事情,然后发布了由C等消耗的事件E2(形成一个流程链).
我想做的是两件事:
RabbitListener's以便不执行作为E1发布结果的整个过程.我只想断言A做了它应该做的并发布了E1.我已设法通过设置来适应这一点spring.rabbitmq.listener.auto-startup=false.RabbitListerner正确配置了B. 但我再次不希望C被称为E2的副作用.我知道我可以使用模拟做到这一点但最好我想测试真实的交易并使用实际的组件(包括将消息发送到我的案例中运行在Docker中的实际RabbitMQ实例).
我可以在Spring Boot中以一种很好的方式实现这一目标吗?或者是否可能建议使用@RabbitListenerTest并确实使用模拟?
在@RabbitListener拥有id财产:
/**
* The unique identifier of the container managing for this endpoint.
* <p>If none is specified an auto-generated one is provided.
* @return the {@code id} for the container managing for this endpoint.
* @see org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry#getListenerContainer(String)
*/
String id() default "";
Run Code Online (Sandbox Code Playgroud)
然后RabbitListenerEndpointRegistry#getListenerContainer(String)返回MessageListenerContainer并且您已经可以控制start()/stop()单个@RabbitListener处理程序.