zoukankan      html  css  js  c++  java
  • 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());
                }

    这里需要注意,主题的数据不会被消费,会被一直记录下来,只能手动清除

  • 相关阅读:
    [OpenCV] Ptr类模板
    [OpenCV]Mat类详解
    [C++] Vector用法
    [OpeCV] highgui头文件
    c++中的.hpp文件
    【2017】KK English
    CMake Tutorial & Example
    [g2o]C++图优化库
    Teradata基础教程中的数据库试验环境脚本
    Oracle中对象权限与系统权限revoke
  • 原文地址:https://www.cnblogs.com/chx9832/p/12313826.html
Copyright © 2011-2022 走看看