JMS Learning (iv) selector detailed

Source: Internet
Author: User

First, preface

After mastering the structure of the message, let's look at one of the key features of JMS: the selector. Sometimes, as consumers only want to deal with the information they are interested in. If there is only one consumer of a message, we can allow the client to handle the messages that are of interest to them according to the rules, and those that do not satisfy certain rules are discarded directly.

But if the message is the mechanism of broadcasting, so that each client to do such a process, it increases the workload of the client, a better way, is the message provider to complete the filtering and routing of messages, so that can greatly reduce the workload of the client, consumers in the real process, the user does not care about the filtering of the message , you can only be responsible for handling the message. In other words, a JMS message provider can guarantee that the message it receives is the message it wants.

In JMS, this mechanism is implemented by selector, and this article describes selector in detail.

Ii. means of realization

In JMS, selector is not an object, but rather a string, or, more precisely, a conditional expression, which is not limited to dealing with logical expressions, but rather an expression similar to SQL92 syntax. The variable in the expression must be either a key of the standard message header information or a key of a property, if the expression evaluates to true, it means that the message satisfies the condition, the receiving side needs to be processed, and if false, the receiving side does not need to be processed.

The expression is specified when creating a consumer, as shown in the following example:

Messageconsumer receiver = Session.createconsumer (mydest, "articletype = ' joke '");

The receiver will only receive a message with the ArticleType attribute and a value of ' joke '. Suppose there are two messages, as follows:

  Message1.setstringproperty ("ArticleType", "joke");

Message2.setstringproperty ("ArticleType", "pic");

It is clear that only message1 will be dealt with.

  

Iii. Expression Definitions

Can see actually set up a selector or relatively simple, if the SQL syntax is familiar with, then the expression of understanding and writing will be relatively simple. Some of the important rules are as follows:

1. The operator of an expression is not case-sensitive, but is usually capitalized

2. The variable name of the expression is consistent with the naming conventions of ordinary Java variable names, case sensitive, such as ArticleType and ArticleType are two different variables.

3. The variable name of the expression must be a standard header header name or an existing property name, otherwise the corresponding value will be null

4. The value of the expression does not convert type, that is, if there is Message2.setstringproperty ("version", "1"), then the expression "Version=1" for message2, the result is false.

5. Support basic arithmetic operations, logical operations, parentheses, inverse operators

6. Support between. And ..., in (not) operations

7. Supports a like operation for fuzzy matching,% means matching any number of characters, _ means matching an arbitrary character

8. Support is null and is not NULL

9. Other SQL 92 standards not mentioned, can be considered to be used after the WHERE statement expression, can be used here.

Iv. Summary

With the header information and attributes of message, combined with selector, it is convenient to filter messages.

JMS Learning (iv) selector detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.