简体   繁体   English

Spring集成:与嵌入式Broker的自动化集成测试?

[英]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? 是否有可能(例如在内存中)启动代理,该代理可用于使用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? 我已经尝试使用ActiveMQ实现此目的(在https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-messaging.html之后 ),但不成功,也许有人成功了一个简短的工作示例?

It's not Spring Integration (Spring Boot) responsibility to provide some embedded broker for such a protocol. 提供这种协议的嵌入式代理不是Spring Integration(Spring Boot)的责任。 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. 如果有的话,我们可以考虑对该问题实施自动配置,类似于对嵌入式RDBMS,JMS和MongoDB所做的配置。 You really need to consult ActiveMQ documentation . 您确实需要查阅ActiveMQ文档

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. 我没有尝试过,但这正是我针对STOMP进行测试所要做的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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