use of org.motechproject.admin.domain.QueueMessage in project motech by motech.
the class BrokerStatisticsControllerTest method shouldReturnMessageInformationGivenQueueName.
@Test
public void shouldReturnMessageInformationGivenQueueName() throws Exception {
given(mBeanService.getQueueMessages("foo")).willReturn(Arrays.asList(new QueueMessage("123", false, new DateTime())));
mockMvc.perform(MockMvcRequestBuilders.get("/queues/browse?queueName=foo")).andExpect(status().isOk()).andExpect(content().string(new StringContains("\"messageId\":\"123"))).andExpect(content().string(new StringContains("\"redelivered\":false")));
}
use of org.motechproject.admin.domain.QueueMessage in project motech by motech.
the class MBeanService method getQueueMessages.
/**
* Retrieves a list of messages for the given JMS queue.
*
* @param queueName The name of the queue for which messages should be retrieved.
* @return {@link List} of messages for the given queue.
*/
@PreAuthorize(SecurityConstants.MANAGE_ACTIVEMQ)
public List<QueueMessage> getQueueMessages(String queueName) {
try {
ArrayList<QueueMessage> queueMessages = new ArrayList<>();
QueueViewMBean queueViewMBean = mBeanServer.getQueueViewMBean(queueName);
for (CompositeData compositeData : queueViewMBean.browse()) {
if (compositeData != null) {
String messageId = (String) compositeData.get(JMS_MESSAGE_ID);
Boolean redelivered = (Boolean) compositeData.get(JMS_REDELIVERED);
Date timestamp = (Date) compositeData.get(JMS_TIMESTAMP);
queueMessages.add(new QueueMessage(messageId, redelivered, DateUtil.newDateTime(timestamp)));
}
}
return queueMessages;
} catch (OpenDataException openDataException) {
throw new MotechException(String.format("Could not Browse MBean for queue %s", queueName), openDataException);
} catch (IOException ioException) {
throw new MotechException(String.format("Could not access MBean for queue %s", queueName), ioException);
}
}
Aggregations