Fails to commit transaction
edc May 18, 2006 7:41 PMPlaying around with the default example queue, I thought I would try to commit a transaction of sends. I decided to break it with Ctrl-C, and it has never worked since. Tried server reboot, still no luck. Does anybody know the status of transactional support?
import java.util.ResourceBundle;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueConnection;
import javax.jms.QueueSession;
import javax.jms.QueueSender;
import javax.jms.QueueReceiver;
import javax.jms.Queue;
import javax.jms.Message;
import javax.jms.TextMessage;
//Import the classes to use JNDI.
import javax.naming.*;
public class JbossJmsSend {
/**
* Main method.
*
* @param args not used
*
*/
public static void main(String[] args) {
ResourceBundle rb = ResourceBundle.getBundle("jndi");
QueueSession myQSess=null;
QueueConnection conn=null;
try {
InitialContext iniCtx = new InitialContext();
ConnectionFactory cf = (ConnectionFactory) iniCtx.lookup("/ConnectionFactory");
QueueConnectionFactory myQConnFactory = (QueueConnectionFactory) cf;
conn = myQConnFactory.createQueueConnection();
//myQSess = conn.createQueueSession(false,QueueSession.AUTO_ACKNOWLEDGE);
myQSess = conn.createQueueSession(true,-1);
//QueueSession myQSess = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue myQueue = (Queue) iniCtx.lookup("/queue/testQueue");
//Create a QueueSender message producer.
QueueSender myQueueSender = myQSess.createSender(myQueue);
//Create and send a message to the queue.
TextMessage myTextMsg = myQSess.createTextMessage();
int i=0;
for (i=1; i<=100; i++)
{
myTextMsg.setText("Hello Mantech-IST from Ed Chwalik: msg_ID = " + i);
//System.out.println("Sending Message: " + myTextMsg.getText());
myQueueSender.send(myTextMsg);
if (i%10==0)
{
System.out.println("Total sent messages = " + i);
myQSess.commit();
} }
i--;
System.out.println("Total sent messages = " + i);
//session.commit();
//Create a QueueReceiver message consumer.
//QueueReceiver myQueueReceiver = myQSess.createReceiver(myQueue);
//Start the QueueConnection created in step 3.
conn.start();
//Receive a message from the queue.
//Message msg = myQueueReceiver.receive();
//Retreive the contents of the message.
//TextMessage txtMsg = (TextMessage) msg;
//System.out.println("Read Message: " + txtMsg.getText());
//myQSess.close();
//conn.close();
} catch (Exception jmse) {
System.out.println("Exception occurred : " + jmse.toString());
jmse.printStackTrace();
}
//Close the session and connection resources.
finally{
try {
myQSess.close();
} catch (JMSException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
}
try {
conn.close();
} catch (JMSException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
}
// wnat to close sessions here!
}
}
}