Add a new "default redistribution policy" DistributedQueueExample and smoke
test
--------------------------------------------------------------------------------
Key: JBMESSAGING-907
URL:
http://jira.jboss.com/jira/browse/JBMESSAGING-907
Project: JBoss Messaging
Issue Type: Feature Request
Reporter: Ovidiu Feodorov
Assigned To: Ovidiu Feodorov
Fix For: 1.2.1
The development team came to the conclusion that the best choice for a default message
redistribution policy configuration - the configuration the release ships with - is
org.jboss.messaging.core.plugin.postoffice.cluster.NullMessagePullPolicy. This is the most
common case, and this is what should be the out-of-the-box configuration. However, this
renders the current DefaultQueueExample, which assumes a DefaultMessagePolicy, irrelevant.
It's actually worse, it breaks it.
I am changing the DistributedQueueExample to work with NullMessagePullPolicy, and so make
it work out-of-the-box. That also makes it extremely boring.
We need to add another DistributedQueueExample, that shows how DefaultMessagePullPolicy
works. It will require changing some configuration on the fly, so there is no time to
write and test it before 1.2.0.
This is the original example (the default distribution policy one):
---------------------------------------------------------------------------------------------------------------------------------
/**
* The example creates two connections to two distinct cluster nodes on which we have
previously
* deployed a distributed queue. The example creates and sends a message using a
connection, and
* attempts to receive the message using the other connection. This is an example of
message
* redistribution in clustered environment at work. The JBoss Messaging clustered Post
Offices
* need to be configured with a default message redistribution policy for this example to
work
* correctly.
*
* Since this example is also used as a smoke test, it is essential that the VM exits with
exit
* code 0 in case of successful execution and a non-zero value on failure.
*
* @author <a href="mailto:ovidiu@jboss.org">Ovidiu Feodorov</a>
* @version <tt>$Revision: 1001 $</tt>
*
* $Id: TopicExample.java 1001 2006-06-24 09:05:40Z timfox $
*/
public class DistributedQueueExample extends ExampleSupport
{
public void example() throws Exception
{
String destinationName = getDestinationJNDIName();
InitialContext ic = null;
Connection connection0 = null;
Connection connection1 = null;
try
{
// connecting to the first node
ic = new InitialContext();
ConnectionFactory cf =
(ConnectionFactory)ic.lookup("/ConnectionFactory");
Queue distributedQueue = (Queue)ic.lookup(destinationName);
log("Distributed queue " + destinationName + " exists");
// When connecting to a messaging cluster, the ConnectionFactory has the
capability of
// transparently creating physical connections to different cluster nodes, in a
round
// robin fashion ...
// ... so this is a connection to a cluster node
connection0 = cf.createConnection();
// ... and this is a connection to a different cluster node
connection1 = cf.createConnection();
// Let's make sure that (this example is also a smoke test)
assertNotEquals(getServerID(connection0), getServerID(connection1));
// Create a session and a producer on the first connection
Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer publisher = session0.createProducer(distributedQueue);
// Create another session and a consumer on the second connection
Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session1.createConsumer(distributedQueue);
ExampleListener messageListener = new
ExampleListener("MessageListener");
consumer.setMessageListener(messageListener);
// Start connection1, so we can receive the message
connection1.start();
// Send the message
TextMessage message = session0.createTextMessage("Hello!");
publisher.send(message);
log("The message was successfully sent to the distributed queue");
// Wait longer than clustered Post Office's "StatsSendPeriod",
which is usually 10 secs
messageListener.waitForMessage(15000);
message = (TextMessage)messageListener.getMessage();
log(messageListener.getName() + " received message: " +
message.getText());
assertEquals("Hello!", message.getText());
displayProviderInfo(connection0.getMetaData());
}
finally
{
if (ic != null)
{
try
{
ic.close();
}
catch(Exception e)
{
throw e;
}
}
try
{
if (connection0 != null)
{
connection0.close();
}
}
catch(JMSException e)
{
log("Could not close connection " + connection0 + ", exception
was " + e);
throw e;
}
try
{
if (connection1 != null)
{
connection1.close();
}
}
catch(JMSException e)
{
log("Could not close connection " + connection1 + ", exception
was " + e);
throw e;
}
}
}
protected boolean isQueueExample()
{
return true;
}
public static void main(String[] args)
{
new DistributedQueueExample().run();
}
}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira