简体   繁体   中英

PHP stomp selector for ActiveMQ

$topic  = '/topic/orders';
$selector = "orders IN ('1233', '345', '22222')";
$username = 'username'; $pass = 'pass';

$connection = new Connection($brokerUri);
$client = new Client($connection);
$client->setLogin($username, $pass);
$stomp = new StatefulStomp($client);
$stomp->subscribe($topic,$selector);

It will subscribe to the topic on ActiveMQ but the subscription will prefix with convert_string_expressions:

Please see attached image.

在此处输入图像描述

How can I fix this prefix?

ActiveMQ "Classic" is hard-coded to prefix any selector used by a STOMP client with convert_string_expressions: . This was done via AMQ-4146 almost 10 years ago now. The prefix is documented here which states:

The JMS spec states that a String property should not get converted to a numeric when used in a selector. So for example, if a message has the 'age' property set to String '21' then the following selector should not match it: 'age > 18'. Since ActiveMQ support STOMP client which can only send messages with string properties, that restriction is a bit limiting. If you want your JMS selectors to auto-convert String properties the the appropriate number type, just prefix the the selector with 'convert_string_expressions:'. If you changed selector in the previous example to be 'convert_string_expressions:age > 18', then it would match the message.

To "fix" this you'd have to submit a PR to the ActiveMQ project which adds a new configuration parameter for the STOMP connector to make this behavior configurable. That said, there should be no reason to change this as it shouldn't be hurting anything.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM