ActiveMQ5 jdk1.8版 下载,安装与配置

一  ActiveMQ 下载 安装

ActiveMQ 官网icon-default.png?t=N7T8https://activemq.apache.org/     

       目前打开官网有两个版本选择:ActiveMQ "Classic"  和  ActiveMQ Artemis ,Classic是一直存在的,Artemis是新的高性能,由于是jdk1.8的项目,所以选用之前的Classic,最新的版本使用jdk11+,由于我当前环境是使用jdk8,因此找支持jdk1.8 例如 ActiveMQ  5.16.7,

点这里直接下载linux版(202311 支持jdk1.8最新的安全版5.16.7):https://archive.apache.org/dist/activemq/5.16.7/apache-activemq-5.16.7-bin.tar.gz

      

 ActiveMQ 下载

wget https://archive.apache.org/dist/activemq/5.16.7/apache-activemq-5.16.7-bin.tar.gz


ActiveMQ 安装

tar -xvzf apache-activemq-5.16.7-bin.tar.gz

 把下载的ActiveMQ 压缩包解压就算是安装完成。

二 ActiveMQ 配置

1 配置web页面管理界面

 打开配置文件路径:apache-activemq-5.16.7/conf/jetty.xml

说明:一般只需改端口,上面是8611,所以这里web管理地址是:http://xx.xx.xx.xx:8611/


  配置web管理账号密码 

打开配置文件路径:/apache-activemq-5.16.7/conf/jetty-realm.properties

admin: pass, admin
user: pass, user

说明:第1列是用户名,第二列是密码,第三列是角色(一般不用改)

2  配置java客户端 生产与消费者密码


  打开配置文件 /apache-activemq-5.16.7/conf/activemq.xml


  在位置在broker标签内增加:


 <!-- add plugins -->
    <plugins>
      <simpleAuthenticationPlugin>
        <users>
          <authenticationUser username="${activemq.username}" password="${activemq.password}" groups="users,admins"/>
        </users>
      </simpleAuthenticationPlugin>
    </plugins>

  配置文件 -> \conf\credentials.properties(设置用户名密码)


activemq.username=admin
activemq.password=xxxxxx

 


ActiveMQ 启动停止管理

方式一:命令行操作

 启动运行

bin/activemq start

  停止运行

bin/activemq stop

方式二:配置服务

  配置成服务并设置开机启动,防止服务器重启忘记启动。 

ln -snf /usr/local/apache-activemq-5.16.7/bin/activemq /etc/init.d/activemq

chkconfig --add activemq

chkconfig activemq on

 常用的服务指令:

service activemq start

service activemq stop

service activemq status

service activemq restart

四 安装验证

 1 web端管理界面验证

    web端管理界面,默认端口使是8161

   2 检查服务使用端口 

     检查消费者与生产者默认使用的端口61616,如下:

netstat -an|grep 61616

 端口连接正常。 

 五 在Java应用使用ActiveMQ

  1 引用ActiveMQ

   pom配置文件

      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-activemq</artifactId>
        <version>2.1.5.RELEASE</version>
      </dependency>

 2 spring框架的ActiveMQ配置 

  spring框架配置文件的ActiveMQ配置 如下:

spring:
  activemq:
    broker-url: tcp://xx.xx.xx.xx:61616
    user: admin
    password: xxxxxx
    in-memory: true
    pool:
      enabled: false

3 在JAVA代码例用ActiveMQ: 

  生产端发送队列信息java代码:

import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Service;

import javax.jms.Destination;

/**
 * @author hua
 */
@Service
public class MsgSendServiceImpl {

    @Autowired
    private JmsMessagingTemplate jmsTemplate;
    /**
     * 发送消息 采用指定队列类型
     *
     * @param queueName 队列名称
     * @param message   队列消息
     */
    public void sendMessageByQueue(String queueName, final String message) {

        Destination destination = new ActiveMQQueue(queueName);
        jmsTemplate.convertAndSend(destination, message);
    }
}

   客户端接收消息队列代码如下:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Service;

/**
 * @author hua
 */
@Service
public class MsgReceiveServiceImpl {


    // 使用JmsListener配置消费者监听的队列,其中text是接收到的消息 根据配置文件只能接收一种类型
   @JmsListener(destination = "top_name")
    public void receiveQueue(String text) {
          System.out.println("收到信息:"+text);
         

    }
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qyhua

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值