how to browse / search message in topic by consumertemplate

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

how to browse / search message in topic by consumertemplate

nono
Hey All,

I need to use consumertemplate to search message

i did something like below. but i have two concerns

1) it could not search particular message based on messageid

2) i just want to search or browse message, i dont want to digest it

any suggestions or hints are more than welcome!

@Override
public void process(Exchange exchange) throws Exception {
Result result = new Result();
try {
result.setMessageBody("MESSAGE NOT FOUND");
if (exchange != null && exchange.getIn() != null) {
String operationName =
exchange.getIn().getHeader(CxfConstants.OPERATION_NAME, String.class);
MessageContentsList msgList = (MessageContentsList)
exchange.getIn().getBody();
if (operationName.equalsIgnoreCase("getMessageFromTopic")) {
String topic = (String) msgList.get(0);
String messagid = (String) msgList.get(1);
     Exchange ex = consumerTemplate.receive("activemq:topic:"+topic);
     String messageid=  (String)ex.getIn().getHeader("JMSMessageID");
     String messageBody=ex.getIn().getBody(String.class);
     result.setMessageId(messageid);
     result.setMessageBody(messageBody);
}
}
} catch (Exception e) {
LOG.error("erorr happened ", e);
throw e;
}
exchange.getOut().setBody(result);