SpringBoot整合ActiveMQ開啟持久化


1.開啟隊列持久化

只需要添加三行代碼

jmsTemplate.setDeliveryMode(2);
jmsTemplate.setExplicitQosEnabled(true);
jmsTemplate.setDeliveryPersistent(true);

 

 

 

2. 開啟主題持久化,啟動類添加如下配置

@Bean(name = "topicListenerFactory")
            public JmsListenerContainerFactory<DefaultMessageListenerContainer> topicListenerFactory(ConnectionFactory connectionFactory){
                DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();

                factory.setSubscriptionDurable(true);// Set this to "true" to register a durable subscription,

                factory.setClientId("B");

                factory.setConnectionFactory(connectionFactory);
                return factory;

            }

//消費者消費  destination隊列或者主題的名字
            @JmsListener(destination = "boot_topic",containerFactory = "topicListenerFactory")
            public void getMessage(TextMessage message,Session session) throws JMSException {
                System.out.println("消費者獲取到消息:"+message.getText());
            }

這里需要注意,主題的數據不會被消費,會被一直記錄下來,只能手動清除

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM