use of javax.jms.QueueReceiver in project activemq-artemis by apache.
the class NewQueueRequestorTest method testQueueRequestor.
@Test
public void testQueueRequestor() throws Exception {
QueueConnection conn1 = null, conn2 = null;
try {
Queue queue1 = createQueue(true, "myQueue");
conn1 = (QueueConnection) cf.createConnection();
QueueSession sess1 = conn1.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueRequestor requestor = new QueueRequestor(sess1, queue1);
conn1.start();
// And the responder
conn2 = (QueueConnection) cf.createConnection();
QueueSession sess2 = conn2.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
TestMessageListener listener = new TestMessageListener(sess2);
QueueReceiver receiver = sess2.createReceiver(queue1);
receiver.setMessageListener(listener);
conn2.start();
Message m1 = sess1.createMessage();
log.trace("Sending request message");
TextMessage m2 = (TextMessage) requestor.request(m1);
assertNotNull(m2);
assertEquals("This is the response", m2.getText());
requestor.close();
} finally {
conn1.close();
conn2.close();
}
}
use of javax.jms.QueueReceiver in project wildfly by wildfly.
the class MDBEJBRuntimeNameTestsCase method testMDB.
@Test
@InSequence(1)
public void testMDB() throws Exception {
final QueueConnectionFactory factory = (QueueConnectionFactory) context.lookup("java:/jms/RemoteConnectionFactory");
final QueueConnection connection = factory.createQueueConnection("guest", "guest");
try {
connection.start();
final QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
final Queue replyDestination = session.createTemporaryQueue();
final String requestMessage = "test";
final Message message = session.createTextMessage(requestMessage);
message.setJMSReplyTo(replyDestination);
final Destination destination = (Destination) context.lookup(Constants.QUEUE_JNDI_NAME);
final MessageProducer producer = session.createProducer(destination);
producer.send(message);
producer.close();
// wait for a reply
final QueueReceiver receiver = session.createReceiver(replyDestination);
final Message reply = receiver.receive(TimeoutUtil.adjust(1000));
assertNotNull("Did not receive a reply on the reply queue. Perhaps the original (request) message didn't make it to the MDB?", reply);
final String result = ((TextMessage) reply).getText();
assertEquals("Unexpected reply messsage", Constants.REPLY_MESSAGE_PREFIX + requestMessage, result);
} finally {
if (connection != null) {
// just closing the connection will close the session and other related resources (@see javax.jms.Connection)
safeClose(connection);
}
}
}
use of javax.jms.QueueReceiver in project jmeter by apache.
the class JMSSampler method clearQueue.
private String clearQueue(Queue queue, SampleResult res) {
String retVal = null;
QueueReceiver consumer = null;
String queueName = null;
try {
queueName = queue.getQueueName();
consumer = session.createReceiver(queue);
Message deletedMsg = null;
long deletedMsgCount = 0;
do {
deletedMsg = consumer.receive(getTimeoutAsInt());
if (deletedMsg != null) {
deletedMsgCount++;
deletedMsg.acknowledge();
}
} while (deletedMsg != null);
retVal = deletedMsgCount + " message(s) removed using receive timeout:" + getTimeoutAsInt() + "ms";
res.setResponseMessage(retVal);
} catch (Exception ex) {
res.setResponseMessage("Error clearing queue:" + queueName);
LOGGER.error("Error clearing queue {}", queueName, ex);
return "Error clearing queue " + queueName + ", message:" + ex.getMessage();
} finally {
Utils.close(consumer, LOGGER);
}
return retVal;
}
use of javax.jms.QueueReceiver in project jmeter by apache.
the class JMSSampler method browseQueueForConsumption.
private String browseQueueForConsumption(Queue queue, String jmsSelector, SampleResult res, StringBuilder buffer, StringBuilder propBuffer) {
String retVal = null;
QueueReceiver consumer = null;
Message reply = null;
String queueName = null;
try {
queueName = queue.getQueueName();
consumer = session.createReceiver(queue, jmsSelector);
reply = consumer.receive(getTimeoutAsInt());
LOGGER.debug("Message: {}", reply);
if (reply != null) {
res.setResponseMessage("1 message received successfully");
res.setResponseHeaders(reply.toString());
TextMessage msg = (TextMessage) reply;
retVal = msg.getText();
extractContent(buffer, propBuffer, msg);
} else {
res.setResponseMessage("No message received");
}
} catch (Exception ex) {
res.setResponseMessage("Error browsing queue '" + queueName + "' with selector '" + jmsSelector + "', timeout '" + getTimeout() + "', message:" + ex.getMessage());
LOGGER.error("Error browsing queue {} with selector {} and configured timeout {}", queueName, jmsSelector, getTimeout(), ex);
} finally {
Utils.close(consumer, LOGGER);
}
return retVal;
}
use of javax.jms.QueueReceiver in project iaf by ibissource.
the class IfsaRequesterSender method getRawReplyMessage.
/**
* Retrieves a message with the specified correlationId from queue or other channel, but does no processing on it.
*/
private javax.jms.Message getRawReplyMessage(QueueSession session, IFSAQueue queue, TextMessage sentMessage) throws SenderException, TimeoutException {
String selector = null;
javax.jms.Message msg = null;
QueueReceiver replyReceiver = null;
try {
replyReceiver = getReplyReceiver(session, sentMessage);
selector = replyReceiver.getMessageSelector();
long timeout = getExpiry(queue);
log.debug(getLogPrefix() + "start waiting at most [" + timeout + "] ms for reply on message using selector [" + selector + "]");
msg = replyReceiver.receive(timeout);
if (msg == null) {
log.info(getLogPrefix() + "received null reply");
} else {
log.info(getLogPrefix() + "received reply");
}
} catch (Exception e) {
throw new SenderException(getLogPrefix() + "got exception retrieving reply", e);
} finally {
try {
closeReplyReceiver(replyReceiver);
} catch (IfsaException e) {
log.error(getLogPrefix() + "error closing replyreceiver", e);
}
}
if (msg == null) {
throw new TimeoutException(getLogPrefix() + " timed out waiting for reply using selector [" + selector + "]");
}
if (msg instanceof IFSATimeOutMessage) {
throw new TimeoutException(getLogPrefix() + "received IFSATimeOutMessage waiting for reply using selector [" + selector + "]");
}
return msg;
// try {
// TextMessage result = (TextMessage)msg;
// return result;
// } catch (Exception e) {
// throw new SenderException(getLogPrefix()+"reply received for message using selector ["+selector+"] cannot be cast to TextMessage ["+msg.getClass().getName()+"]",e);
// }
}
Aggregations