Apache MQ - JMS message selector

2019-07-09 06:52发布

问题:

I need some help to fetch all the messages for a particular queue which has a particular property on it.

The problem here is I need to match the JMS header property process with processName.As the message can have the value for process as upper or lowercase but processName always has a value which is uppercase.

I can NOT use equalsIgnorecase here like : StringJMSCriteriaBuilder("process").equalIgnorecase(processName);

As there is no such method in IJMSSelectorCriteriaBuilder interface.

Below is the code I have currently:

private String createJMSSelectorMessage(QueueFilter queueFilter) throws Exception {
        StringBuffer selectorMessage = new StringBuffer();
        String processName=Service.getProcess(Long.valueOf(queueFilter.getProcess())).getProcessName();


        IJMSSelectorCriteriaBuilder processNameSelectorCriteriaBuilder = new StringJMSCriteriaBuilder("process").eq(processName);
        selectorMessage.append(processNameSelectorCriteriaBuilder.getJMSSelectorCriteriaValue());
        return selectorMessage;
        }

回答1:

The JMS specification stipulates that selectors are case sensitive.

Two strings are equal if and only if they contain the same sequence of characters.

Solutions I have seen used include:

  • Pre-processing all messages to normalize case
  • Use Message Broker
  • Browse, evaluate in code and select
  • Have the program putting the message normalize case first

Sorry, there's no good receiver-side solution that doesn't involve parsing every message.