This example demonstrates how you can configure a live server to scale down messages to another live server on shutdown.
This example starts 2 live servers each one with a connector configured for the other live server.
The second live server is killed and its messages are scaled down to the first server on shutdown.
The following shows how to configure the live servers to scale down to one another.
<ha-policy template="NONE">
<scale-down>true</scale-down>
<scale-down-connectors>
<connector-ref>server1-connector</connector-ref>
</scale-down-connectors>
notice that we have used a template to set some sensible defaults but overridden the backup strategy so back ups are full servers
To run the example, simply type mvn verify
from this directory
initialContext1 = getContext(1);
initialContext = getContext(0);
Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");
ConnectionFactory connectionFactory = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
ConnectionFactory connectionFactory1 = (ConnectionFactory)initialContext1.lookup("/ConnectionFactory");
connection = connectionFactory.createConnection();
connection1 = connectionFactory1.createConnection();
Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
Session session1 = connection1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(queue);
MessageProducer producer1 = session1.createProducer(queue);
for (int i = 0; i < numMessages; i++)
{
TextMessage message = session.createTextMessage("This is text message " + i);
producer.send(message);
System.out.println("Sent message: " + message.getText());
message = session1.createTextMessage("This is another text message " + i);
producer1.send(message);
System.out.println("Sent message: " + message.getText());
}
killServer(0);
connection.start();
MessageConsumer consumer = session.createConsumer(queue);
TextMessage message0 = null;
for (int i = 0; i < numMessages; i++)
{
message0 = (TextMessage)consumer.receive(5000);
System.out.println("Got message: " + message0.getText());
}
message0.acknowledge();
finally
block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
finally
{
if (connection != null)
{
connection.close();
}
if (initialContext != null)
{
initialContext.close();
}
if (connection1 != null)
{
connection1.close();
}
if (initialContext1 != null)
{
initialContext1.close();
}
}