SpringBoot整合ActiveMQ

ActiveMQ简单使用

JMS

ActiveMQ

下载安装

复制代码
https://activemq.apache.org/components/classic/download/

解压缩文件。进入win64目录,双击运行activemq.bat文件,运行服务

将下面的网址输入到浏览器,用户名和密码都是admin

SpringBoot整合ActiveMQ

  • 导入坐标
java 复制代码
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-activemq</artifactId>
        </dependency>
  • 添加配置
java 复制代码
server:
  port: 8080


spring:
  activemq:
    broker-url: tcp://localhost:61616

  jms:
    template:
      default-destination: itheima
  • 实现业务类
java 复制代码
package com.ustc.service.activemq;

import com.ustc.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Service;

@Service
public class MessageServiceActivemqImpl implements MessageService {
    @Autowired
    private JmsMessagingTemplate messagingTemplate;

    @Override
    public void sendMessage(String id) {
        System.out.println("待发送短信的订单已经纳入处理对队列id" + id);
        messagingTemplate.convertAndSend(id);
    }

    @Override
    public String doMessge() {
        String id = messagingTemplate.receiveAndConvert(String.class);
        System.out.println("已经完成短信发送服务:id" + id);
        return id;
    }
}
相关推荐
皮皮林5512 小时前
Java性能调优黑科技!1行代码实现毫秒级耗时追踪,效率飙升300%!
java
冰_河2 小时前
QPS从300到3100:我靠一行代码让接口性能暴涨10倍,系统性能原地起飞!!
java·后端·性能优化
桦说编程5 小时前
从 ForkJoinPool 的 Compensate 看并发框架的线程补偿思想
java·后端·源码阅读
躺平大鹅7 小时前
Java面向对象入门(类与对象,新手秒懂)
java
初次攀爬者8 小时前
RocketMQ在Spring Boot上的基础使用
java·spring boot·rocketmq
花花无缺8 小时前
搞懂@Autowired 与@Resuorce
java·spring boot·后端
Derek_Smart9 小时前
从一次 OOM 事故说起:打造生产级的 JVM 健康检查组件
java·jvm·spring boot
NE_STOP10 小时前
MyBatis-mybatis入门与增删改查
java
孟陬13 小时前
国外技术周刊 #1:Paul Graham 重新分享最受欢迎的文章《创作者的品味》、本周被划线最多 YouTube《如何在 19 分钟内学会 AI》、为何我不
java·前端·后端