activemq安装与配置_spring +ActiveMQ 实战 topic selecter指定接收

76dce432e6be5b4acae384da2eedb8b2.png

一,下载并安装ActiveMQ

首先我们到apache官网上下载activeMQ(http://activemq.apache.org/download.html),进行解压后运行其bin目录下面的activemq.bat文件启动activeMQ。

二,新建一个maven 项目并导入相关jar包

三,在maven中引入:

 org.apache.activemq activemq-core 5.7.0org.apache.activemq activemq-pool 5.12.1

四,spring-active.xml配置

<?xml version="1.0" encoding="UTF-8"?>first-queue

五,springmvc.xml配置

<?xml version="1.0" encoding="UTF-8"?>

六, web.xml配置

七,消息发送接口代码

(1)消息发送接口

import javax.jms.Destination; public interface ProducerService {  void sendMessage(Destination destination, final String msg,final int i); }

(2)消息发送接口实现类

import com.demo.test1.activemq.service.ProducerService;import org.springframework.jms.core.JmsTemplate;import org.springframework.jms.core.MessageCreator;import org.springframework.stereotype.Service; import javax.annotation.Resource;import javax.jms.*; @Servicepublic class ProducerServiceImpl implements ProducerService {  @Resource(name="jmsTemplate") private JmsTemplate jmsTemplate;  @Override public void sendMessage(Destination destination, final String msg, final int i) { System.out.println(Thread.currentThread().getName()+" 向队列"+destination.toString()+"发送消息--------->"+msg);  jmsTemplate.send(destination, new MessageCreator() { public Message createMessage(Session session) throws JMSException { TextMessage textMessage = session.createTextMessage(msg); textMessage.setIntProperty("con
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值