2

I have a java application that is consuming from one JMS queue, doing some processing, and then sending to an output queue.

While I'm testing, it'd be very handy to have a filesystem based JMS implementation for the output queue; such that any messages sent to it would just be written to a directory on disk.

Does anyone know if this exists? I've considered switching to an integration framework like apache-camel which has file based endpoints, but seems overkill for what I need right now. I'm using activemq, is it possible to configure an embedded broker to do this?

2 Answers 2

1

I would go for apache camel anyhow. It also saves you quite some boilerplate code to connect to activemq. If you are also using spring already its just a matter of adding a simple routebuilder and some xml configuration. The jars themselves are rather small so its a rather small bit of overhead to pay in return of a big amount of flexibility.

Sign up to request clarification or add additional context in comments.

1 Comment

Good choice. The standard distribution of ActiveMQ comes pre configured with a basic Camel setup anyway.
0

I think this approach of testing your jms related client code can get very complicated. If you need to spy on which messages where send from your application, consider using a QueueBrowser.

However, the code that receives the messages must have some sort of side effects (otherwise, it would not be useful). I would base the assertions on these rather then inspecting the message queues. This should be much easier and will most likely result in better tests.

3 Comments

I'm not really sure I understand your second paragraph, can you elaborate? Just to add a little more colour to this, the consumer of these messages isn't currently available and is provided by another team in the company.
I see. If you want to test the code that sends the messages in isolation (which is a perfectly valid thing to do, of course), I would set up an in-process AMQ Broker (by supplying a connection-string like "vm://test" to the connection factory) and register a consumer in your test which puts all messages it receives in a list. Then, run your producer code and inspect the messages that where sent. Because JMS messaging runs asynchronously, you may have to wait a few millis befor examine the messages.
Yup, I'm already using an embedded broker as part of unit testing to make sure that my message consumption is working as expected. I also have full unit test code coverage over my message production code. I just really want a simple way have my system running, consuming messages, logging metrics etc. but producing files instead of JMS messages so I theoretically I can just be fully ready to go, and just flip a switch over to a real JMS queue when that's ready.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.