@RabbitListener method testing in SpringBoot app

前端 未结 1 1251
梦如初夏
梦如初夏 2021-02-13 06:31

Code:

RabbitMQListener:

@Component
public class ServerThroughRabbitMQ implements ServerThroughAMQPBroker {
    private static final AtomicLong ID_COUNTER         


        
1条回答
  •  无人及你
    2021-02-13 07:18

    RabbitMQ and Integration Testing can be hard, since Rabbit MQ keeps some kind of state: - messages from previous tests in queues - listeners from previous tests still listening on queues

    There are several approaches:

    • Purge all queues before you start the test (that might be what you mean by cleanTestQueues())
    • Delete all queues (or use temporary queues) and recreate them before each test
    • Using the Rabbit Admin Rest API killing listeners or connections of previous tests
    • delete the vhost and recreating the infrasture for each test (which is the most brutal way)

    0 讨论(0)
提交回复
热议问题