Spring 集成:使用嵌入式 Broker 进行自动集成测试?

Spring Integration: Automated integration tests with embedded Broker?

是否有可能在内存中启动一个可用于使用 Spring 集成 MQTT 执行自动化测试用例的代理? 我已经尝试使用 ActiveMQ 实现此目的(遵循 https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-messaging.html)但不知何故没有成功,也许有人有一个简短的工作示例?

为此类协议提供一些嵌入式代理不是 Spring 集成(Spring 启动)的责任。如果有的话,我们可以考虑在这个问题上实现自动配置,类似于我们对嵌入式 RDBMS、JMS 和 MongoDB 所做的。你真的需要咨询ActiveMQ documentation.

看来我们可以在测试中这样做 class:

private static BrokerService activeMQBroker;

...

@BeforeClass
public static void setup() throws Exception {
        activeMQBroker = new BrokerService();
        activeMQBroker.addConnector("mqtt://localhost:1883");
        activeMQBroker.setPersistent(false);
        activeMQBroker.setUseJmx(false);
        activeMQBroker.start();
}

我没有尝试过,但这正是我针对 STOMP 所做的测试。