use of javax.jms.JMSContext in project javaee7-samples by javaee-samples.
the class SubscriptionCreator method createSubscription.
/**
* We create the subscription at soonest possible time after deployment so we
* wouldn't miss any message
*/
@PostConstruct
void createSubscription() {
try (JMSContext jms = factory.createContext()) {
// <1> This is factory with clientId specified
// <2> creates durable subscription on the topic
JMSConsumer consumer = jms.createDurableConsumer(topic, Resources.SUBSCRIPTION);
consumer.close();
}
}
use of javax.jms.JMSContext in project wildfly by wildfly.
the class DefaultTimeoutMDB method onMessage.
@Override
public void onMessage(Message message) {
try {
log.tracef("onMessage received message: %s '%s'", message, ((TextMessage) message).getText());
final Destination replyTo = message.getJMSReplyTo();
if (replyTo == null) {
throw new RuntimeException("ReplyTo info in message was not specified" + " and bean does not know where to reply to");
}
// should timeout txn - this timeout waiting has to be greater than 1 s
// (see transaction timeout default setup task)
TxTestUtil.waitForTimeout(tm);
TxTestUtil.enlistTestXAResource(tm.getTransaction(), checker);
try (JMSContext context = factory.createContext()) {
context.createProducer().setJMSCorrelationID(message.getJMSMessageID()).send(replyTo, REPLY_PREFIX + ((TextMessage) message).getText());
}
} catch (Exception e) {
throw new RuntimeException("onMessage method execution failed", e);
}
}
use of javax.jms.JMSContext 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.JMSContext in project wildfly by wildfly.
the class ExternalJMSDestinationManagementTestCase method testCreatedDestinations.
@Test
public void testCreatedDestinations() throws Exception {
ActiveMQJMSConnectionFactory cf = (ActiveMQJMSConnectionFactory) remoteContext.lookup("jms/TestConnectionFactory");
Assert.assertNotNull(cf);
Destination myExternalQueue = (Destination) remoteContext.lookup("jms/queue/" + QUEUE_NAME);
Assert.assertNotNull(myExternalQueue);
Destination myLegacyExternalQueue = (Destination) remoteContext.lookup("jms/queue/" + LEGACY_QUEUE_NAME);
Assert.assertNotNull(myLegacyExternalQueue);
Destination myExternalTopic = (Destination) remoteContext.lookup("jms/topic/" + TOPIC_NAME);
Assert.assertNotNull(myExternalTopic);
Destination myLegacyExternalTopic = (Destination) remoteContext.lookup("jms/topic/" + LEGACY_TOPIC_NAME);
Assert.assertNotNull(myLegacyExternalTopic);
try (JMSContext jmsContext = cf.createContext("guest", "guest", JMSContext.AUTO_ACKNOWLEDGE)) {
checkJMSDestination(jmsContext, myLegacyExternalQueue);
checkJMSDestination(jmsContext, myLegacyExternalTopic);
}
cf = (ActiveMQJMSConnectionFactory) remoteContext.lookup("jms/TestConnectionFactory");
cf.setEnable1xPrefixes(false);
try (JMSContext jmsContext = cf.createContext("guest", "guest", JMSContext.AUTO_ACKNOWLEDGE)) {
checkJMSDestination(jmsContext, myExternalQueue);
checkJMSDestination(jmsContext, myExternalTopic);
}
JMSOperations ops = JMSOperationsProvider.getInstance(managementClient.getControllerClient());
if (!ops.isRemoteBroker()) {
ModelNode op = Operations.createOperation("read-children-names", ops.getServerAddress());
op.get("child-type").set("runtime-queue");
List<ModelNode> runtimeQueues = Operations.readResult(managementClient.getControllerClient().execute(op)).asList();
Set<String> queues = runtimeQueues.stream().map(ModelNode::asString).collect(Collectors.toSet());
Assert.assertEquals(initialQueues.size() + 4, queues.size());
Assert.assertTrue("We should have myExternalQueue queue", queues.contains(QUEUE_NAME));
Assert.assertTrue("We should have myExternalQueue queue", queues.contains("jms.queue." + LEGACY_QUEUE_NAME));
queues.removeAll(initialQueues);
queues.remove(QUEUE_NAME);
queues.remove("jms.queue." + LEGACY_QUEUE_NAME);
checkRuntimeQueue(ops, QUEUE_NAME, "ANYCAST", QUEUE_NAME);
checkRuntimeQueue(ops, "jms.queue." + LEGACY_QUEUE_NAME, "ANYCAST", "jms.queue." + LEGACY_QUEUE_NAME);
for (String topicId : queues) {
checkRuntimeTopic(ops, topicId);
}
}
}
use of javax.jms.JMSContext in project wildfly by wildfly.
the class ExportImportJournalTestCase method sendMessage.
protected static void sendMessage(Context ctx, String destinationLookup, String text) throws NamingException, JMSException {
ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
assertNotNull(cf);
Destination destination = (Destination) ctx.lookup(destinationLookup);
assertNotNull(destination);
try (JMSContext context = cf.createContext("guest", "guest")) {
TextMessage message = context.createTextMessage(text);
message.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
context.createProducer().send(destination, message);
}
}
Aggregations