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;
    }
}
相关推荐
恋爱绝缘体120 小时前
2020重学C++重构你的C++知识体系
java·开发语言·c++·算法·junit
xiaolyuh12321 小时前
Spring 框架 核心架构设计 深度详解
spring·设计模式·spring 设计模式
wszy180921 小时前
新文章标签:让用户一眼发现最新内容
java·python·harmonyos
wszy180921 小时前
顶部标题栏的设计与实现:让用户知道自己在哪
java·python·react native·harmonyos
期待のcode1 天前
前后端分离项目 Springboot+vue 在云服务器上的部署
服务器·vue.js·spring boot
程序员小假1 天前
我们来说一下无锁队列 Disruptor 的原理
java·后端
资生算法程序员_畅想家_剑魔1 天前
Kotlin常见技术分享-02-相对于Java 的核心优势-协程
java·开发语言·kotlin
ProgramHan1 天前
Spring Boot 3.2 新特性:虚拟线程的落地实践
java·jvm·spring boot
nbsaas-boot1 天前
Go vs Java 的三阶段切换路线图
java·开发语言·golang
毕设源码-钟学长1 天前
【开题答辩全过程】以 基于Java的慕课点评网站为例,包含答辩的问题和答案
java·开发语言