首页 > 代码库 > metaq spring
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(); } } }
metaq spring
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。