Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Copy Messages from one ActiveMQ instance to another with Apache Camel and Groovy
import org.apache.activemq.camel.component.ActiveMQComponent
import org.apache.camel.CamelContext
import org.apache.camel.builder.RouteBuilder
import org.apache.camel.impl.DefaultCamelContext
class CopyFromOneServerToAnother extends RouteBuilder{
public static void main(String[] args) {
final CamelContext camelContext = new DefaultCamelContext();
// IP address for the queue I will be consuming messages from
camelContext.addComponent("jms-01", ActiveMQComponent.activeMQComponent("tcp://"));
// IP address for the queue I will be placing my consumed messages from
camelContext.addComponent("jms-02", ActiveMQComponent.activeMQComponent("tcp://"));
try {
// Add the routes defined below to the camel context
camelContext.addRoutes(new CopyFromOneServerToAnother());
catch (final Exception e) {
finally {
try {
catch (final Exception e) {
public void configure() throws Exception {
/// The name of the AMQ instance and queue where message will be taken from
// Simply log when each message has been processed
// Additional processors can be used here to alter messages, fix issue with them before being placed on the new queue
// Final resting point for each message.
Copy link

xpapad commented Dec 5, 2011

I'm facing a similar issue right now, just my two cents :) The first problem with your approach is that messages can be lost if there is a problem during delivery, therefore the route should be transactional. Another issue is that the default shutdown strategy suspends an endpoint when you close a route. This will prevent other routes from consuming messages from your source queue. If this is an issue in your case, you should lower the timeout of the shutdown strategy in your Camel context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment