use of javax.jms.Message in project jmeter by apache.
the class Receiver method run.
@Override
public void run() {
active = true;
Message reply;
while (active) {
reply = null;
try {
reply = consumer.receive(5000);
if (reply != null) {
String messageKey;
final MessageAdmin admin = MessageAdmin.getAdmin();
if (useResMsgIdAsCorrelId) {
messageKey = reply.getJMSMessageID();
synchronized (admin) {
// synchronize with FixedQueueExecutor
admin.putReply(messageKey, reply);
}
} else {
messageKey = reply.getJMSCorrelationID();
if (messageKey == null) {
// JMSMessageID cannot be null
log.warn("Received message with correlation id null. Discarding message ...");
} else {
admin.putReply(messageKey, reply);
}
}
}
} catch (JMSException e1) {
log.error("Error handling receive", e1);
}
}
Utils.close(consumer, log);
Utils.close(session, log);
Utils.close(conn, log);
}
use of javax.jms.Message in project wildfly by wildfly.
the class MessageDrivenTimeoutTestCase method sendMessage.
static Queue sendMessage(String text, String queueJndi, InitialContext initCtx) throws Exception {
QueueConnection connection = getConnection(initCtx);
connection.start();
Queue replyDestination = null;
try {
final QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
final Message message = session.createTextMessage(text);
replyDestination = (Queue) initCtx.lookup(TransactionTimeoutQueueSetupTask.REPLY_QUEUE_JNDI_NAME);
message.setJMSReplyTo(replyDestination);
final Destination destination = (Destination) initCtx.lookup(queueJndi);
final MessageProducer producer = session.createProducer(destination);
producer.send(message);
producer.close();
} finally {
connection.close();
}
return replyDestination;
}
use of javax.jms.Message in project wildfly by wildfly.
the class TransactionScopedJMSContextTestCase method sendAndReceiveWithContext.
@Test
public void sendAndReceiveWithContext() throws JMSException, InterruptedException {
int numThreads = 5;
int numMessages = 10;
launcher.start(numThreads, numMessages);
int receivedMessages = 0;
try (JMSContext context = factory.createContext()) {
JMSConsumer consumer = context.createConsumer(queue);
Message m;
do {
m = consumer.receive(1000);
if (m != null) {
receivedMessages++;
}
} while (m != null);
}
assertEquals(numThreads * numMessages, receivedMessages);
}
use of javax.jms.Message in project wildfly by wildfly.
the class InjectedJMSContextTestCase method tearDown.
@After
public void tearDown() throws JMSException {
// drain the queue to remove any pending messages from it
try (JMSContext context = factory.createContext()) {
JMSConsumer consumer = context.createConsumer(queue);
Message m;
do {
m = consumer.receiveNoWait();
} while (m != null);
}
}
use of javax.jms.Message in project wildfly by wildfly.
the class ContainerManagedTransactionNotSupportedTestCase method doSetRollbackOnlyInContainerManagedTransactionNotSupportedMDBThrowsIllegalStateException.
private void doSetRollbackOnlyInContainerManagedTransactionNotSupportedMDBThrowsIllegalStateException(Destination destination) throws Exception {
try (JMSContext context = cf.createContext()) {
TemporaryQueue replyTo = context.createTemporaryQueue();
String text = UUID.randomUUID().toString();
TextMessage message = context.createTextMessage(text);
message.setJMSReplyTo(replyTo);
context.createProducer().send(destination, message);
Message reply = context.createConsumer(replyTo).receive(adjust(2000));
assertNotNull(reply);
assertEquals(message.getJMSMessageID(), reply.getJMSCorrelationID());
assertTrue("messageDrivenContext.setRollbackOnly() did not throw the expected IllegalStateException", reply.getBooleanProperty(EXCEPTION_PROP_NAME));
}
}
Aggregations