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;
    }
}
相关推荐
菜菜小狗的学习笔记1 分钟前
八股(二)Java集合
java·开发语言
星乐a2 分钟前
String 不可变性与常量池深度解析
java·开发语言
captain3762 分钟前
ACM模式下Java输入输出函数为什么会超时?及解决方法
java·开发语言
神の愛4 分钟前
mybatis什么时候不走 缓存??
spring·缓存·mybatis
程序员老邢8 分钟前
【产品底稿 04】商助慧 V1.1 里程碑:爬虫入库 + MySQL + Milvus 全链路打通
java·爬虫·mysql·ai·springboot·milvus
2601_9507039410 分钟前
Java安全编程与静态分析实战
java
好家伙VCC11 分钟前
**发散创新:基于Python与OpenCV的视频流帧级分析实战**在当前人工智能与计算机视觉飞速发展的背景下
java·人工智能·python·计算机视觉
SimonKing12 分钟前
大V说’AI替代不了你’,但现实是——用AI的人正在替代你
java·后端·程序员
tryxr22 分钟前
SpringMVC 中的常用注解和用法
spring·mvc·springmvc
一叶龙洲27 分钟前
Java中使用模板引擎(FreeMarker / Velocity) + Word XML导出复杂Word
xml·java·word