Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Closing of receiver on top of tx session
package org.apache.qpid.jms.transactions;
import org.apache.qpid.jms.support.AmqpTestSupport;
import org.junit.Test;
import javax.jms.*;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
* Created by schojak on 23.10.15.
*/
public class JmsTransactedReceiverCloseTest extends AmqpTestSupport {
@Test(timeout = 60000)
public void testReceiverClose() throws Exception {
connection = createAmqpConnection();
connection.start();
Session mgmtSession = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
Queue queue = mgmtSession.createQueue(name.getMethodName());
// Sender
Session session1 = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
MessageProducer sender = session1.createProducer(queue);
sender.send(session1.createMessage());
session1.commit();
// Tx Receiver with Rollback
Session session2 = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
MessageConsumer receiver2 = session2.createConsumer(queue);
Message received2 = receiver2.receive(1000);
assertNotNull("receiver3 didn't received the message", received2);
session2.rollback();
receiver2.close();
// Normal Receiver
Session session3 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer receiver3 = session3.createConsumer(queue);
Message received3 = receiver3.receive(1000);
assertNotNull("receiver3 didn't received the message", received3);
receiver3.close();
connection.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment