我想阅读some_dir / activemq.xml文件,以便我可以使用org.apache.activemq.broker.BrokerService创建代理,该代理将根据提供的文件进行所有配置。我尝试以编程方式设置属性:
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(&#34; /conf/activemq.xml")
或者它是不可能的(虽然我认为是)。所以启动代理的唯一方法是从命令行和编写java客户端(生产者/消费者)连接到它。
答案 0 :(得分: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