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;
    }
}
相关推荐
沉鱼.441 分钟前
枚举问题集
java·数据结构·算法
林夕sama4 分钟前
多线程基础(五)
java·开发语言·前端
Zzxy9 分钟前
HikariCP连接池
java·数据库
罗超驿13 分钟前
Java数据结构_栈_算法题
java·数据结构·
谁在黄金彼岸15 分钟前
Spring Boot + WebFlux 全面使用指南
spring boot
希望永不加班19 分钟前
SpringBoot 主启动类解释:@SpringBootApplication 到底做了什么
java·spring boot·后端·spring
智能工业品检测-奇妙智能28 分钟前
国产化系统的性价比对比
人工智能·spring boot·后端·openclaw·奇妙智能
蝎子莱莱爱打怪1 小时前
别再裸用 Claude Code 了!32 个亲测Skills + 8 个 MCP,开发效率直接拉满!
java·后端·claude
野犬寒鸦1 小时前
JVM垃圾回收机制面试常问问题及详解
java·服务器·开发语言·jvm·后端·算法·面试
_杨瀚博1 小时前
JAVA找出哪个类import了不存在的类
java·后端