码迷,mamicode.com
首页 > 编程语言 > 详细

metaq spring

时间:2014-10-20 21:26:37      阅读:300      评论:0      收藏:0      [点我收藏+]

标签:style   color   io   os   ar   使用   java   strong   sp   

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();
        }
    }

}

metaq spring

标签:style   color   io   os   ar   使用   java   strong   sp   

原文地址:http://blog.csdn.net/luyee2010/article/details/40313883

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!