Apache MQ Artemis - MQTT retained message not available for a client that connects to other node in cluster

白昼怎懂夜的黑 提交于 2020-07-09 06:53:45

问题


I have 4 ActiveMQ Artemis 2.10.1 instances running in a cluster. A client (A) connects to one of the nodes and publishes MQTT message with QoS=0 and retain=true. When a new MQTT client (B) connects to another node in the cluster and subscribes for the topic, the previously sent message is not received. When than client A publishes a next message, client B gets the message.

Is it a bug in Artemis that retained message sent by A is not received by a client B when it connects to another node in the cluster or I'm missing something?

If I connect client A and client B to the same node in the cluster, client B gets the message after it is connected and subscribed for the topic.

broker.xml - I use poc.# for the testing:

<configuration xmlns="urn:activemq"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:xi="http://www.w3.org/2001/XInclude"
               xsi:schemaLocation="urn:activemq /schema/artemis-configuration.xsd">

    <core xmlns="urn:activemq:core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:activemq:core ">

        <name>Broker 01</name> <!-- changed on every node -->

        <persistence-enabled>true</persistence-enabled>
        <journal-type>NIO</journal-type>
        <paging-directory>data/paging</paging-directory>
        <bindings-directory>data/bindings</bindings-directory>
        <journal-directory>data/journal</journal-directory>
        <large-messages-directory>data/large-messages</large-messages-directory>
        <journal-datasync>true</journal-datasync>
        <journal-min-files>2</journal-min-files>
        <journal-pool-files>10</journal-pool-files>
        <journal-device-block-size>4096</journal-device-block-size>
        <journal-file-size>10M</journal-file-size>

        <journal-buffer-timeout>1328000</journal-buffer-timeout>

        <journal-max-io>1</journal-max-io>
        <disk-scan-period>5000</disk-scan-period>
        <max-disk-usage>90</max-disk-usage>
        <critical-analyzer>true</critical-analyzer>
        <critical-analyzer-timeout>120000</critical-analyzer-timeout>
        <critical-analyzer-check-period>60000</critical-analyzer-check-period>
        <critical-analyzer-policy>HALT</critical-analyzer-policy>

        <acceptors>
            <acceptor name="artemis">tcp://0.0.0.0:61616</acceptor>
            <acceptor name="mqtt">tcp://0.0.0.0:1883?protocols=MQTT</acceptor>
        </acceptors>

        <connectors>
            <connector name="netty-connector">tcp://10.0.0.2:61616</connector>  <!-- changed on every node -->
        </connectors>

        <broadcast-groups>  
            <broadcast-group name="my-broadcast-group">  
                <group-address>231.7.7.7</group-address>  
                <group-port>9876</group-port>  
                <broadcast-period>2000</broadcast-period>  
                <connector-ref>netty-connector</connector-ref>  
            </broadcast-group>  
        </broadcast-groups>
        <discovery-groups>  
            <discovery-group name="my-discovery-group">  
                <group-address>231.7.7.7</group-address>  
                <group-port>9876</group-port>  
                <refresh-timeout>10000</refresh-timeout>  
            </discovery-group>  
        </discovery-groups>

        <cluster-connections>
             <cluster-connection name="artemis-cluster">
                <address></address>
                <connector-ref>netty-connector</connector-ref>
                <retry-interval>1000</retry-interval>
                <use-duplicate-detection>true</use-duplicate-detection>
                <message-load-balancing>ON_DEMAND</message-load-balancing>
                <max-hops>1</max-hops>
                <discovery-group-ref discovery-group-name="my-discovery-group"/> 
             </cluster-connection>
        </cluster-connections>

        <security-settings>
            <security-setting match="#">
                <permission type="createNonDurableQueue" roles="amq"/>
                <permission type="deleteNonDurableQueue" roles="amq"/>
                <permission type="createDurableQueue" roles="amq"/>
                <permission type="deleteDurableQueue" roles="amq"/>
                <permission type="createAddress" roles="amq"/>
                <permission type="deleteAddress" roles="amq"/>
                <permission type="consume" roles="amq"/>
                <permission type="browse" roles="amq"/>
                <permission type="send" roles="amq"/>
                <!-- we need this otherwise ./artemis data imp wouldn't work -->
                <permission type="manage" roles="amq"/>
            </security-setting>

            <!-- Security setting for testing. -->
            <security-setting match="poc.#">
                <permission type="createNonDurableQueue" roles="read-write"/>
                <permission type="deleteNonDurableQueue" roles="read-write"/>
                <permission type="createDurableQueue" roles="read-write"/>
                <permission type="deleteDurableQueue" roles="read-write"/>
                <permission type="createAddress" roles="read-write"/>
                <permission type="deleteAddress" roles="write"/>
                <permission type="consume" roles="read-write"/>
                <permission type="browse" roles="read-write"/>
                <permission type="send" roles="write"/>
            </security-setting>
        </security-settings>

        <address-settings>
            <address-setting match="activemq.management#">
                <dead-letter-address>DLQ</dead-letter-address>
                <expiry-address>ExpiryQueue</expiry-address>
                <redelivery-delay>0</redelivery-delay>
                <max-size-bytes>-1</max-size-bytes>
                <message-counter-history-day-limit>10</message-counter-history-day-limit>
                <address-full-policy>PAGE</address-full-policy>
                <auto-create-queues>true</auto-create-queues>
                <auto-create-addresses>true</auto-create-addresses>
                <auto-create-jms-queues>true</auto-create-jms-queues>
                <auto-create-jms-topics>true</auto-create-jms-topics>
            </address-setting>
            <address-setting match="#">
                <dead-letter-address>DLQ</dead-letter-address>
                <expiry-address>ExpiryQueue</expiry-address>
                <redelivery-delay>0</redelivery-delay>
                <max-size-bytes>-1</max-size-bytes>
                <message-counter-history-day-limit>10</message-counter-history-day-limit>
                <address-full-policy>PAGE</address-full-policy>
                <auto-create-queues>true</auto-create-queues>
                <auto-create-addresses>true</auto-create-addresses>
                <auto-create-jms-queues>true</auto-create-jms-queues>
                <auto-create-jms-topics>true</auto-create-jms-topics>
            </address-setting>

            <!-- Address setting for testing -->
            <address-setting match="poc.#">
                <dead-letter-address>DLQ</dead-letter-address>
                <expiry-address>ExpiryQueue</expiry-address>
                <redelivery-delay>0</redelivery-delay>
                <max-size-bytes>-1</max-size-bytes>
                <message-counter-history-day-limit>10</message-counter-history-day-limit>
                <address-full-policy>PAGE</address-full-policy>
                <auto-create-queues>true</auto-create-queues>
                <auto-delete-queues>true</auto-delete-queues>
                <auto-create-addresses>true</auto-create-addresses>
                <auto-delete-addresses>true</auto-delete-addresses>
                <default-address-routing-type>MULTICAST</default-address-routing-type>
            </address-setting>
        </address-settings>

        <addresses>
            <address name="DLQ">
                <anycast>
                    <queue name="DLQ" />
                </anycast>
            </address>
            <address name="ExpiryQueue">
                <anycast>
                    <queue name="ExpiryQueue" />
                </anycast>
            </address>
        </addresses>
    </core>
</configuration>


回答1:


You need to set this <address-setting> for the address you're concerned with:

<redistribution-delay>0</redistribution-delay>

See the "Message Redistribution" section of the ActiveMQ Artemis documentation for more details on this.



来源:https://stackoverflow.com/questions/58744799/apache-mq-artemis-mqtt-retained-message-not-available-for-a-client-that-connec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!