代码之家  ›  专栏  ›  技术社区  ›  Pustovalov Dmitry

在artemismq中对队列设置筛选器时出错

  •  0
  • Pustovalov Dmitry  · 技术社区  · 7 年前

    尝试通过配置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文档,config的语法必须与选择器的语法相同。怎么了?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Justin Bertram    7 年前

    这里的问题是 filter 正在XML中定义,XML对允许哪些字符和不允许哪些字符有自己的规则。简单地说,XML无效。尝试使用:

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

    通过逃避 < XML应该正确解析的字符。

    推荐文章