`
chengct521
  • 浏览: 20743 次
  • 性别: Icon_minigender_1
  • 来自: 西安
最近访客 更多访客>>
社区版块
存档分类
最新评论

Spring 配置 ActiveMQ

阅读更多

<!-- ////////////////////////////////////////// -->
<!-- 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>
 

 

分享到:
评论
2 楼 chengct521 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">
1 楼 tzb2008 2008-09-15  
大哥,想问下这个标签“amq:queue”在我这里怎么报错啊?不知道需要导入什么包??麻烦告诉下,谢谢了!

相关推荐

    spring配置activemq详解

    在"spring配置activemq详解"这个主题中,我们将探讨如何在Spring项目中配置和使用ActiveMQ。以下是对这个主题的详细说明: 1. **配置ActiveMQ**: - 首先,我们需要在项目中引入ActiveMQ的相关依赖,这通常通过在`...

    Spring和ActiveMQ整合的完整实例

    1. **配置ActiveMQ**:首先,我们需要在项目中添加ActiveMQ的依赖,可以通过Maven或Gradle实现。然后,配置ActiveMQ服务器,例如,可以在application.xml或application.properties中设置连接参数,如URL、用户名和...

    Spring集成ActiveMQ配置

    消息发送者通常不会在Spring配置文件中直接配置,而是利用Spring提供的JMS模板进行消息的发送。同样地,消息接收者也并非直接由Spring初始化,而是通过注入JMS模板来接收消息。 为了确保消息的正常接收,需要在应用...

    spring集成activemq例子demo

    2. **Spring配置ActiveMQ** - 在Spring的配置文件(如`applicationContext.xml`)中引入JMS相关的XML命名空间: ```xml xmlns:jms="http://www.springframework.org/schema/jms" xsi:schemaLocation=...

    Spring和ActiveMQ的整合实例源码ActiveMQSpringDemo.zip

    1. **Spring配置ActiveMQ**:Spring通过XML配置文件或Java配置类来定义JMS模板和消息监听器容器,配置ActiveMQ连接工厂和目的地。这些配置会创建与ActiveMQ服务器的连接,并设置消息生产者和消费者的细节。 2. **...

    spring使用activeMQ实现消息发送

    1. **配置ActiveMQ**:在开始之前,我们需要在本地或者远程部署一个ActiveMQ服务器。配置文件通常为`activemq.xml`,在这里可以设置broker(消息代理)的属性,如端口、存储策略等。在Spring应用中,我们可以通过...

    activemq spring 客户端配置

    当一个服务器不可用时,Spring配置的连接工厂会自动尝试连接到Zookeeper中标识的其他复制节点。 以上就是关于“activemq spring 客户端配置”的主要内容。通过这些步骤,你可以构建一个能够在Spring环境中与...

    spring整合Activemq源码

    - **配置ActiveMQ**:在Spring应用中,我们需要添加ActiveMQ的相关依赖,并在配置文件中定义ConnectionFactory和Destination。ConnectionFactory是连接到消息代理的工厂,Destination则是消息的目标,可以是Queue或...

    spring+activemq

    接下来,**Spring与ActiveMQ的集成**:在Spring应用中配置ActiveMQ,通常需要在Spring配置文件中定义`JmsTemplate`和`DefaultMessageListenerContainer`。`JmsTemplate`用于发送消息,而`...

    Spring-ActiveMQ.rar_Spring Activemq_activemq_activemq spring

    2. **Spring配置** 要在Spring应用中配置ActiveMQ,我们需要在Spring的配置文件(如:applicationContext.xml)中添加以下内容: - 引入JMS相关的命名空间:`&lt;beans xmlns="http://www.springframework.org/schema...

    activemq-3:使用spring配置activemq的发布订阅模式的示例

    标题中的“activemq-3:使用spring配置activemq的发布订阅模式的示例”表明我们将探讨如何在Apache ActiveMQ中使用Spring框架配置发布/订阅(Pub/Sub)模式。ActiveMQ是流行的开源消息代理,它实现了Java消息服务...

    Spring Boot ActiveMQ连接池配置过程解析

    要配置ActiveMQ连接池,我们需要做两项修改:配置文件和添加连接池依赖。 配置文件 在application.properties配置文件中,我们需要添加以下配置: * `spring.activemq.broker-url=tcp://localhost:61616`:指定...

    Spring和ActiveMQ的整合实例源码

    3. **ActiveMQ配置**:在Spring中配置ActiveMQ,我们需要在`applicationContext.xml`或对应的配置文件中添加ActiveMQ的连接工厂和目的地(Topic或Queue)。这通常包括URL、用户名、密码等信息,以连接到ActiveMQ...

    spring 与ACTIVEMQ整合

    2. **配置ActiveMQ服务器**:设置ActiveMQ服务器,可以是本地运行的实例,也可以是远程服务器。配置包括服务器地址、端口、用户名和密码等信息。 3. **创建ConnectionFactory**:在Spring配置文件中,定义一个`...

    Spring集成ActiveMQ配置.docx

    Spring 集成 ActiveMQ 配置 Spring 集成 ActiveMQ 配置是指将 Spring 框架与 ActiveMQ 消息队列集成,以实现基于 JMS(Java Message Service)的消息传递。ActiveMQ 是 Apache 软件基金会的一个开源的消息队列系统...

    spring_activeMQ

    Spring配置ActiveMQ** 在Spring应用中,我们首先需要配置ActiveMQ服务器连接。这通常通过`&lt;bean&gt;`标签定义一个`ConnectionFactory`来完成。例如: ```xml &lt;bean id="connectionFactory" class="org.apache....

    spring 整合activemq实现自定义动态消息队列

    百度spring整合activemq 发现几乎都只是在xml文件配置固定的消息队列而且太麻烦。并没有根据需求进行动态生成主题和队列。本文档参考了纯粹的activemq java代码和百度上的demo,很简洁的实现了动态消息队列的生成和...

    Spring与ActiveMQ整合完整案例

    首先,我们需要在Spring配置文件中声明JMS相关组件,包括ConnectionFactory、Destination(队列或主题)以及MessageListener容器。然后,通过注解或XML配置创建消息生产者和消费者。 4. **案例实践**:在...

Global site tag (gtag.js) - Google Analytics