use of javax.jms.JMSProducer in project activemq-artemis by apache.
the class JmsContextTest method testReceiveText.
@Test
public void testReceiveText() throws Exception {
JMSProducer producer = context.createProducer();
JMSConsumer consumer = context.createConsumer(queue1);
String randomStr = newXID().toString();
System.out.println("RandomStr:" + randomStr);
TextMessage sendMsg = context.createTextMessage(randomStr);
producer.send(queue1, sendMsg);
TextMessage receiveMsg = (TextMessage) consumer.receiveNoWait();
assertEquals(randomStr, receiveMsg.getText());
}
use of javax.jms.JMSProducer in project activemq-artemis by apache.
the class JmsContextTest method recoverAckTest.
@Test
public void recoverAckTest() throws Exception {
try (JMSContext context = cf.createContext(JMSContext.CLIENT_ACKNOWLEDGE)) {
int numMessages = 10;
TextMessage textMessage = null;
// Create JMSConsumer from JMSContext
JMSConsumer consumer = context.createConsumer(queue1);
// Create JMSProducer from JMSContext
JMSProducer producer = context.createProducer();
// send messages
for (int i = 0; i < numMessages; i++) {
String message = "text message " + i;
textMessage = context.createTextMessage(message);
textMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "recoverAckTest" + i);
producer.send(queue1, textMessage);
}
// receive messages but do not acknowledge
for (int i = 0; i < numMessages; i++) {
textMessage = (TextMessage) consumer.receive(5000);
assertNotNull(textMessage);
}
context.recover();
// receive messages a second time followed by acknowledge
for (int i = 0; i < numMessages; i++) {
textMessage = (TextMessage) consumer.receive(5000);
assertNotNull(textMessage);
}
// Acknowledge all messages
context.acknowledge();
}
// doing this check with another context / consumer to make sure it was acked.
try (JMSContext context = cf.createContext(JMSContext.CLIENT_ACKNOWLEDGE)) {
// Create JMSConsumer from JMSContext
JMSConsumer consumer = context.createConsumer(queue1);
assertNull(consumer.receiveNoWait());
}
}
use of javax.jms.JMSProducer in project activemq-artemis by apache.
the class JmsContextTest method testInvalidDestination.
@Test
public void testInvalidDestination() {
JMSProducer producer = context.createProducer();
Message msg = context.createMessage();
try {
producer.send((Destination) null, msg);
Assert.fail("null Destination");
} catch (InvalidDestinationRuntimeException expected) {
// no-op
}
}
use of javax.jms.JMSProducer in project activemq-artemis by apache.
the class JmsContextTest method testDelay.
@Test
public void testDelay() throws Exception {
JMSProducer producer = context.createProducer();
JMSConsumer consumer = context.createConsumer(queue1);
producer.setDeliveryDelay(500);
long timeStart = System.currentTimeMillis();
String strRandom = newXID().toString();
producer.send(queue1, context.createTextMessage(strRandom));
TextMessage msg = (TextMessage) consumer.receive(2500);
assertNotNull(msg);
long actualDelay = System.currentTimeMillis() - timeStart;
assertTrue("delay is not working, actualDelay=" + actualDelay, actualDelay >= 500 && actualDelay < 2000);
assertEquals(strRandom, msg.getText());
}
use of javax.jms.JMSProducer in project activemq-artemis by apache.
the class JmsContextTest method testDeliveryMode.
@Test
public void testDeliveryMode() throws Exception {
JMSProducer producer = context.createProducer();
JMSConsumer consumer = context.createConsumer(queue1);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
String strRandom = newXID().toString();
producer.send(queue1, context.createTextMessage(strRandom));
TextMessage msg = (TextMessage) consumer.receiveNoWait();
assertNotNull(msg);
assertEquals(DeliveryMode.NON_PERSISTENT, msg.getJMSDeliveryMode());
}
Aggregations