嵌入式AMQP Java代理 [英] Embedded AMQP Java Broker
问题描述
我正在尝试为连接到RabbitMQ代理的Scala/Java应用程序创建集成测试.为了实现这一点,我希望有一个嵌入式经纪人讲我在每次测试之前启动和停止的AMQP.最初,我试图将ActiveMQ引入AMQP作为嵌入式代理,但是该应用程序使用RabbitMQ,因此只能使用0.9.3版本的AMQP,而ActiveMQ需要1.0版本的AMQP.
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代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!