简体   繁体   中英

Spring Integration: Automated integration tests with embedded Broker?

Is it in a way possible to, say in memory, start a broker that can be used to execute automated test cases using Spring Integration MQTT? I've tried achieving this with ActiveMQ (following https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-messaging.html ) but somehow didn't succeed, maybe anyone has a short working example?

It's not Spring Integration (Spring Boot) responsibility to provide some embedded broker for such a protocol. If there is one, we could consider to implement an auto-configuration on the matter , similar to what we do for embedded RDBMS, JMS and MongoDB. You really need to consult ActiveMQ documentation .

Looks like we can do it like this in the test 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();
}

I didn't try it, but this is exactly what I do to test against STOMP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM