JMS "pipocando" com um load maiorzinho

Olá pessoal

Tenho a seguinte classe para envio de mensagem para o MQ:

[code]package test.mq;

import javax.jms.DeliveryMode;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;

import mapl.util.logging.Level;
import mapl.util.logging.http.TrataErroClass;

import test.exception.ManagerQueueException;
import test.exception.ServiceLocatorException;
import test.util.*;

public class ManagerQueue {

/**
 * Fields
 */
private TrataErroClass objTrataErro;

/**
 * Constructor
 */
public ManagerQueue(){
	objTrataErro = new TrataErroClass(this);
}

/**
 * Puts the message into the Queue.
 * Uses the queue and queueFactory 
 * provided as argument unless null
 * values are passed, and in that 
 * case it will read the value from 
 * config.properties:
 *  - jndi.queueName
 * 	- jndi.queueFactory
 * 
 * @param message
 * @throws ManagerQueueException
 */
public void sendMessage(String message, String queueName, String queueFactoryName) throws ManagerQueueException {
	QueueSender objQueueSender = null;
	QueueSession objQueueSession = null;
	QueueConnection objQueueConnection = null;
	final String JMS_QUEUE;
	if (queueName == null)    		
		JMS_QUEUE = Property.getString("jndi.queueName");
	else    		
		JMS_QUEUE = queueName;
	
	final String JMS_QUEUE_FACTORY;
	if (queueFactoryName == null)
		JMS_QUEUE_FACTORY = Property.getString("jndi.queueFactory");
	else
		JMS_QUEUE_FACTORY = queueFactoryName;
	
	objTrataErro.performLogaMensagem(Level.INFO, "Got parameters for sending message: JMS_QUEUE:" + JMS_QUEUE + " JMS_QUEUE_FACTORY:" + JMS_QUEUE_FACTORY);
	
	try {
		//Finds Queue Factory
		QueueConnectionFactory objQueueConnectionFactory = (QueueConnectionFactory)ServiceLocator.getInstance().lookup(JMS_QUEUE_FACTORY);
		//Finds Queue
		Queue objQueue = (Queue)ServiceLocator.getInstance().lookup(JMS_QUEUE);
		//Connects to Queue
		objQueueConnection = objQueueConnectionFactory.createQueueConnection();
		//Starts a Session
		objQueueSession = objQueueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
		//Creates a Queue Sender.
		objQueueSender = objQueueSession.createSender(objQueue);
		//Sets Delivery Mode
		objQueueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
		//Starts Connections
		objQueueConnection.start();
		//Creates Text Message
		TextMessage objTextMessage = objQueueSession.createTextMessage();
		//Sets the message value
		objTextMessage.setText(message);
		//Sends the message into the queue
		objQueueSender.send(objTextMessage);
		
	} catch (ServiceLocatorException e) {
		throw new ManagerQueueException("Error when locating QueueConnectionFactory: " + e.getMessage());
	} catch (JMSException e) {	
		if (e.getLinkedException() == null)
			throw new ManagerQueueException("Error sending message: " + e.getMessage());
		else
			throw new ManagerQueueException("Error sending message: " + e.getMessage() + "\nLinkedException: " + e.getLinkedException() + "\nLinkedException Cause:" + e.getLinkedException().getCause());
	} catch (Exception e) {
		throw new ManagerQueueException("Error sending message: " + e.getMessage());
	} catch (Throwable e) {
		throw new ManagerQueueException("(Throwable)Error sending message: " + e.getMessage());			
	} finally {
		try {
			if(objQueueSender != null) objQueueSender.close();
			if(objQueueSession != null) objQueueSession.close();
			if(objQueueConnection != null) objQueueConnection.close();
		} catch (Exception e) {
			throw new ManagerQueueException("Error closing message: " + e.getMessage());
		}
	}
}

}[/code]

Mas quando temos uma carga maior, 1000 mensagem em alguns minutos vemos todo tipo de erro, a maioria relacionados a desconexão:

MQJMS2008 ? Não consegue abrir a fila;
MQJMS2000 ? Não consegue fechar uma fila que estava previamente aberta;

A causa para esse problema foi o erro:

J2CA0056I ? Que indica um problema na conexão com a fila (geralmente timeout), capturada pelo WebSphere (de acordo com documentação que achei)

Mesmo com esses erros a maioria das mensagens ainda são entregues.

O que fazer para tornar o meu código mais robusto?

Quando você faz um teste de carga, normalmente dá uma pausa entre uma mensagem e outra. Por exemplo, se você vai simular 1000 mensagens por segundo, precisa dar uma pausa de 1ms entre uma mensagem e outra.

Oi Thingol (sempre você :smiley: )

Estamos fazendo os testes de uma aplicação externa, que chama um web service que acessa essa classe que coloca as mensagens na fila (cada mensagem tem comprimento de mais de 3500 caracteres).

Você acha que 1 milisegundo entre cada envio vai fazer alguma diferença??

O código que estou usando parece correto?

Parece estar OK, talvez você tenha de ver se algum parâmetro (de rede ou do próprio MQ Series) deva ser modificado para aguentar o tranco.