use of javax.jms.IllegalStateException in project rabbitmq-jms-client by rabbitmq.
the class AcknowledgeAnomaliesQueueMessageIT method messageTestBase.
private void messageTestBase(MessageTestType mtt) throws Exception {
try {
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(QUEUE_NAME);
drainQueue(queueSession, queue);
QueueSender queueSender = queueSession.createSender(queue);
queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
for (int i = 0; i < 2; ++i) {
// send two messages
queueSender.send(mtt.gen(queueSession, (Serializable) queue));
}
} finally {
reconnect();
}
Message msgNotAcked = null;
try {
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, RMQSession.CLIENT_INDIVIDUAL_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(QUEUE_NAME);
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
msgNotAcked = queueReceiver.receive(TEST_RECEIVE_TIMEOUT);
mtt.check(msgNotAcked, (Serializable) queue);
Message msg2 = queueReceiver.receive(TEST_RECEIVE_TIMEOUT);
mtt.check(msg2, (Serializable) queue);
msg2.acknowledge();
// repeat acknowledgement: should be a no-op
msg2.acknowledge();
} finally // requeues unacknowledged messages
{
reconnect();
}
try {
// should get an illegal state exception
msgNotAcked.acknowledge();
} catch (IllegalStateException ise) {
// brilliant
} catch (Exception e) {
fail(String.format("Message acknowledged outside session gave wrong exception: %s", e));
}
{
queueConn.start();
// automatically acknowledged
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(QUEUE_NAME);
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
Message msg = queueReceiver.receive(TEST_RECEIVE_TIMEOUT);
mtt.check(msg, (Serializable) queue);
// repeat ack: should be a no-op
msg.acknowledge();
}
}
use of javax.jms.IllegalStateException in project activemq-artemis by apache.
the class ActiveMQRASession method commit.
/**
* Commit
*
* @throws JMSException Failed to close session.
*/
@Override
public void commit() throws JMSException {
if (cri.getType() == ActiveMQRAConnectionFactory.XA_CONNECTION || cri.getType() == ActiveMQRAConnectionFactory.XA_QUEUE_CONNECTION || cri.getType() == ActiveMQRAConnectionFactory.XA_TOPIC_CONNECTION) {
throw new TransactionInProgressException("XA connection");
}
lock();
try {
Session session = getSessionInternal();
if (cri.isTransacted() == false) {
throw new IllegalStateException("Session is not transacted");
}
if (ActiveMQRASession.trace) {
ActiveMQRALogger.LOGGER.trace("Commit session " + this);
}
session.commit();
} finally {
unlock();
}
}
use of javax.jms.IllegalStateException in project activemq-artemis by apache.
the class ActiveMQRASession method createTopic.
/**
* Create a topic
*
* @param topicName The topic name
* @return The topic
* @throws JMSException Thrown if an error occurs
*/
@Override
public Topic createTopic(final String topicName) throws JMSException {
if (cri.getType() == ActiveMQRAConnectionFactory.QUEUE_CONNECTION || cri.getType() == ActiveMQRAConnectionFactory.XA_QUEUE_CONNECTION) {
throw new IllegalStateException("Cannot create topic for javax.jms.QueueSession");
}
Session session = getSessionInternal();
if (ActiveMQRASession.trace) {
ActiveMQRALogger.LOGGER.trace("createTopic " + session + " topicName=" + topicName);
}
Topic result = session.createTopic(topicName);
if (ActiveMQRASession.trace) {
ActiveMQRALogger.LOGGER.trace("createdTopic " + session + " topic=" + result);
}
return result;
}
use of javax.jms.IllegalStateException in project activemq-artemis by apache.
the class ActiveMQRASession method createDurableSubscriber.
/**
* Create a durable topic subscriber
*
* @param topic The topic
* @param name The name
* @return The subscriber
* @throws JMSException Thrown if an error occurs
*/
@Override
public TopicSubscriber createDurableSubscriber(final Topic topic, final String name) throws JMSException {
if (cri.getType() == ActiveMQRAConnectionFactory.QUEUE_CONNECTION || cri.getType() == ActiveMQRAConnectionFactory.XA_QUEUE_CONNECTION) {
throw new IllegalStateException("Cannot create durable subscriber from javax.jms.QueueSession");
}
lock();
try {
Session session = getSessionInternal();
if (ActiveMQRASession.trace) {
ActiveMQRALogger.LOGGER.trace("createDurableSubscriber " + session + " topic=" + topic + " name=" + name);
}
TopicSubscriber result = session.createDurableSubscriber(topic, name);
result = new ActiveMQRATopicSubscriber(result, this);
if (ActiveMQRASession.trace) {
ActiveMQRALogger.LOGGER.trace("createdDurableSubscriber " + session + " ActiveMQTopicSubscriber=" + result);
}
addConsumer(result);
return result;
} finally {
unlock();
}
}
use of javax.jms.IllegalStateException in project activemq-artemis by apache.
the class ActiveMQRASession method createQueue.
/**
* Create a queue
*
* @param queueName The queue name
* @return The queue
* @throws JMSException Thrown if an error occurs
*/
@Override
public Queue createQueue(final String queueName) throws JMSException {
if (cri.getType() == ActiveMQRAConnectionFactory.TOPIC_CONNECTION || cri.getType() == ActiveMQRAConnectionFactory.XA_TOPIC_CONNECTION) {
throw new IllegalStateException("Cannot create browser or javax.jms.TopicSession");
}
Session session = getSessionInternal();
if (ActiveMQRASession.trace) {
ActiveMQRALogger.LOGGER.trace("createQueue " + session + " queueName=" + queueName);
}
Queue result = session.createQueue(queueName);
if (ActiveMQRASession.trace) {
ActiveMQRALogger.LOGGER.trace("createdQueue " + session + " queue=" + result);
}
return result;
}
Aggregations