考虑到我唯一的要求是使用ActiveMQ的示例,我如何让我的ActiveMQ使用JDBC连接,而不创建使用VM传输的嵌入式连接。
这是我的工厂豆子:
@Bean
public ActiveMQConnectionFactory connectionFactory() {
logger.info("ActiveMQConnectionFactory");
ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(brokerUrl);
activeMQConnectionFactory.setTrustAllPackages(true);
RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
redeliveryPolicy.setRedeliveryDelay(15000);
redeliveryPolicy.setMaximumRedeliveries(-1);
activeMQConnectionFactory.setRedeliveryPolicy(redeliveryPolicy);
return activeMQConnectionFactory;
}
我在url:tcp//0.0.0.0:61616中公开了ACTIVEMQ的图像,但即使配置了如下所示的JDBC适配器,我也不能将消息持久化到SQL服务器中,ACTIVEMQ正在接收此消息,并使用KahaDB作为默认设置。使用JDBC的唯一方法是从tcp更改为vm:localhost,但这会创建一个嵌入的actiemq。
@Bean
public BrokerService broker(DataSource dataSource, ActiveMQConnectionFactory activeMQConnectionFactory) throws Exception {
logger.info("BrokerService");
final BrokerService broker = new BrokerService();
JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter(dataSource, new OpenWireFormat());
jdbc.setUseLock(true);
Statements statements = jdbc.getStatements();
statements.setBinaryDataType(BINARY_DATA_TYPE);
broker.setUseJmx(true);
broker.setPersistent(true);
broker.setPersistenceAdapter(jdbc);
broker.addConnector(format("vm:(broker:(tcp://localhost:61616,network:static:%s)?persistent=true)", brokerUrl));
logger.info("BrokerService URL: " + broker.getTransportConnectors().get(0).getConnectUri().toString());
return broker;
}
1条答案
按热度按时间ih99xse11#
建议使用XML文件配置代理。与编写经纪人代码相比,更容易管理。
ActiveMQ JDBC信息:ref:https://activemq.apache.org/jdbc-support
持久性适配器信息:ref:https://activemq.apache.org/persistence
启动引用XML文件的嵌入式代理:ref:https://activemq.apache.org/vm-transport-reference
具体地说: