Spring Loaded Inline ActiveMQ Messages

In my Spring Boot application, I have configured Embedded Apache ActiveMQ.

@Configuration
@EnableJms
public class ActiveMQConfig {

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

}

      

I use the following code to send messages:

@Autowired
private JmsMessagingTemplate jmsMessagingTemplate;

@Autowired
private Queue queue;

this.jmsMessagingTemplate.convertAndSend(this.queue, message);

      

I am currently using ActiveMQ in memory, this is mine application.properties

:

#ActiveMQ
spring.activemq.in-memory=true
spring.activemq.pool.enabled=false
spring.activemq.packages.trust-all=true

      

Since I don't want to lose messages that have already been queued, for example, during application restart, I need to configure my built-in ActiveMQ to persist the data.

Could you please show how this can be done with Spring Boot Configuration?

+3


source to share


1 answer


BrokerService is persistent by default, did you do some tests?

if you want you can define it to override:

@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;
}

      



or

@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>

      

+3


source







All Articles