s2 = c2.createSession(true, Session.SESSION_TRANSACTED);
prod = sess.createProducer(destination);
consumer = sess.createConsumer(destination);
for (int i = 0; i < counter; ++i) {
SimpleTransferObject to = new SimpleTransferObject(requestName, i);
ObjectMessage msg = sess.createObjectMessage();
msg.setObject(to);
logger.info("Sending message with name " + to.getName());
ut.begin();
try {
prod.send(msg, Message.DEFAULT_DELIVERY_MODE, priority, Message.DEFAULT_TIME_TO_LIVE);
} finally {
ut.commit();
}
logger.info("Message sent.");
MessageReceiver.browse("After send", sess, destination, logger);
ut.begin();
try {
received = consumer.receive(1000);
if (received == null) throw new JMSException("Not received first time");
if (!to.equals(((ObjectMessage)received).getObject())) throw new JMSException("Wrong object inside: " + ((ObjectMessage)received).getObject());
} finally {
ut.rollback();
}
ut.begin();
try {
received = consumer.receive(2000);
if (received == null) throw new JMSException("Not received second time");
if (!to.equals(((ObjectMessage)received).getObject())) throw new JMSException("Wrong object inside: " + ((ObjectMessage)received).getObject());
} finally {
ut.commit();
}
}