2015-05-15 14 views
9

के साथ ActiveMQ कॉन्फ़िगरेशन मैं स्प्रिंग बूट के साथ एंबेडेड के रूप में ActiveMQ का उपयोग करता हूं। ऐसा लगता है कि ब्रोकर को सक्रिय ActiveQQConnectionFactory बनाया गया है। मैं समझता हूं कि ब्रोकर को कॉन्फ़िगर करने का तरीका ब्रोकर के साथ क्वेरी में पैरामीटर सेट करना है। जैसा कि यहां बताया गया है: http://activemq.apache.org/how-do-i-embed-a-broker-inside-a-connection.htmlस्प्रिंग बूट

मैं डीएलक्यू के बारे में कुछ विशेषताओं को सेट करना चाहता हूं, इसलिए यह गंतव्य नीति में विशेषता है, लेकिन विशेषता प्रकार एक साधारण प्रकार नहीं है लेकिन एक जटिल प्रकार है, मैं अक्षम करने के लिए क्वेरी पैरामीटर कैसे लिख सकता हूं डीएलक्यू, कृपया?

उत्तर

3

अच्छा सवाल। ऑटो ब्रोकर निर्माण के लिए वीएम-ट्रांसपोर्ट पर गुण बहुत अच्छे हैं, लेकिन केवल एक बिंदु तक जो मुझे लगता है कि आपने मारा है।

मेरा सुझाव यह है कि आप ब्रोकर कॉन्फ़िगरेशन को परिभाषित करते हैं जैसा कि आप आम तौर पर एक्सएमएल में करते थे और फिर यूआरआई में इस एक्सएमएल को देखें। गंतव्य नीतियां वास्तव में एक जटिल संरचना होती हैं और मुझे नहीं लगता कि यह संभव है कि यदि संभव हो तो सरल क्वेरी पैरा के साथ उन्हें परिभाषित करना एक अच्छा विचार होगा।

vm://localhost?brokerConfig=xbean:activemq.xml 
1

मुझे यह समस्या थी और वसंत कॉन्फ़िगरेशन फ़ाइल का उपयोग करके इसे हल किया गया। मेरे मामले में, मैं अपने ब्रोकर को जारी रखने के लिए कॉन्फ़िगर करना चाहता था।

मैंने अपने पोम में आवश्यक libs को जोड़ा: सक्रिय एमक्यू-ब्रोकर, एक्टिवएमक-वसंत, वसंत-जेएमएस (और मेरे मामले में, activemq-leveldb-store) सहित।

मेरे वसंत xml फ़ाइल इस तरह देखा:

<beans 
    xmlns="http://www.springframework.org/schema/beans" 
    xmlns:amq="http://activemq.apache.org/schema/core" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 
    http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd"> 

<broker xmlns="http://activemq.apache.org/schema/core" brokerName="xyz"> 
     <persistenceAdapter> 
     <levelDB directory="activemq-data"/> 
     </persistenceAdapter> 

    <transportConnectors> 
     <transportConnector uri="vm:localhost?persistent=true" /> 
    </transportConnectors> 

    </broker> 
</beans> 

और मैं अपने विन्यास वर्गों में से एक में वसंत फ़ाइल पंजीकृत:

@ImportResource("activemq-spring.xml") 

यही काम किया है।

मैंने पहले xbeans समाधान की कोशिश की, लेकिन मैं अटक गया क्योंकि मुझे कुछ xbeans कक्षाएं याद आ रही थीं, और मुझे नहीं पता था कि यह संस्करण संस्करण या क्या था। मैं ActiveMQ का उपयोग कर रहा 5.12.1

1

पारितोषिक @Petter और @April जवाब, एक ही समाधान नीचे लेकिन अधिक पूरा नमूने के साथ:

1. Petter solution, import activemq.xml at connnection factory url

build.gradle

ext { 
    springBootVersion = "1.5.3.RELEASE" 
    activeMQVersion = "5.14.5" 
} 

dependencies { 

    compile("org.springframework.boot:spring-boot-starter-activemq:${springBootVersion}") 
    compile("org.apache.activemq:activemq-broker:${activeMQVersion}") 

    testCompile("org.springframework.boot:spring-boot-starter-test:${springBootVersion}") 
    testCompile group: 'org.apache.activemq', name: 'activemq-spring', version: "${activeMQVersion}" 
    testCompile("junit:junit:4.12") 

} 

src/main/resource/activemq.xml

<beans xmlns="http://www.springframework.org/schema/beans" 
      xmlns:amq="http://activemq.apache.org/schema/core" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation=" 
       http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans.xsd 
       http://activemq.apache.org/schema/core 
       http://activemq.apache.org/schema/core/activemq-core-5.4.0.xsd 
     "> 
    <broker xmlns="http://activemq.apache.org/schema/core" brokerName="broker1" persistent="false" > 
     <transportConnectors> 
      <transportConnector name="vm" uri="vm://broker1"/> 
     </transportConnectors> 
    </broker> 
</beans> 

Config.java

@EnableJms 
@SpringBootApplication 
@EnableAutoConfiguration 
@Configuration 
public class Config {} 

application.properties

spring.activemq.broker-url=vm://broker1?brokerConfig=xbean:activemq.xml 

2. April solution, import activemq.xml at Spring Configuration

बस को दूर application.properties तो कॉन्फ़िग को @ImportResource("classpath:activemq.xml") प्रविष्टि जोड़ने।जावा

Config.java

@EnableJms 
@SpringBootApplication 
@EnableAutoConfiguration 
@Configuration 
@ImportResource("classpath:activemq.xml") 
public class Config {}