在 ArtemisMQ 的队列上设置过滤器时出错

Error while setting filter on queue in ArtemisMQ

我在尝试通过 ArtemisMQ 配置在队列上配置过滤器时遇到问题 (broker.xml):

<address name="foo">
    <multicast>
      <queue name="filtered_foo">
        <durable>true</durable>
        <filter string="bar <> 42"/>
      </queue>
    </multicast>
</address>

尝试启动代理时出现错误:

[Fatal Error] :207:30: The value of attribute "string" associated with an element type "filter" must not contain the '<' character.
Exception in thread "main" org.xml.sax.SAXParseException; lineNumber: 207; columnNumber: 30; The value of attribute "string" associated with an element type "filter" must not contain the '<' character.
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:257)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:339)
    at org.apache.activemq.artemis.utils.XMLUtil.readerToElement(XMLUtil.java:90)
    at org.apache.activemq.artemis.utils.XMLUtil.stringToElement(XMLUtil.java:55)
    at org.apache.activemq.artemis.core.config.FileDeploymentManager.readConfiguration(FileDeploymentManager.java:76)
    at org.apache.activemq.artemis.integration.FileBroker.start(FileBroker.java:68)
    at org.apache.activemq.artemis.cli.commands.Run.execute(Run.java:82)
    at org.apache.activemq.artemis.cli.Artemis.internalExecute(Artemis.java:149)
    at org.apache.activemq.artemis.cli.Artemis.execute(Artemis.java:97)
    at org.apache.activemq.artemis.cli.Artemis.execute(Artemis.java:124)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.activemq.artemis.boot.Artemis.execute(Artemis.java:129)
    at org.apache.activemq.artemis.boot.Artemis.main(Artemis.java:49)

如果我使用相同的过滤器字符串为消费者设置选择器,它会起作用:

auto consumer = session->createConsumer("foo::filtered_foo", "bar <> 42");

根据 Artemis 文档,配置的语法必须与选择器的语法相同。有什么问题吗?

这里的问题是 filter 是在 XML 中定义的,XML 有自己的允许字符和不允许字符的规则。简而言之,您的 XML 无效。试试这个:

<filter string="bar &lt;> 42"/>

通过转义 < 字符,XML 应该可以正确解析。