简体   繁体   中英

Testing RabbitMQ and Spring Integration

I'm developing an application with Spring Integration and RabbitMq and I'm wondering how to test it (integration tests).

I think SoapUI can be a great Solution but it doesn't support RAbbitMq, hermesjms.com has support for Qpid so i thought that could be easy to do a new plugin to support Rabbitmq but it's being more difficult than I thought due to the project is a little old and has a bunch of dependencies. So I'm starting to think in doing something myself, like a DSL in python, something like this:

tests = [{ 'name': 'start',
    'routing_key': 'returned',
    'payload' : "xxxxx",
    'timeOut' : '10000',
    'expected': '',
    'threads': '1'
},
{ 'name': 'second',.....
]

And then with Pika execute the actions and check the results.

I know it's very stupid and sopaui is huge and awesome, but at least it'd allow me to do small tests.

What would you recommend?

RabbitMQ provides you a Webfrontend (so called Management View 1 ).

So: What exactly do you want to test? Let's say, you want to verify that an incoming message on requestChannel down to the service and back, you could just autowire the channel directly (ie @Autowired private Channel requestChannel; ) and put a message into it.

However, only if you design your architecture right: Each step of your process can be tested using mocks or special modified injected dependencies.

In addition to you own components, these testability applies for the spring components (interfaces). Let's say, you have implement your own router: Test und verify in- and output. The same is for a transformer.

If you try to verify the "bic picture", you will have to rebuild the complete scenario. But this should not be so complicated with non persistent and non durable queues and messages.

Is there something else you want test?

For rabbitMq, my advice is to use a real RabbiMQ: this can be done by using Vagrant with chef for provisioning the RabbitMq and the Vagrant maven plugin to start the Box before Integration tests and halt it in the post phase of integration tests:

The Vagrant Maven plugin: http://nicoulaj.github.io/vagrant-maven-plugin/

Vagrant WebSite: http://www.vagrantup.com/

Cookbook Chef for RabbitMQ: https://github.com/opscode-cookbooks/rabbitmq

To Summarize you must:

  1. Install Vagrant and create an empty Box(Centos or Ubunutu).
  2. provision the VM with rabbitMQ cookbook.
  3. place.box into you home folder (rabbitMQ.box).
  4. Configure you maven Project to start the VM with vagrant up (~/rabbitMQ.box) in the pre phase of integration tests.
  5. Configure you maven Project to stop the VM with vagrant halt (~/rabbitMQ.box) in the pre phase of integration tests.

Hope that this help

RabbitMQ now has an HTTP API so you could use this instead of its JMS

http://hg.rabbitmq.com/rabbitmq-management/raw-file/rabbitmq_v2_8_4/priv/www/api/index.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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