2016-07-29 140 views
1

我正在尝试设置一个使用嵌入式JMS队列的简单Spring Boot应用程序。我与HornetQ成功,但是当我尝试转换为Artemis时,ArtemisConnectionFactory出现故障。这是我用于HornetQ的代码。任何帮助将是欣赏。Spring Boot Apache Artemis嵌入式JMS队列Eample

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

回答

0

对我来说你的代码工作。为了测试应用程序,我添加了一个产生消息的CommandLineRunner

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

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

compile('org.springframework.boot:spring-boot-starter-artemis') 
compile('org.apache.activemq:artemis-jms-server')