use of javax.jms.Message in project wildfly by wildfly.
the class JMSQueueManagementTestCase method testMessageRemoval.
// @org.junit.Ignore("AS7-2480")
@Test
public void testMessageRemoval() throws Exception {
MessageProducer producer = session.createProducer(queue);
Message msgA = session.createTextMessage("A");
producer.send(msgA);
producer.send(session.createTextMessage("B"));
producer.send(session.createTextMessage("C"));
final ModelNode op = getQueueOperation("remove-message");
op.get("message-id").set(msgA.getJMSMessageID());
ModelNode result = execute(op, true);
Assert.assertTrue(result.isDefined());
Assert.assertTrue(result.asBoolean());
result = execute(getQueueOperation("count-messages"), true);
Assert.assertTrue(result.isDefined());
Assert.assertEquals(2, result.asInt());
result = execute(getQueueOperation("remove-messages"), true);
Assert.assertTrue(result.isDefined());
Assert.assertEquals(2, result.asInt());
result = execute(getQueueOperation("count-messages"), true);
Assert.assertTrue(result.isDefined());
Assert.assertEquals(0, result.asInt());
}
use of javax.jms.Message in project beam by apache.
the class JmsCheckpointMark method finalizeCheckpoint.
/**
* Acknowledge all outstanding message. Since we believe that messages will be delivered in
* timestamp order, and acknowledged messages will not be retried, the newest message in this
* batch is a good bound for future messages.
*/
@Override
public void finalizeCheckpoint() {
for (Message message : messages) {
try {
message.acknowledge();
Instant currentMessageTimestamp = new Instant(message.getJMSTimestamp());
if (currentMessageTimestamp.isAfter(oldestPendingTimestamp)) {
oldestPendingTimestamp = currentMessageTimestamp;
}
} catch (Exception e) {
// nothing to do
}
}
messages.clear();
}
use of javax.jms.Message in project beam by apache.
the class JmsIOTest method testReadMessages.
@Test
public void testReadMessages() throws Exception {
// produce message
Connection connection = connectionFactory.createConnection(USERNAME, PASSWORD);
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(session.createQueue(QUEUE));
TextMessage message = session.createTextMessage("This Is A Test");
producer.send(message);
producer.send(message);
producer.send(message);
producer.send(message);
producer.send(message);
producer.send(message);
producer.close();
session.close();
connection.close();
// read from the queue
PCollection<JmsRecord> output = pipeline.apply(JmsIO.read().withConnectionFactory(connectionFactory).withQueue(QUEUE).withUsername(USERNAME).withPassword(PASSWORD).withMaxNumRecords(5));
PAssert.thatSingleton(output.apply("Count", Count.<JmsRecord>globally())).isEqualTo(new Long(5));
pipeline.run();
connection = connectionFactory.createConnection(USERNAME, PASSWORD);
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(session.createQueue(QUEUE));
Message msg = consumer.receiveNoWait();
assertNull(msg);
}
use of javax.jms.Message in project spring-boot by spring-projects.
the class ArtemisAutoConfigurationTests method embeddedWithPersistentMode.
@Test
public void embeddedWithPersistentMode() throws IOException, JMSException {
File dataFolder = this.folder.newFolder();
// Start the server and post a message to some queue
load(EmptyConfiguration.class, "spring.artemis.embedded.queues=TestQueue", "spring.artemis.embedded.persistent:true", "spring.artemis.embedded.dataDirectory:" + dataFolder.getAbsolutePath());
final String msgId = UUID.randomUUID().toString();
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
jmsTemplate.send("TestQueue", new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
return session.createTextMessage(msgId);
}
});
// Shutdown the broker
this.context.close();
// Start the server again and check if our message is still here
load(EmptyConfiguration.class, "spring.artemis.embedded.queues=TestQueue", "spring.artemis.embedded.persistent:true", "spring.artemis.embedded.dataDirectory:" + dataFolder.getAbsolutePath());
JmsTemplate jmsTemplate2 = this.context.getBean(JmsTemplate.class);
jmsTemplate2.setReceiveTimeout(1000L);
Message message = jmsTemplate2.receive("TestQueue");
assertThat(message).isNotNull();
assertThat(((TextMessage) message).getText()).isEqualTo(msgId);
}
use of javax.jms.Message in project play-cookbook by spinscale.
the class ActiveMqTest method assertThatPluginSendsMessages.
@Test
public void assertThatPluginSendsMessages() throws Exception {
assertEquals(0, ChatRoom.get().archive().size());
Event event = new Join("user");
ChatRoom.get().publish(event);
// Check chatroom
int currentEventCount = ChatRoom.get().archive().size();
assertEquals(1, currentEventCount);
// Check for messages
Message msg = receiveSubscriber.receive(2000);
Event evt = (ChatRoom.Event) ((ObjectMessage) msg).getObject();
assertEquals("join", evt.type);
}
Aggregations