Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonyfs/55b346e0e0c3d9d8530fdfbd00bb3113 to your computer and use it in GitHub Desktop.
Save jonyfs/55b346e0e0c3d9d8530fdfbd00bb3113 to your computer and use it in GitHub Desktop.
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://172.31.100.01:61616"));
// IP address for the queue I will be placing my consumed messages from
camelContext.addComponent("jms-02", ActiveMQComponent.activeMQComponent("tcp://172.31.100.02:61616"));
try {
// Add the routes defined below to the camel context
camelContext.addRoutes(new CopyFromOneServerToAnother());
camelContext.start();
Thread.sleep(10000000);
}
catch (final Exception e) {
e.printStackTrace();
}
finally {
try {
camelContext.stop();
}
catch (final Exception e) {
e.printStackTrace();
}
}
}
@Override
public void configure() throws Exception {
/// The name of the AMQ instance and queue where message will be taken from
from("jms-01:some-broken-queue")
// 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
.log("Processed")
// Final resting point for each message.
.to("jms-02:some-fixed-queue")
.end();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment