自动删除地址在ActiveMQ Artemis中不起作用

发布于 2025-01-27 22:03:29 字数 3112 浏览 3 评论 0原文

当不再使用该地址时,我遇到的问题会自动删除动态地址。

以下是Broker.xml的摘录:

         <address-setting match="#">
            <dead-letter-address>DLQ</dead-letter-address>
            <expiry-address></expiry-address>
            <redelivery-delay>0</redelivery-delay>
            <expiry-delay>10</expiry-delay>
            <max-size-bytes>-1</max-size-bytes>
            <max-size-messages>-1</max-size-messages>
            <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-delete-queues>true</auto-delete-queues>
            <auto-delete-addresses>true</auto-delete-addresses>
            <auto-delete-created-queues>true</auto-delete-created-queues>
            <auto-delete-queues-message-count>-1</auto-delete-queues-message-count>
         </address-setting>

以下是创建主题的生产者代码:

    /////////////////////////////////////
    //Constructor to establish connection
    /////////////////////////////////////
    
    public ActiveMQ(String amq_url) throws JMSException, NamingException{
        jndi_env = new Hashtable<String, Object>();
        jndi_env.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
        jndi_env.put(InitialContext.PROVIDER_URL, amq_url);
        ic = new InitialContext(jndi_env);
        ConnectionFactory connectionFactory = (ConnectionFactory) ic.lookup("ConnectionFactory");
        this.connection = (ActiveMQConnection) connectionFactory.createConnection();
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    }
    
    ///////////useTopic()///////////
    //create/select topic
    ////////////////////////////////    
    public void useTopic(String topicName) throws JMSException, NamingException{
        if (producer != null) producer.close();
        this.topic = (Destination) ic.lookup("dynamicTopics/"+topicName);
        this.producer = session.createProducer(topic);
    }

    public void closeConnection() throws JMSException{
        if (producer != null) producer.close();
        if (connection != null) connection.stop();
        if (session != null) session.close();
        if (connection != null) connection.close();
    } 

}

当在ActiveMQ Artemis中创建地址时,它看起来与下拉列表中的其他其他代码(EG Test_sdcdata vs expryqueue)。

我和我的同事无法弄清楚为什么在不重新启动ActiveMQ Artemis服务器的情况下,该特定地址不会基于上述删除。该控制台表明,在我停止创建主题的程序后,没有任何消费者或生产者连接。该主题基于ActiveMQ Artemis Web控制台的消息数为0。有什么想法吗?我觉得我没有设置需要设置的特定价值。

I'm having issues getting ActiveMQ Artemis to automatically delete a dynamic address when there it is no longer used.

Below is an excerpt from the broker.xml:

         <address-setting match="#">
            <dead-letter-address>DLQ</dead-letter-address>
            <expiry-address></expiry-address>
            <redelivery-delay>0</redelivery-delay>
            <expiry-delay>10</expiry-delay>
            <max-size-bytes>-1</max-size-bytes>
            <max-size-messages>-1</max-size-messages>
            <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-delete-queues>true</auto-delete-queues>
            <auto-delete-addresses>true</auto-delete-addresses>
            <auto-delete-created-queues>true</auto-delete-created-queues>
            <auto-delete-queues-message-count>-1</auto-delete-queues-message-count>
         </address-setting>

Below is the producer code that creates the topic:

    /////////////////////////////////////
    //Constructor to establish connection
    /////////////////////////////////////
    
    public ActiveMQ(String amq_url) throws JMSException, NamingException{
        jndi_env = new Hashtable<String, Object>();
        jndi_env.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
        jndi_env.put(InitialContext.PROVIDER_URL, amq_url);
        ic = new InitialContext(jndi_env);
        ConnectionFactory connectionFactory = (ConnectionFactory) ic.lookup("ConnectionFactory");
        this.connection = (ActiveMQConnection) connectionFactory.createConnection();
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    }
    
    ///////////useTopic()///////////
    //create/select topic
    ////////////////////////////////    
    public void useTopic(String topicName) throws JMSException, NamingException{
        if (producer != null) producer.close();
        this.topic = (Destination) ic.lookup("dynamicTopics/"+topicName);
        this.producer = session.createProducer(topic);
    }

    public void closeConnection() throws JMSException{
        if (producer != null) producer.close();
        if (connection != null) connection.stop();
        if (session != null) session.close();
        if (connection != null) connection.close();
    } 

}

When the address is created in ActiveMQ Artemis it looks different than the other ones in the drop down list (e.g. TEST_SDCData vs ExpiryQueue).

Addresses

My coworker and I are unable to figure out why this specific address will not delete based on the above without restarting the ActiveMQ Artemis server. The console shows that there are no consumers or producers connected after I stop the program that creates the topic. The topic has a message count of 0 based on the ActiveMQ Artemis web console. Any thoughts? I feel like I'm not setting a specific value that needs to be set.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

○愚か者の日 2025-02-03 22:03:29

据我所知,一切都按设计工作。让我解释一下...

当JMS客户端向主题发送消息时,自动创建 - addressestrue,经纪人将通过根据根据命名命名的地址来响应消息发送的位置。但是,由于JMS主题没有消费者,因此消息将简单地删除。这符合基本发布/订阅语义。

目前将无法删除该地址,因为经纪人知道没有在其上创建任何消费者,因此实际上并未在功能上使用。如果经纪人在这种情况下删除地址,则必须在发送另一条消息时立即重新创建它。随着消息被发送到浪费宝贵的资源,它最终会一遍又一遍地创建和删除地址。经纪人通过等待至少在地址上创建了一个消费者之前避免这种病理状况(即消费者断开连接后)。

您的地址看起来与Web控制台中的“ Expiryqueue”和“ DLQ”地址不同的原因是因为这两个地址上有队列。您的地址以及“ ActiveMQ.Theotifications”地址没有队列。

如果您不清楚地址和队列如何相互关系,则可以在文档

As far as I can tell everything is working as designed. Let me explain...

When a JMS clients sends a message to a topic and auto-create-addresses is true then the broker will respond by creating an address named according to where the message was sent. However, since the JMS topic has no consumers the message will simply be dropped. This conforms with basic publish/subscribe semantics.

The address won't be deleted at this point because the broker knows that no consumers have ever been created on it and therefore it hasn't actually been functionally used. If the broker were to delete the address in this situation then it would have to re-create it immediately when another message was sent to it. It would end up creating and deleting the address over and over as messages were sent to it wasting valuable resources. The broker avoids this pathological situation by waiting until at least one consumer has been created on the address before deleting it (i.e. once the consumer disconnects).

The reason your address looks different from the "ExpiryQueue" and "DLQ" addresses in the web console is because those two addresses have queues on them. Your address as well as the "activemq.notifications" address have no queues.

If you're unclear on how addresses and queues relate to each other you can read more in the documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文