try
{
TransportConfiguration configurationSource = new TransportConfiguration(NettyConnectorFactory.class.getName(), sourceParameters);
ServerLocator locatorSource = HornetQClient.createServerLocator(false, configurationSource);
ClientSessionFactory factorySource = locatorSource.createSessionFactory();
ClientSession sessionSource = factorySource.createSession(sourceUser, sourcePass, false, false, false, false, 0);
ClientConsumer consumer;
if (filter == null)
{
consumer = sessionSource.createConsumer(queue);
}
else
{
consumer = sessionSource.createConsumer(queue, filter);
}
TransportConfiguration configurationTarget = new TransportConfiguration(NettyConnectorFactory.class.getName(), targetParameters);
ServerLocator locatorTarget = HornetQClient.createServerLocatorWithoutHA(configurationTarget);
ClientSessionFactory factoryTarget = locatorTarget.createSessionFactory();
ClientSession sessionTarget = factoryTarget.createSession(targetUser, targetPassword, false, false, false, false, 0);
ClientProducer producer = sessionTarget.createProducer(producingAddress);
sessionSource.start();
int countMessage = 0;
while (true)
{
ClientMessage message = consumer.receive(waitTimeout);
if (message == null)
{
break;
}
message.acknowledge();
if (!message.containsProperty("_HQ_TOOL_original_address"))
{
message.putStringProperty("_HQ_TOOL_original_address", message.getAddress().toString());
}
LinkedList<String> listToRemove = new LinkedList<String>();
for (SimpleString name : message.getPropertyNames())
{
if (name.toString().startsWith("_HQ_ROUTE_TO"))
{
listToRemove.add(name.toString());
}
}
for (String str: listToRemove)
{
message.removeProperty(str);
}
producer.send(message);
if (countMessage++ % commit == 0)
{
System.out.println("Sent " + countMessage + " messages");
sessionTarget.commit();
sessionSource.commit();
}
}
sessionTarget.commit();
sessionSource.commit();
consumer.close();
producer.close();
sessionSource.close();
sessionTarget.close();
locatorSource.close();
locatorTarget.close();
}