Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot Spring引导嵌入ActiveMQ持久消息_Spring Boot_Activemq_Spring Jms - Fatal编程技术网

Spring boot Spring引导嵌入ActiveMQ持久消息

Spring boot Spring引导嵌入ActiveMQ持久消息,spring-boot,activemq,spring-jms,Spring Boot,Activemq,Spring Jms,在我的Spring Boot应用程序中,我配置了嵌入式ApacheActiveMQ @Configuration @EnableJms public class ActiveMQConfig { @Bean public Queue queue() { return new ActiveMQQueue("import.decisions.queue"); } } 为了发送信息,我使用以下代码: @Autowired private JmsMessag

在我的Spring Boot应用程序中,我配置了嵌入式ApacheActiveMQ

@Configuration
@EnableJms
public class ActiveMQConfig {

    @Bean
    public Queue queue() {
        return new ActiveMQQueue("import.decisions.queue");
    }

}
为了发送信息,我使用以下代码:

@Autowired
private JmsMessagingTemplate jmsMessagingTemplate;

@Autowired
private Queue queue;

this.jmsMessagingTemplate.convertAndSend(this.queue, message);
现在我使用内存中的ActiveMQ,这是我的
应用程序。属性

#ActiveMQ
spring.activemq.in-memory=true
spring.activemq.pool.enabled=false
spring.activemq.packages.trust-all=true
因为我不想丢失已经排队的消息,例如在应用程序重新启动期间,我需要配置嵌入式ActiveMQ来持久化数据


您能演示一下如何使用Spring引导配置完成吗?

默认情况下BrokerService是持久的,您做过一些测试吗

如果需要,可以将其定义为覆盖:

@Bean(initMethod = "start", destroyMethod = "stop")
public BrokerService broker() throws Exception {
    final BrokerService broker = new BrokerService();
    //broker.addConnector("tcp://localhost:61616");
    broker.addConnector("vm://localhost");
    PersistenceAdapter persistenceAdapter = new KahaDBPersistenceAdapter();
    File dir = new File(System.getProperty("user.home") + File.separator + "kaha");
    if (!dir.exists()) {
        dir.mkdirs();
    }
    persistenceAdapter.setDirectory(dir);
    broker.setPersistenceAdapter(persistenceAdapter);
    broker.setPersistent(true);
    return broker;
}


org.apache.activemq
activemq存储

谢谢你的回答。我已向队列中添加了约1000条消息。然后在执行过程中,我终止了我的应用程序,然后再次启动它。成功启动后,什么也没有发生。使用者不使用以前排队的消息。另外,为了使用重写的代理服务测试您的方法,我在应用程序类路径中找不到
kahadbpersistencedapter
类。现在我只在我的Maven
pom.xml
中添加了
spring boot starter activemq
,以便启动并运行activemq。还应该添加哪些其他工件?很抱歉,我忘记了mvn依赖项,我已经更新了答案谢谢,我已经添加了activemq存储,现在该方法开始工作了!
@Bean(initMethod = "start", destroyMethod = "stop")
public BrokerService broker() throws Exception {
    final BrokerService broker = new BrokerService();
    //broker.addConnector("tcp://localhost:61616");
    broker.addConnector("vm://localhost");
    broker.setPersistent(true);
    // default messages store is under AMQ_HOME/data/KahaDB/
    return broker;
}
<dependency>
  <groupId>org.apache.activemq</groupId>
  <artifactId>activemq-kahadb-store</artifactId>
</dependency>