Apache ActiveMQ的基础配置与Spring集成配置
BrokerService
1 2 3 4 5 6 7 8 9
BrokerService brokerService = new BrokerService(); TransportConnector transport = brokerService.addConnector("tcp://localhost:61616" ); transport.setDiscoveryUri(...); brokerService.setPersistenceAdapter(...); brokerService.start();
activemq & spring
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns ="http://www.springframework.org/schema/beans" 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" > <bean id ="connectionFactory" class ="org.apache.activemq.ActiveMQConnectionFactory" > <property name ="brokerURL" value ="tcp://localhost:61616" /> </bean > <bean id ="queue" class ="org.apache.activemq.command.ActiveMQQueue" autowire ="constructor" > <constructor-arg value ="moon.inbondMessage" /> </bean > <bean id ="datasource" class ="org.h2.jdbcx.JdbcDataSource" > <property name ="url" value ="jdbc:h2:file:~/.h2/harmony" /> <property name ="user" value ="sa" /> <property name ="password" value ="" /> </bean > <bean id ="persistenceAdapter" class ="org.apache.activemq.store.jdbc.JDBCPersistenceAdapter" > <property name ="dataSource" ref ="datasource" /> </bean > <bean id ="brokerService" class ="org.apache.activemq.broker.BrokerService" init-method ="start" destroy-method ="stop" scope ="singleton" > <property name ="brokerId" value ="localhost" /> <property name ="brokerName" value ="test-farmework-activemq" /> <property name ="useJmx" value ="true" /> <property name ="persistent" value ="true" /> <property name ="persistenceAdapter" ref ="persistenceAdapter" /> <property name ="transportConnectors" > <list > <bean class ="org.apache.activemq.broker.TransportConnector" > <property name ="uri" value ="tcp://localhost:61616" /> </bean > </list > </property > <property name ="shutdownHooks" > <list > <bean class ="org.apache.activemq.hooks.SpringContextHook" /> </list > </property > </bean > </beans >
VM Transport
在VM内部而无需通过联网的方式传输, 当第一个使用者(客户端)使用时将启动一个内置的brokerService, 其他broker使用时将自动连接到已经启动的brokerService, 当且仅当最后一个使用者关闭时候brokerService才关闭.
1 2
// 相同broker连接条件为BrokerName相同 vm://brokerName?transportOptions
http://activemq.apache.org/vm-transport-reference.html http://activemq.apache.org/networks-of-brokers.html http://activemq.apache.org/features.html
近期评论