2017-06-21 57 views
0

我想要讀取some_dir/activemq.xml文件,以便我可以使用org.apache.activemq.broker.BrokerService創建代理,根據提供的文件進行配置。我嘗試以編程方式設置屬性:從activemq.xml文件讀取代理配置並使用Java代碼啓動代理

TransportConnector tc = new TransportConnector(); 
    tc.setName("openwire"); 
    tc.setUri(new URI("tcp://localhost:61616?trace=true")); 

    List<TransportConnector> tcList = new ArrayList<TransportConnector>(); 
    tcList.add(tc); 
    broker.setTransportConnectors(tcList); 

    DiscoveryNetworkConnector nc = new DiscoveryNetworkConnector(); 
    nc.setName("Q:broker1->broker2"); 
    nc.setUri(new URI("static:(tcp://localhost:61616)")); 
    nc.setDuplex(false); 
    nc.setDecreaseNetworkConsumerPriority(false); 
    nc.setNetworkTTL(2); 
    nc.setDynamicOnly(true); 

    List<DiscoveryNetworkConnector> ncList = new ArrayList<DiscoveryNetworkConnector>(); 
    ncList.add(nc); 

    broker.setNetworkConnectors(ncList); 


    System.out.println(broker); 
    //broker.startTransportConnector(tc); 
    //broker.startAllConnectors(); 
    broker.start(); 

但它很長。 有什麼辦法可以做broker.readConfigFile(「/ conf/activemq.xml」)

或者這是不可能的(儘管我認爲是這樣)。因此,啓動代理的唯一方法是從命令行編寫Java客戶端(生產者/消費者)以連接到該客戶端。

回答

1

嘗試

org.apache.activemq.broker.BrokerService broker = org.apache.activemq.broker.BrokerFactory.createBroker(new URI("xbean:file:some_dir/activemq.xml")); 
broker.start(); 
沒有找到
<dependency> 
    <groupId>org.apache.activemq</groupId> 
    <artifactId>activemq-all</artifactId> 
    <version>5.xx.x</version> 
</dependency> 

http://activemq.apache.org/how-do-i-embed-a-broker-inside-a-connection.html

+0

特例去解決每個:org.eclipse.jetty.util.security.Constraint 組織/日蝕/碼頭/ server/UserIdentity org/eclipse/jetty/util/component/AbstractLifeCycle org.eclipse.jetty.security.HashLoginService IO/fabric8 /洞察/日誌/支持/ LogQuerySupportMBean io.fabric8.insight.log.log4j.Log4jLogQuery 組織/阿帕奇/公/日誌/的LogFactory 組織/阿帕奇/ xbean /春/上下文/ IMPL/URIEditor 組織/ springframework/context/ApplicationContext org/springframework/core/NestedRuntimeException org/springframework/beans/BeansException,其中罐子添加爲沒有運氣仍然:( – niranjan

+0

檢查我的更新,是否已添加activemq-all依賴項? –

+0

是activemq-all-5.11.1.jar和kahadb-5.5.0.jar被添加了,因此除了傳遞配置文件 – niranjan