`

ActiveMQ spring 配置

 
阅读更多
<bean id="memcachedClient" class="net.spy.memcached.spring.MemcachedClientFactoryBean" >    
<property name="servers" value="memcache.mtc.sohu.com:33001"/>  
<property name="transcoder">    
<bean class="net.spy.memcached.transcoders.SerializingTranscoder">        
<property name="compressionThreshold" value="1024"/>      
</bean>   
</property>  
<property name="opTimeout" value="3000"/>    
<property name="timeoutExceptionThreshold" value="1998"/>   
<property name="hashAlg" value="KETAMA_HASH"/>    
<property name="locatorType" value="CONSISTENT"/>     
<property name="failureMode" value="Redistribute"/>    
<property name="useNagleAlgorithm" value="false"/>  
    </bean>
    <!-- static service util -->
    <bean id="memcache" class="com.sohu.t.api.memcache.MemcacheUtil" factory-method="getInstance" />
    <!-- jms change password 相关 -->
    <!-- 配置JMS连接工厂 -->
    <bean id="connectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
         <property name="brokerURL" value="tcp://ip:port"/>
         <property name="userName" value="rcver"/>
         <property name="password" value="r%@#$cv_09ers"/>
         <property name="clientID" value="1073-PASSPORT.PASSWORD.TOPI"/>
    </bean>
    <!-- 配置JMS模版 -->
    <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
         <property name="connectionFactory" ref="connectionFactory"/>
         <property name="defaultDestination" ref="destination"></property>
    </bean>
    <bean id="topicListener"
class="org.springframework.jms.listener.adapter.MessageListenerAdapter">
<constructor-arg ref="topicMessageReceiver" />
<property name="defaultListenerMethod" value="receive" />
</bean>
    <!-- 发送消息的目的地(一个队列) -->
    <bean id="destination" class="org.apache.activemq.command.ActiveMQTopic">
         <!-- 设置消息队列的名字 -->
<!--         <constructor-arg index="0" value="PASSPORT.PASSWORD.TOPIC"/> -->
<!--         <property name="physicalName" value="PASSPORT.PASSWORD.TOPIC?consumer.retroactive=true&amp;consumer.prefetchSize=10"></property> -->
          <property name="physicalName" value="PASSPORT.PASSWORD.TOPIC"></property>
    </bean>
    <bean id="listenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">   
        <property name="connectionFactory" ref="connectionFactory" />   
        <property name="pubSubDomain" value="true"/>   
        <property name="destination" ref="destination" />   
        <property name="clientId" value="1073-PASSPORT.PASSWORD.TOPI"/> 
        <property name="messageListener" ref="topicListener" />
        <property name="sessionAcknowledgeModeName" value="AUTO_ACKNOWLEDGE"/>
        <property name="subscriptionDurable" value="true"/> 
        <property name="durableSubscriptionName" value="PASSPORT.PASSWORD.TOPIC" /> 
   </bean>
   <bean id="topicMessageReceiver" class="com.sohu.t.api.activemq.MessageReceiver">
   <constructor-arg ref="userSecurityTaskExecutor" />
   </bean>



import javax.jms.Destination;
import javax.jms.TextMessage;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jms.core.JmsTemplate;

import com.sohu.t.api.push.mq.ActivityTaskExecutor;
import com.sohu.t.api.push.mq.MsgTaskExecutor;
import com.sohu.t.api.push.mq.UserSecurityTaskExecutor;
import com.sohu.t.api.push.queue.KestrelQueueFactory;
import net.rubyeye.xmemcached.MemcachedClient;
import com.sohu.t.api.push.util.Constants;


public class Server extends Thread {

private MsgTaskExecutor msgExecutor;
private ActivityTaskExecutor activityExecutor;
private UserSecurityTaskExecutor userSecurityTaskExecutor;

JmsTemplate template;
Destination destination;

private MemcachedClient memcachedClient = KestrelQueueFactory.getInstance();
private static final ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"applicationContext.xml"});
public Server(){
msgExecutor = (MsgTaskExecutor)context.getBean("msgTaskExecutor");
activityExecutor = (ActivityTaskExecutor)context.getBean("activityTaskExecutor");
userSecurityTaskExecutor = (UserSecurityTaskExecutor)context.getBean("userSecurityTaskExecutor");

//用户passport密码修改业务
template = (JmsTemplate) context.getBean("jmsTemplate");
        destination = (Destination) context.getBean("destination");
}
@Override
    public void run() {
while(true){
try{
// String jsonStr = memcachedClient.get(Constants.QUEUE_NAME);
// if(jsonStr!=null){
// msgExecutor.excuteMsgExecutor(jsonStr);
// }
//
TextMessage changPasswordTM = (TextMessage) template.receive(destination);
                if (null != changPasswordTM) {
                String changPasswordMsg = changPasswordTM.getText();
                System.out.println("收到消息内容为: " + changPasswordMsg);
                userSecurityTaskExecutor.excuteMsgExecutor(changPasswordMsg);
                 }
// if(jsonStr==null){
// Thread.sleep(1000);
// }
}catch(Exception e){
e.printStackTrace();
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
continue;
}
continue;
}
}
    }
public static void main(String args[]){
Server thread = new Server();
thread.start();
}
}
分享到:
评论

相关推荐

    activeMQ_spring简单案例(含XML配置)

    接下来,我们看看如何在Spring中配置ActiveMQ。Spring框架提供了一套完整的JMS支持,包括连接工厂、目的地(队列或主题)以及消息监听器的声明式配置。在XML配置文件中,我们可以定义如下的元素: ```xml ...

    activemq spring 客户端配置

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

    spring配置activemq详解

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

    ActiveMQ+spring配置方案详解

    当我们需要在Spring应用中集成ActiveMQ时,就需要进行相应的配置。本文将深入讲解ActiveMQ与Spring的整合配置方案。 首先,我们需要在项目中引入ActiveMQ的相关依赖。这通常通过在`pom.xml`文件中添加Maven依赖来...

    ActiveMQ路由配置方式

    ActiveMQ路由配置方式 ActiveMQ路由配置是Apache ActiveMQ项目中的一种重要配置方式,它依赖另一个Apache项目Camel。ActiveMQ集成了Camel,启动时同时会启动Camel。通过Camel Web Console可以进行Routing配置。 ...

    Spring集成ActiveMQ配置

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

    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+spring

    3. **配置Spring**:在Spring的配置文件(如applicationContext.xml)中,我们需要配置JMS相关的bean,包括ConnectionFactory(连接工厂)、Destination(目的地,如Queue或Topic)、MessageListenerContainer(监听...

    spring activeMQ-demo 配置

    **二、Spring配置** 1. **JMS配置**: 在Spring的配置文件(如applicationContext.xml)中,添加对JMS的支持,包括定义ConnectionFactory、Destination(Topic或Queue)和MessageListenerContainer。 ```xml ...

    activeMq整合spring所需jar包

    3. 在Spring配置文件中声明JMS模板(JMSTemplate)和消息监听容器(MessageListenerContainer)。 4. 创建消息生产者,通过JMS模板发送消息。 5. 创建消息消费者,实现MessageListener接口,或者使用消息监听容器...

    activemq5.5.1 Spring模板

    3. 创建JmsTemplate:在Spring配置文件中,定义一个`JmsTemplate`bean,设置连接工厂和其他相关属性。连接工厂通常是通过`ActiveMQConnectionFactory`创建的。 4. 发送与接收消息:使用`JmsTemplate`的`...

    activeMQ_spring_Demo.zip_DEMO_activemq_activemq spring_rowbv3

    《ActiveMQ与Spring整合实战教程》 在Java企业级应用中,消息中间件扮演着至关重要的角色,它能够实现应用间的解耦,提高系统的可扩展性和可靠性。ActiveMQ作为Apache基金会的一个开源项目,是Java消息服务(JMS)...

    ActiveMQ与Spring整合示例Demo

    - `src/main/java/com/example/config/MessagingConfig.java`:Spring配置类,包含连接工厂、消息模板和监听容器的配置。 - `src/main/java/com/example/service/MessageService.java`:业务逻辑类,负责发送消息。 ...

    activeMQ+spring整合

    综上所述,"activeMQ+spring整合"是一个实用的示例,它演示了如何在Spring环境中配置和使用ActiveMQ,以实现消息的可靠传输。通过下载并研究`activemqDOME`这个压缩包中的代码,你可以更深入地理解这个整合过程,...

    activemq与spring整合源代码

    3. Spring配置:在Spring的配置文件中,定义JMS相关的bean,包括ConnectionFactory、Destination(队列或主题)、MessageListenerContainer等。这里可以使用`&lt;bean&gt;`标签和`&lt;jee:jndi-lookup&gt;`标签来引用ActiveMQ的...

    Spring和ActiveMQ整合的完整实例

    2. **配置Spring**:在Spring的配置文件中,定义JmsTemplate,指定ActiveMQ的ConnectionFactory,这通常是通过JNDI查找完成的。同时,可以配置MessageListenerContainer,它将负责监听消息并调用我们定义的消息监听...

    ActiveMQ与spring整合封装

    首先,ActiveMQ与Spring的整合主要基于Spring的JMS(Java Message Service)支持。Spring通过`ConnectionFactory`和`Destination`接口来抽象JMS提供者的具体实现,使得我们能够轻松地更换消息中间件,而无需修改大量...

Global site tag (gtag.js) - Google Analytics