论坛首页 入门技术论坛

Spring 配置 ActiveMQ

浏览 5205 次
该帖已经被评为新手帖
作者 正文
   发表时间:2008-06-08  

<!-- ////////////////////////////////////////// -->
<!-- For JMS (ActiveMQ) Begin -->
<!-- ////////////////////////////////////////// -->
<bean id="broker"
class="org.apache.activemq.xbean.BrokerFactoryBean">
<property name="config" value="classpath:activemq.xml" />
<property name="start" value="true" />
</bean>

<bean id="jmsConnectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory"
depends-on="broker">
<property name="brokerURL" value="vm://billing" />
</bean>

<!--<amq:connectionFactory id="jmsConnectionFactory" brokerURL="vm://localhost"/>-->

<bean id="jmsFactoryPool"
class="org.apache.activemq.pool.PooledConnectionFactory">
<property name="connectionFactory" ref="jmsConnectionFactory" />
</bean>

<bean id="jmsTransactionManager"
class="org.springframework.jms.connection.JmsTransactionManager">
<property name="connectionFactory" ref="jmsConnectionFactory" />
</bean>

<bean id="messageConverter"
class="org.springframework.jms.support.converter.SimpleMessageConverter" />

<bean id="jmsTemplate"
class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="jmsFactoryPool" />
<property name="messageConverter" ref="messageConverter" />
</bean>

<!-- ActiveMQ destinations to use -->
<amq:queue name="mBSettlementQueue"

physicalName="pp.queue.MBSettlementQueue" />

<!-- POJO which send success message by JmsTemplate and queue -->
<bean id="settlementMsgProducer"
class="com.pp.billing.settlement.SettlementMsgProducer">
<property name="jmsTemplate" ref="jmsTemplate" />
<property name="destination" ref="mBSettlementQueue" />
</bean>

<bean id="settlementMsgListener"
class="org.springframework.jms.listener.adapter.MessageListenerAdapter">
<constructor-arg>
<bean
class="com.PP.billing.settlement.SettlementMsgListener">
</bean>
</constructor-arg>
<!-- may be other method -->
<property name="defaultListenerMethod" value="onMessage" />
<!-- custom MessageConverter define -->
<property name="messageConverter" ref="messageConverter" />
</bean>

<bean id="listenerContainer"
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<!-- property name="transactionManager" ref="jmsTransactionManager" / -->

  <property name="connectionFactory" ref="jmsConnectionFactory" />
<property name="destination" ref="mBSettlementQueue" />
<property name="messageListener" ref="settlementMsgListener" />
<property name="concurrentConsumers" value="2" />
<property name="recoveryInterval" value="3000" />
<property name="receiveTimeout" value="10000" />
</bean>

public class SoapGWProducer {
	/**
	 *define log object to print log record
	 */
	private static Log log = LogFactory.getLog(SoapGWProducer.class);

	/**
	 *define jmsTemplate
	 */
	private JmsTemplate jmsTemplate;

	/**
	 *define destination
	 */
	private Queue destination;

	/**
	 * @return Returns jmsTemplate.
	 */
	public JmsTemplate getJmsTemplate() {
		return jmsTemplate;
	}

	/**
	 * @param jmsTemplate The jmsTemplate to set.
	 */
	public void setJmsTemplate(JmsTemplate jmsTemplate) {
		this.jmsTemplate = jmsTemplate;
	}


	/**
	 * @return destination
	 */
	public Queue getDestination() {
		return destination;
	}

	/**
	 * @param destination destination
	 */
	public void setDestination(Queue destination) {
		this.destination = destination;
	}

	/**
	 * send message to queue
	 * @param message message
	 */
	public void send(SoapGWMessage message) {
		try {
			jmsTemplate.convertAndSend(this.destination, message);
		} catch (Exception e) {
			log.error("send SoapGWMessage to SoapGWQueue error:"
					+ e.getMessage(), e);
		}
	}
}
public class SoapGWListener {

	/**
	 *define log object to print the log content
	 */
	private static Log log = LogFactory.getLog(SoapGWListener.class);

	/**
	 *define start message content
	 */
	public static final String START_MESSAGE = "Start";

	/**
	 * listerner message and do mblox SoapGWMessage
	 * @param message message
	 */
	public void onMessage(SoapGWMessage message) {
		if (log.isInfoEnabled()) {
			log.info("start SoapGWListener onMessage(),parameter is:" + message);
		}
		//get message informatio
		String phoneNumber = message.getPhoneNumber();
	}

activemq.xml

<?xml version="1.0" encoding="ISO-8859-1"?>

<beans>
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>

    <broker xmlns="http://activemq.org/config/1.0" brokerName="localhost">
    <persistenceAdapter>
        <jdbcPersistenceAdapter dataSource="#mssql-ds" useDatabaseLock="false">
            <statements>
                <statements binaryDataType ="binary(1024)"/>
            </statements>
         </jdbcPersistenceAdapter>
    </persistenceAdapter>

      <!-- Use the following to configure how ActiveMQ is exposed in JMX -->
      <managementContext>
         <managementContext connectorPort="1099" jmxDomainName="org.apache.activemq"/>
      </managementContext>
    </broker>

    <bean id="mssql-ds" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
      <property name="driverClass" value="$DB_DRIVERNAME"/>
      <property name="jdbcUrl" value="$DB_QUEUE_URL"/>
      <property name="user" value="$DB_QUEUE_USER"/>
      <property name="password" value="$DB_QUEUE_PASSWD"/>
      <property name="initialPoolSize" value="50"/>
      <property name="minPoolSize" value="20"/>
      <property name="maxPoolSize" value="1000"/>
      <property name="acquireIncrement" value="30"/>
      <property name="maxIdleTime" value="100"/>
      <property name="maxStatements" value="10"/>
    </bean>
</beans>
 

 

   发表时间:2008-09-15  
大哥,想问下这个标签“amq:queue”在我这里怎么报错啊?不知道需要导入什么包??麻烦告诉下,谢谢了!
0 请登录后投票
   发表时间:2008-10-20  
tzb2008 写道

大哥,想问下这个标签“amq:queue”在我这里怎么报错啊?不知道需要导入什么包??麻烦告诉下,谢谢了!

不好意思, 很长时间没有到这里来了。
你需要在文件头部加入如下代码:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:amq="http://activemq.org/config/1.0"[color=red][/color]
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
    http://activemq.org/config/1.0 http://roy.apache.org/activemq-4.1-working-V4.2.xsd">
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics