osdir.com

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to browse / search message in topic by consumertemplate


You cannot brower the message in a JMS topic[1].

[1]http://activemq.apache.org/can-you-browse-a-topic.html

Willem Jiang

Twitter: willemjiang
Weibo: 姜宁willem
On Wed, Nov 7, 2018 at 11:09 PM Wang Yan <wyanbox@xxxxxxxxx> wrote:
>
> 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);