Search code examples
phpactivemq-classicmessage-queuestomp

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.

enter image description here

How can I fix this prefix?


Solution

  • 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.