I'm actively using ActiveMQ in my project. Although production use standalone ActiveMQ instance my tests require embedded ActiveMQ instance. After execution of particular test method ActiveMQ holds unprocessed messages in queues. I'd like to wipe out ActiveMQ instance after each test. I tried to use JMX to connect to local ActiveMQ instance and wipe out queues, but it's heavy-weight solution. Could anyone suggest me something more lightweight?
just turn off broker persistence when you define the broker URL for your unit tests
vm://localhost?broker.persistent=false
ActiveMQ has an option to delete all message on startup, if you use the XML way of configuring ActiveMQ broker, you can set it on the < activemq > tag,
<activemq:broker .... deleteAllMessagesOnStartup="true">
...
</activemq:broker>
Another approach could be to use unique data directories per unit test which is what we do when unit testing camel-jms component with embedded ActiveMQ broker. We have a helper class that setup ActiveMQ for us, depending on we needed persistent queues or not
https://git-wip-us.apache.org/repos/asf?p=camel.git;a=blob;f=components/camel-jms/src/test/java/org/apache/camel/component/jms/CamelJmsTestHelper.java;h=8c81f3e2bed738a75841988fd1239f54a100cd89;hb=HEAD
I believe you want to purge the queue. There are several options for that.
https://activemq.apache.org/how-do-i-purge-a-queue.html
from the link
"You can use the Web Console to view queues, add/remove queues, purge queues or delete/forward individual messages. Another option is to use JMX to browse the queues and call the purge() method on the QueueViewMBean. You could also delete the queue via removeQueue(String) or removeTopic(String) methods on the BrokerViewMBean. You can also do it programmatically"
The link describes each option in details
Related
I am currently testing out JMS queue (first time using JMS) and message driven beans.
I have created a queue to provide other applications with state updates for one of our projects.
Logic is written in native JMS, deployed on a JBOSS7 using the ActiveMQ implementation.
It depends on a selector to deliver the messages to the right client, and while I can just place good faith in my colleagues, preferably I would like to enforce the use of the selector so the clients don't consume messages not meant for them.
So basically I would prefer that no messages are delivered to a client which has not specified a selector.
When I deploy a consumer without any selector it just consumes all messages available on the queue.
Otherwise everything works as expected.
I have looked and haven't been able to find anything I am looking for, maybe it's possible by configuring ActiveMQ itself but I am not really at home in that ecosystem.
So the problem is resolved by using a system I wasn't that aware about and I thought I'd share it here if someone need it:
The JMS clients are on different physical machines so originally the plan was to do manual JNDI remote lookup to access the queue but this caused some problems. Mainly having to write retry logic when the Queue is unavailable.
I threw that plan out the window to opt for a Bridge instead, following the guide found here: http://www.mastertheboss.com/howto/jboss-jms6/configuring-jms-bridge-with-wildfly-10
This has multiple advantages (both the producer system or the client can go down without causing too many problems) but most notably this solves my problem: I can define a selector on the bridge per Client. So the responsibility of choosing who receives which messages is back in my court.
I will have a crack at implementing this.
I have a vm://localhost in-memory activemq setting on an Spring Boot JMS project.
My controllers send events to a particular topic, and some tests check the events are properly sent with #JmsMessagingTemplate. The problem is when I execute multiple tests at the same time, some pf them fail because they are getting the unexpected event.
How can I fix that? I tried to play with acknowledge modes, concurrent users, exclusive consumers, jms.listener.max-concurrency, activemq pool configuration...
You should do one of the following:
Start an instance of in-memory ActiveMQ for each test (group of tests). For example you may use embedded broker to spawn multiple instances.
Dynamically generate unique topic name for test and create separate topic for each test.
I Created Java message listener, how to monitor or alert when listener is down.
I have tried with JConsole is there any other way I should use.
If the message broker you are using ships with a web console, you can use that. Like these for rabbitmq and activemq:
https://www.rabbitmq.com/management.html
http://activemq.apache.org/web-console.html
ActiveMQ provides Advisory Messages, which allows you to watch the system using regular JMS messages.
Also note that what is "visible" with JConsole can be accessed programmatically, using JMX. Have a look at How to programmatically check JMX MBean operations and attributes?. JMX mbeans, attributes and operation can also been accesses through HTTP with Jolokia.
I'm confronted with a system (Java, OSGI-based, Equinox, Blueprint) that needs to send asynchronous notifications via SOAP messages to a remote system. The system must ensure that the notifications reach the remote system (i.e. it reponses with a confirmation message, WS-ReliableMessaging is not available).
Now I see two Options:
Use the EventAdmin mechanism of OSGI to trigger the notifications, implement my own handler which persists the notification in a queue. A quartz job would poll the queue and try to send the Soap message. The message would only be removed from the queue if the remote system reponses successfully.
Use a messaging middleware like ActiveMQ (e.g. as part of Apache Servicemix) to make use of JMS and make the whole task a lot easier.
What do you suggest?
Take JMS, if you go for 1 you'll end up implementing some of the stuff that is already provided by a JMS system. OSGi events are nice, but after a shutdown of the container they are gone. So this will be at least one of the drawbacks that you'll have to re-implement that a JMS messaging system like ActiveMQ already provides.
I have two systems: HQ on Linux and Active MQ on windows
Both systems need to send and receive message between each other.
Anyone implemented a way of integrating between them?? In this case I would like to have an example
Thanks,
ray.
JMS providers in general are not interoperable, because there is no common internal message format, or the connection protocol.
The perfect solution would be unifying the providers, so that both systems use the same (could be different instances — don't know about HQ, but ActiveMQ can send to another ActiveMQ).
If this is not acceptable, you can always write adapters yourself, with message-driven beans. One MDB would listen on an MQ queue, to repack the message and forward to ActiveMQ; the other MDB would do the same other way round. The exact setup and configuration of connection factories and queues depends on the application server.
ActiveMQ provides a solution for this scenario, its called a JMS to JMS bridge this allows you to bridge destinations between JMS brokers either inbound, outbound or both. Have a look at the documentation at the link above.