Skip to content

Instantly share code, notes, and snippets.

@scholzj
Created October 23, 2015 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scholzj/45dfc385a06c7ac971a8 to your computer and use it in GitHub Desktop.
Save scholzj/45dfc385a06c7ac971a8 to your computer and use it in GitHub Desktop.
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