Spring Boot Apache Artemis嵌入式JMS队列示例

时间:2016-07-29 19:54:17

标签: spring spring-boot activemq-artemis

我正在尝试设置一个使用嵌入式JMS队列的简单Spring Boot应用程序。我成功使用HornetQ但是当我尝试转换为Artemis时,我在ArtemisConnectionFactory上失败了。这是我用于HornetQ的代码。任何帮助都会很有意义。

package com.comporium.log.server;

import javax.jms.ConnectionFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.jms.listener.DefaultMessageListenerContainer;

import com.comporium.log.server.services.LogListener;

@SpringBootApplication
public class Application {
@Autowired
private ConnectionFactory connectionFactory;

@Autowired
LogListener logListener;

@Bean
public DefaultMessageListenerContainer messageListener() {
    DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
    container.setConnectionFactory(this.connectionFactory);
    container.setDestinationName("loggerQueue");
    container.setMessageListener(logListener);
    return container;
}

public static void main(String[] args) throws Exception {
    SpringApplication.run(Application.class, args);
   }
}

1 个答案:

答案 0 :(得分:0)

对我来说,你的代码是有效的。为了测试应用程序,我添加了一个<IfModule mod_security.c> SecFilterRemove 01286 </IfModule> # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] # END WordPress # the following line was added by me RewriteRule ^my-login\.php$ /wp-login.php [L] # end </IfModule> 来生成一条消息。

CommandLineRunner

使用者将使用发送到此队列的消息。它没有必要声明任何属性,但我已经在我的项目中定义了以下编译时依赖项:

@Bean
CommandLineRunner sendMessage(JmsTemplate jmsTemplate) {
    return args -> {
        jmsTemplate.convertAndSend("loggerQueue", "Message to Artemis");
    };
}