Igor Artamonov
Igor Artamonov

Reputation: 35961

Simple Java AMQP server

Are there any simple AMQP server/broker implementation written in Java?

I need to use it for local integration 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.

Upvotes: 3

Views: 2561

Answers (3)

madmuffin
madmuffin

Reputation: 993

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.

Upvotes: 1

madmuffin
madmuffin

Reputation: 993

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.

Upvotes: 3

Romain Hippeau
Romain Hippeau

Reputation: 24375

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.

Upvotes: 1

Related Questions