Broker 10.5 | webMethods Broker Documentation | webMethods Broker Messaging Programmer's Guide | JMS Policy Based Client-Side Clustering | Samples | Sample 2: Defining Multisend Best Effort Policy in a Cluster
 
Sample 2: Defining Multisend Best Effort Policy in a Cluster
This sample demonstrates how you can configure your cluster to use the multisend best effort policy using the webMethods API for JMS.
*To configure the cluster to use the multisend best effort policy
1. Create the connection factory using the webMethods API for JMS.
2. Set the load balancing policy as multisend best effort for the connection factory.
3. Set the Brokers in the cluster.
4. Set the maximum number of receiving Brokers in the connection factory.
5. Create the JMS connection, JMS session and the message producer.
6. Publish messages using the message producer.
WmQueueConnectionFactoryImpl queueCF = null;

queueCF = (WmQueueConnectionFactoryImpl)
WmJMSFactory.getQueueConnectionFactory();

// set the JMS Client group
queueCF.setClientGroup(clientGroup);

// set the brokers in the cluster
factory.setBrokerCluster( new String[] {"Broker1@localhost:6849",
"Broker2@localhost:6949",
"Broker3@localhost:7010"} );

// set the load balancing policy as Multi Send Best effort
queueCF.setClusterPolicy(WmClusterPolicyManager.MULTISEND_BEST_EFFORT);

// set the maximum number of brokers count
queueCF.setMultiSendCount(2);

QueueConnection queueConnection = (QueueConnection)
queueCF.createQueueConnection();
queueConnection.start();

QueueSession queueSession = queueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);

MessageProducer producer = queueSession.createProducer(queue);

TextMessage message = null;

for (int i = 0; i < 10; ++i)
{
message = queueSession.createTextMessage();
message.setText("QueueMessage " + i);
producer.send(message);
}

producer.close();
queueSession.close();
queueConnection.close();