use of javax.jms.QueueReceiver in project iaf by ibissource.
the class PullingIfsaProviderListener method getRawMessage.
/**
* Retrieves messages to be processed by the server, implementing an IFSA-service, but does no processing on it.
*/
@Override
public Object getRawMessage(Map threadContext) throws ListenerException {
Object result = null;
QueueSession session = null;
QueueReceiver receiver = null;
threadContext.remove(THREAD_CONTEXT_ORIGINAL_RAW_MESSAGE_KEY);
try {
session = getSession(threadContext);
try {
receiver = getReceiver(threadContext, session);
result = receiver.receive(getTimeOut());
while (result == null && canGoOn() && !JtaUtil.inTransaction()) {
result = receiver.receive(getTimeOut());
}
} catch (Exception e) {
throw new ListenerException(getLogPrefix(), e);
} finally {
releaseReceiver(receiver);
}
} finally {
if (sessionNeedsToBeSavedForAfterProcessMessage(result)) {
threadContext.put(THREAD_CONTEXT_SESSION_KEY, session);
} else {
releaseSession(session);
}
}
if (result instanceof IFSAPoisonMessage) {
IFSAHeader header = ((IFSAPoisonMessage) result).getIFSAHeader();
String source;
try {
source = header.getIFSA_Source();
} catch (Exception e) {
source = "unknown due to exeption:" + e.getMessage();
}
String msg = getLogPrefix() + "received IFSAPoisonMessage " + "source [" + source + "]" + "content [" + ToStringBuilder.reflectionToString((IFSAPoisonMessage) result) + "]";
log.warn(msg);
}
try {
if ((result instanceof IFSATextMessage || result instanceof IFSAPoisonMessage) && JtaUtil.inTransaction()) {
threadContext.put(THREAD_CONTEXT_ORIGINAL_RAW_MESSAGE_KEY, result);
result = new MessageWrapper(result, this);
}
} catch (Exception e) {
throw new ListenerException("cannot wrap non serialzable message in wrapper", e);
}
return result;
}
use of javax.jms.QueueReceiver in project wildfly by wildfly.
the class MessageDrivenTimeoutTestCase method receiveMessage.
static String receiveMessage(Queue replyQueue, InitialContext initCtx) throws Exception {
QueueConnection connection = getConnection(initCtx);
connection.start();
try {
final QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
final QueueReceiver receiver = session.createReceiver(replyQueue);
final Message reply = receiver.receive(TimeoutUtil.adjust(5000));
// waiting for synchro could be finished before checking
Thread.sleep(TimeoutUtil.adjust(500));
if (reply == null)
return null;
return ((TextMessage) reply).getText();
} finally {
connection.close();
}
}
use of javax.jms.QueueReceiver in project activemq-artemis by apache.
the class QueueReceiverTest method testCreateReceiverWithMessageSelector.
/**
* com.sun.ts.tests.jms.ee.all.queueconn.QueueConnTest line 171
*/
@Test
public void testCreateReceiverWithMessageSelector() throws Exception {
QueueConnection qc = null;
try {
qc = createQueueConnection();
QueueSession qs = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueReceiver qreceiver = qs.createReceiver(queue1, "targetMessage = TRUE");
qc.start();
TextMessage m = qs.createTextMessage();
m.setText("one");
m.setBooleanProperty("targetMessage", false);
QueueSender qsender = qs.createSender(queue1);
qsender.send(m);
m.setText("two");
m.setBooleanProperty("targetMessage", true);
qsender.send(m);
TextMessage rm = (TextMessage) qreceiver.receive(1000);
ProxyAssertSupport.assertEquals("two", rm.getText());
} finally {
if (qc != null) {
qc.close();
}
Thread.sleep(2000);
removeAllMessages(queue1.getQueueName(), true);
checkEmpty(queue1);
}
}
use of javax.jms.QueueReceiver in project activemq-artemis by apache.
the class ActiveMQRASession method createReceiver.
/**
* Create a queue receiver
*
* @param queue The queue
* @return The queue receiver
* @throws JMSException Thrown if an error occurs
*/
@Override
public QueueReceiver createReceiver(final Queue queue) throws JMSException {
lock();
try {
QueueSession session = getQueueSessionInternal();
if (ActiveMQRASession.trace) {
ActiveMQRALogger.LOGGER.trace("createReceiver " + session + " queue=" + queue);
}
QueueReceiver result = session.createReceiver(queue);
result = new ActiveMQRAQueueReceiver(result, this);
if (ActiveMQRASession.trace) {
ActiveMQRALogger.LOGGER.trace("createdReceiver " + session + " receiver=" + result);
}
addConsumer(result);
return result;
} finally {
unlock();
}
}
use of javax.jms.QueueReceiver in project activemq-artemis by apache.
the class SimpleOpenWireTest method testTempQueueDelete.
@Test
public void testTempQueueDelete() throws Exception {
connection.start();
QueueSession queueSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue tempQueue = queueSession.createTemporaryQueue();
ActiveMQConnection newConn = (ActiveMQConnection) factory.createConnection();
try {
QueueSession newQueueSession = newConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueSender queueSender = newQueueSession.createSender(tempQueue);
Message msg = queueSession.createMessage();
queueSender.send(msg);
try {
QueueReceiver consumer = newQueueSession.createReceiver(tempQueue);
fail("should have gotten exception but got consumer: " + consumer);
} catch (JMSException ex) {
// correct
}
connection.close();
try {
Message newMsg = newQueueSession.createMessage();
queueSender.send(newMsg);
} catch (JMSException e) {
// ok
}
} finally {
newConn.close();
}
}
Aggregations