zoukankan      html  css  js  c++  java
  • metaq spring

    spring metaq

    spring bean 配置

      <bean id="sessionFactory" class="com.taobao.metamorphosis.client.extension.spring.MetaqMessageSessionFactoryBean">
            <property name="zkConnect" value="192.168.137.2:2181"/>
            <property name="zkSessionTimeoutMs" value="30000"/>
            <property name="zkConnectionTimeoutMs" value="30000"/>
            <property name="zkSyncTimeMs" value="5000"/>
        </bean>
    
        <bean id="messageBodyConverter"  class="com.taobao.metamorphosis.client.extension.spring.JavaSerializationMessageBodyConverter"/>
    
         <bean id ="metaqTemplate" class="com.taobao.metamorphosis.client.extension.spring.MetaqTemplate">    
            <property name="messageSessionFactory" ref="sessionFactory"/>
            <property name="messageBodyConverter" ref="messageBodyConverter"/>
        </bean>

    使用

    import java.util.Date;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Qualifier;
    import org.springframework.stereotype.Service;
    
    import com.taobao.metamorphosis.client.extension.spring.MessageBuilder;
    import com.taobao.metamorphosis.client.extension.spring.MetaqTemplate;
    
    @Service("topicService")
    public class TopicService {
    
        @Autowired
        @Qualifier("metaqTemplate")
        private MetaqTemplate metaqTemplate;
    
        public MetaqTemplate getMetaqTemplate() {
            return metaqTemplate;
        }
    
        public void setMetaqTemplate(MetaqTemplate metaqTemplate) {
            this.metaqTemplate = metaqTemplate;
        }
    
        public void sendMsg(String topic, String msg) {
            try {
    
                metaqTemplate.send(MessageBuilder.withTopic(topic).withBody(new Date()));
    
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    
    }

    版权声明:本文博主原创文章,博客,未经同意不得转载。

  • 相关阅读:
    使Eclipse下支持编写HTML/JS/CSS/JSP页面的自动提示
    SpringMVC与Struts2的对比
    事务不提交,也有可能写redo和数据文件
    14.4.1 InnoDB Startup Configuration
    SLB 权重问题
    perl 访问网站一些useragent的设置
    14.3.5.3 How to Minimize and Handle Deadlocks 如何减少和处理死锁
    nginx 区分pc和mobile 到不同的404页面
    dokcer 运行和进入容器
    docker 私有仓库查询
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/4881326.html
Copyright © 2011-2022 走看看