2016-07-29 49 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')