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;
    }
}
相关推荐
sanggou5 分钟前
License 集成 Spring Gateway:解决 WebFlux 非阻塞与 Spring MVC Servlet 阻塞兼容问题
spring·gateway·mvc
敲键盘的肥嘟嘟左卫门32 分钟前
StringBuilder类的数据结构和扩容方式解读
java
索迪迈科技1 小时前
java后端工程师进修ing(研一版 || day40)
java·开发语言·学习·算法
十碗饭吃不饱1 小时前
net::ERR_EMPTY_RESPONSE
java·javascript·chrome·html5
白初&1 小时前
SpringBoot后端基础案例
java·spring boot·后端
哈基米喜欢哈哈哈1 小时前
ThreadLocal 内存泄露风险解析
java·jvm·面试
萌新小码农‍1 小时前
Java分页 Element—UI
java·开发语言·ui
鼠鼠我捏,要死了捏1 小时前
深入实践G1垃圾收集器调优:Java应用性能优化实战指南
java·g1·gc调优
书院门前细致的苹果2 小时前
ArrayList、LinkedList、Vector 的区别与底层实现
java
再睡亿分钟!2 小时前
Spring MVC 的常用注解
java·开发语言·spring boot·spring