Simple Java AMQP server
Are there any simple AMQP server/broker implementation written in Java?
I need to use it for local integratio开发者_如何学Pythonn tests. I would like to start it from ant/maven, and I don't need any features like clustering, persistence, performance and so on. Just a mock RabbitMQ-like instance, without installation (just as a dependency at maven pom) and configuration.
I'd say it is perfectly legal to write integration tests / end-to-end tests / automated user acceptance tests that test the whole application, including everything that is done within the MQs. You should select the test cases that fire up something like this wiesely, as it drastically slows down the feedback loop of your tests.
There is org.apache.qpid, which you can simply include in your application as mvn/gradle (mvn central) dependency (gradle example):
testCompile 'org.apache.qpid:qpid-broker:6.0.1'
and then add a Rule
containing a ExternalResource
that fires up the broker before your tests, somewhat similar to this rather simple setup:
@Rule
private static final ExternalResource embeddedAMQPBroker = new ExternalResource() {
Broker broker;
@Override
protected void before() throws Throwable {
BrokerOptions brokerOptions = new BrokerOptions();
brokerOptions.setConfigProperty("qpid.amqp_port", "55672");
broker = new Broker();
broker.startup(brokerOptions);
}
@Override
protected void after() {
broker.shutdown();
}
};
Untested, since for me this did not work, because all my applications contain Jetty 9 and QPID (still) requires a Jetty<9.
What you are looking for is an AMQP Mock Object. I really do not know of any and doubt that you will find any off the shelf.
If you are using JUnit as your testing then your are doing UNIT testing. Unit testing is different than integration testing and does not include actually reading/writing to a queue.
Maybe here you could restructure your test or even code to include everything but the read/write to the queue ?
Another option is if you have wrapped your AMQP into some other class for portability then just mock that object.
After publishing my answer in 2016, a new option has come to my attention just recently:
The RabbitMQ Mock (https://github.com/fridujo/rabbitmq-mock) project serves the exact purpose, and is much lighter in weight. It is still a very young project (only started in May 2018), but I was able to use it for integration tests myself.
In order to verify the mock works like "the real thing", I first run my code against a RabbitMQ instance, and switch to the mock thereafter.
精彩评论