gpt4 book ai didi

java - 从 activemq.xml 文件中读取 Broker 配置并使用 Java 代码启动 Broker

转载 作者:行者123 更新时间:2023-12-02 12:48:19 28 4
gpt4 key购买 nike

我想读取 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(“/conf/activemq.xml”)

或者这是不可能的(尽管我认为是)。因此启动代理的唯一方法是从命令行并编写 java 客户端(生产者/消费者)来连接到它。

最佳答案

尝试

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

关于java - 从 activemq.xml 文件中读取 Broker 配置并使用 Java 代码启动 Broker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44678253/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com