boolean verbose = false;
@Override
public Object execute() throws Exception {
ShellTable table = new ShellTable();
table.column("Message ID");
table.column("Content").maxSize(80);
table.column("Charset");
table.column("Type");
table.column("Correlation ID");
table.column("Delivery Mode");
table.column("Destination");
table.column("Expiration");
table.column("Priority");
table.column("Redelivered");
table.column("ReplyTo");
table.column("Timestamp");
if (verbose) {
table.column("Properties");
}
List<JmsMessage> messages = getJmsService().browse(connectionFactory, queue, selector, username, password);
for (JmsMessage message : messages) {
if (verbose) {
StringBuilder properties = new StringBuilder();
for (String property : message.getProperties().keySet()) {
properties.append(property).append("=").append(message.getProperties().get(property)).append("\n");
}
table.addRow().addContent(
message.getMessageId(),
message.getContent(),
message.getCharset(),
message.getType(),
message.getCorrelationID(),
message.getDeliveryMode(),
message.getDestination(),
message.getExpiration(),
message.getPriority(),
message.isRedelivered(),
message.getReplyTo(),
message.getTimestamp(),
properties.toString());
} else {
table.addRow().addContent(
message.getMessageId(),
message.getContent(),
message.getCharset(),
message.getType(),
message.getCorrelationID(),
message.getDeliveryMode(),
message.getDestination(),
message.getExpiration(),
message.getPriority(),
message.isRedelivered(),
message.getReplyTo(),
message.getTimestamp());
}
}
table.print(System.out);
return null;
}