use of javax.jms.JMSContext 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(5000));
assertNotNull(reply);
assertEquals(message.getJMSMessageID(), reply.getJMSCorrelationID());
assertTrue("messageDrivenContext.setRollbackOnly() did not throw the expected IllegalStateException", reply.getBooleanProperty(EXCEPTION_PROP_NAME));
}
}
use of javax.jms.JMSContext in project wildfly by wildfly.
the class SimpleMDB method onMessage.
@Override
public void onMessage(Message message) {
logger.trace("Received message: " + message);
try {
final Destination replyTo = message.getJMSReplyTo();
if (replyTo != null) {
logger.trace("Replying to " + replyTo);
try (JMSContext context = factory.createContext()) {
String reply = (messageDrivenContext != null) ? SUCCESS_REPLY : FAILURE_REPLY;
context.createProducer().setJMSCorrelationID(message.getJMSMessageID()).send(replyTo, reply);
}
}
} catch (JMSException jmse) {
throw new RuntimeException(jmse);
}
}
use of javax.jms.JMSContext in project wildfly by wildfly.
the class JMSHelper method assertSendAndReceiveTextMessage.
public static void assertSendAndReceiveTextMessage(ConnectionFactory cf, Destination destination, String text) throws JMSException {
try (JMSContext context = cf.createContext(AUTO_ACKNOWLEDGE)) {
TemporaryQueue replyTo = context.createTemporaryQueue();
context.createProducer().setJMSReplyTo(replyTo).send(destination, text);
String replyText = context.createConsumer(replyTo).receiveBody(String.class, TimeoutUtil.adjust(5000));
assertEquals(text, replyText);
}
}
use of javax.jms.JMSContext in project wildfly by wildfly.
the class CriticalAnalyzerTestCase method testCriticalAnalyzer.
/**
* Set the critical analyzer to SHUTDOWN strategy.
* Use the byteman script to simulate a slow journal that would make the critical analyzer to activate.
* Check that the critical analyzer was started and created the expected log traces.
* Check that the broker has been stopped.
* @throws Exception
*/
@Test
public void testCriticalAnalyzer() throws Exception {
if (!container.isStarted(DEFAULT_FULL_JBOSSAS)) {
container.start(DEFAULT_FULL_JBOSSAS);
}
InitialContext remoteContext = createJNDIContext();
managementClient = createManagementClient();
ConnectionFactory cf = (ConnectionFactory) remoteContext.lookup("jms/RemoteConnectionFactory");
Queue queue = (Queue) remoteContext.lookup("queue/critical");
deployRules();
try (JMSContext context = cf.createContext("guest", "guest", JMSContext.AUTO_ACKNOWLEDGE)) {
JMSProducer producer = context.createProducer();
for (int i = 0; i < 20; i++) {
TextMessage message = context.createTextMessage(RandomStringUtils.randomAlphabetic(10));
producer.send(queue, message);
}
Assert.fail("Critical analyzer should have kicked in");
} catch (javax.jms.JMSRuntimeException ex) {
Assert.assertTrue("Log should contains ActiveMQ connection failure error log message: [AMQ219016]", ex.getMessage().contains("AMQ219016"));
Assert.assertTrue("Log should contains ActiveMQ critical measure ", LoggingUtil.hasLogMessage(managementClient, "artemis-log", "", (line) -> (line.contains("[org.apache.activemq.artemis.utils.critical.CriticalMeasure]"))));
Assert.assertTrue("Log should contains ActiveMQ AMQ224080 : critical analyzer is stopping the broker", LoggingUtil.hasLogMessage(managementClient, "artemis-log", "", (line) -> (line.contains("AMQ224080"))));
Assert.assertTrue("Log should contains ActiveMQ AMQ222199 : Thread dump ", LoggingUtil.hasLogMessage(managementClient, "artemis-log", "", (line) -> (line.contains("AMQ222199"))));
}
remoteContext.close();
assertFalse(isBrokerRunning());
}
use of javax.jms.JMSContext in project wildfly by wildfly.
the class AbstractMessagingHATestCase method sendMessage.
protected static void sendMessage(Context ctx, String destinationLookup, String text) throws NamingException {
log.trace("Looking up for the RemoteConnectionFactory with " + ctx);
ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
assertNotNull(cf);
log.trace("Looking up for the destination with " + ctx);
Destination destination = (Destination) ctx.lookup(destinationLookup);
assertNotNull(destination);
try (JMSContext context = cf.createContext("guest", "guest")) {
context.createProducer().send(destination, text);
}
}
Aggregations