use of javax.jms.JMSConsumer 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.JMSConsumer in project wildfly by wildfly.
the class MessagingServlet method sendAndReceiveMessage.
private String sendAndReceiveMessage(Destination destination, String text) {
Destination replyTo = context.createTemporaryQueue();
JMSConsumer consumer = context.createConsumer(replyTo);
context.createProducer().setJMSReplyTo(replyTo).send(destination, text);
return consumer.receiveBody(String.class, 5000);
}
use of javax.jms.JMSConsumer in project wildfly by wildfly.
the class ExportImportJournalTestCase method receiveMessage.
protected static void receiveMessage(Context ctx, String destinationLookup, boolean expectReceivedMessage, String expectedText) throws NamingException {
ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
assertNotNull(cf);
Destination destination = (Destination) ctx.lookup(destinationLookup);
assertNotNull(destination);
try (JMSContext context = cf.createContext("guest", "guest")) {
JMSConsumer consumer = context.createConsumer(destination);
String text = consumer.receiveBody(String.class, 5000);
if (expectReceivedMessage) {
assertNotNull(text);
assertEquals(expectedText, text);
} else {
assertNull("should not have received any message", text);
}
}
}
use of javax.jms.JMSConsumer 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.JMSConsumer 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);
}
}
Aggregations