問題描述
我正在嘗試為連接到 RabbitMQ 代理的 Scala/Java 應用程序創建集成測試.為了實現這一點,我想要一個能夠在每次測試之前啟動和停止的 AMQP 嵌入式代理.最初我嘗試將 ActiveMQ 作為 AMQP 的嵌入式代理引入,但是該應用程序使用 RabbitMQ,因此只使用 AMQP 0.9.3 版,而 ActiveMQ 需要 AMQP 1.0 版.
I am trying to create integration test for a Scala / Java application that connects to a RabbitMQ broker. To achieve this I would like an embedded broker that speaks AMQP that I start and stop before each test. Originally I tried to introduce ActiveMQ as an embedded broker with AMQP however the application uses RabbitMQ so only speaks AMQP version 0.9.3 whereas ActiveMQ requires AMQP version 1.0.
我可以使用另一個嵌入式代理來代替 ActiveMQ 嗎?
Is there another embedded broker I can use in place of ActiveMQ?
推薦答案
完全在內存中的解決方案.根據需要替換 spring.*
屬性.
A completely in-memory solution. Replace the spring.*
properties as required.
<dependency>
<groupId>org.apache.qpid</groupId>
<artifactId>qpid-broker</artifactId>
<version>6.1.1</version>
<scope>test</scope>
</dependency>
public class EmbeddedBroker {
public void start() {
Broker broker = new Broker();
BrokerOptions brokerOptions = new BrokerOptions();
brokerOptions.setConfigProperty("qpid.amqp_port", environment.getProperty("spring.rabbitmq.port"));
brokerOptions.setConfigProperty("qpid.broker.defaultPreferenceStoreAttributes", "{"type": "Noop"}");
brokerOptions.setConfigProperty("qpid.vhost", environment.getProperty("spring.rabbitmq.virtual-host"));
brokerOptions.setConfigurationStoreType("Memory");
brokerOptions.setStartupLoggedToSystemOut(false);
broker.startup(brokerOptions);
}
}
添加 initial-config.json
作為資源:
{
"name": "Embedded Test Broker",
"modelVersion": "6.1",
"authenticationproviders" : [{
"name": "password",
"type": "Plain",
"secureOnlyMechanisms": [],
"users": [{"name": "guest", "password": "guest", "type": "managed"}]
}],
"ports": [{
"name": "AMQP",
"port": "${qpid.amqp_port}",
"authenticationProvider": "password",
"protocols": [ "AMQP_0_9_1" ],
"transports": [ "TCP" ],
"virtualhostaliases": [{
"name": "${qpid.vhost}",
"type": "nameAlias"
}]
}],
"virtualhostnodes" : [{
"name": "${qpid.vhost}",
"type": "Memory",
"virtualHostInitialConfiguration": "{ "type": "Memory" }"
}]
}
這篇關于嵌入式 AMQP Java 代理的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!