简约 时尚 高端 网站建设/长安网站优化公司

简约 时尚 高端 网站建设,长安网站优化公司,楚雄网站建设rewlkj,jsp商务网站建设1. 安装 ActiveMQ 1.1 下载 ActiveMQ 访问 ActiveMQ 官方下载页面,根据你的操作系统选择合适的版本进行下载。这里以 Linux 系统,Java环境1.8版本为例,下载 apache-activemq-5.16.7-bin.tar.gz。 1.2 解压文件 将下载的压缩包解压到指定目…

1. 安装 ActiveMQ

1.1 下载 ActiveMQ

访问 ActiveMQ 官方下载页面,根据你的操作系统选择合适的版本进行下载。这里以 Linux 系统,Java环境1.8版本为例,下载 apache-activemq-5.16.7-bin.tar.gz

1.2 解压文件

将下载的压缩包解压到指定目录,例如 /opt

tar -zxvf apache-activemq-5.16.7-bin.tar.gz -C /opt
1.3 启动 ActiveMQ

进入解压后的目录,启动 ActiveMQ:

cd /opt/apache-activemq-5.16.7
./bin/activemq start
1.4 验证 ActiveMQ 是否启动成功

打开浏览器,访问 http://localhost:8161,使用默认用户名 admin 和密码 admin 登录 ActiveMQ 的管理控制台。如果能成功登录,说明 ActiveMQ 已经启动成功。
在这里插入图片描述

1.4 进入ActiveMQ 管理员控制台

ActiveMQ 启动成功后,单击 Manage ActiveMQ broker 超链接进入管理员控制台。
在这里插入图片描述

2. 创建 Spring Boot 项目并整合 JMS - ActiveMQ

2.1 添加依赖

pom.xml 中添加 Spring Boot 集成 ActiveMQ 的依赖:

<dependencies><!-- Spring Boot Web --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- Spring Boot JMS --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-activemq</artifactId></dependency>
</dependencies>
2.2 配置 ActiveMQ

application.properties 中配置 ActiveMQ 的连接信息:

server.port=8080
# ActiveMQ 服务器地址,默认端口 61616
spring.activemq.broker-url=tcp://localhost:61616
# 配置信任所有的包,这个配置是为了支持发送对象消息
spring.activemq.packages.trust-all=true
# ActiveMQ 用户名
spring.activemq.user=admin
# ActiveMQ 密码
spring.activemq.password=admin
2.3 创建消息生产者

创建一个消息生产者类,用于发送消息到 ActiveMQ 的队列:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;import javax.jms.Queue;@Service
public class JmsProducer {@Autowiredprivate JmsTemplate jmsTemplate;@Autowiredprivate Queue queue;public void sendMessage(String message) {jmsTemplate.convertAndSend(queue, message);System.out.println("Sent message: " + message);}
}
2.4 创建消息消费者

创建一个消息消费者类,用于接收 ActiveMQ 队列中的消息:

import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;@Component
public class JmsConsumer {@JmsListener(destination = "test-queue")public void receiveMessage(String message) {System.out.println("Received message: " + message);}
}
2.5 配置 Queue Bean

在 ActiveMqConfig.java 中定义 队列:

import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;import javax.jms.Queue;@Configuration
public class ActiveMqConfig {@Beanpublic Queue queue() {return new ActiveMQQueue("test-queue");}
}
2.6 创建 API 测试发送消息
import com.weigang.producer.JmsProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;@RestController
@RequestMapping("/message")
public class MessageController {@Autowiredprivate JmsProducer producer;@GetMapping("/send")public String sendMessage(@RequestParam String msg) {producer.sendMessage(msg);return "Message sent: " + msg;}
}

然后访问:http://localhost:8080/message/send?msg=HelloActiveMQ

控制台应输出:

Sent message: HelloActiveMQ
Received message: HelloActiveMQ

3. 使用 ActiveMQ Web 界面查看消息

访问 http://localhost:8161/admin/queues.jsp,可以看到 test-queue 队列以及发送的消息。
在这里插入图片描述

4. 发送对象消息

在 JmsProducer 发送 对象:

import com.weigang.model.CustomMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;import javax.jms.Queue;@Service
public class JmsProducer {@Autowiredprivate JmsTemplate jmsTemplate;// 仍然使用 test-queue@Autowiredprivate Queue queue;public void sendMessage(CustomMessage customMessage) {jmsTemplate.convertAndSend(queue, customMessage);System.out.println("Sent message----> id:" + customMessage.getId() + ",content:" + customMessage.getContent());}
}

创建消息对象:

import java.io.Serializable;public class CustomMessage implements Serializable {private static final long serialVersionUID = 1L; // 推荐添加,避免序列化问题private String content;private int id;// 必须有默认构造方法(JMS 反序列化需要)public CustomMessage() {}// 构造方法public CustomMessage(String content, int id) {this.content = content;this.id = id;}public String getContent() {return content;}public void setContent(String content) {this.content = content;}public int getId() {return id;}public void setId(int id) {this.id = id;}@Overridepublic String toString() {return "CustomMessage{" +"content='" + content + '\'' +", id=" + id +'}';}}

消费者处理对象消息:

import com.weigang.model.CustomMessage;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;@Component
public class JmsConsumer {@JmsListener(destination = "test-queue")public void receiveMessage(String message) {System.out.println("Received message: " + message);}@JmsListener(destination = "test-queue")public void receiveMessage(CustomMessage message) {System.out.println("Received object message: " + message.toString());}
}

通过 API 发送对象:

import com.weigang.model.CustomMessage;
import com.weigang.producer.JmsProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;@RestController
@RequestMapping("/message")
public class MessageController {@Autowiredprivate JmsProducer producer;@GetMapping("/send")public String sendMessage(@RequestParam String msg) {producer.sendMessage(msg);return "Message sent: " + msg;}@GetMapping("/sendObj")public String sendMessage(@RequestParam Integer id,@RequestParam String content) {CustomMessage customMessage = new CustomMessage(content, id);producer.sendMessage(customMessage);return "Message sent: " + customMessage;}
}

然后访问:http://localhost:8080/message/sendObj?id=1&content=HelloActiveMQ

控制台应输出:

Sent message----> id:1,content:HelloActiveMQ
Received object message: CustomMessage{content='HelloActiveMQ', id=1}

注意事项

  • 确保 ActiveMQ 服务器正常运行,并且 application.properties 中的连接信息正确。
  • 如果需要使用主题(Topic)进行消息传递,可以在配置中设置 spring.jms.pub-sub-domain=true,并相应地修改消息生产者和消费者的代码。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/72561.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

《几何原本》命题I.13

《几何原本》命题I.13 两条直线相交&#xff0c;邻角是两个直角或者相加等于 18 0 ∘ 180^{\circ} 180∘。 若两角相等&#xff0c;则根据定义&#xff0c;两角为直角。 两角若不相等&#xff0c;如图&#xff0c;则 ( ∠ 1 ∠ 2 ) ∠ 3 ∠ 1 ( ∠ 2 ∠ 3 ) 9 0 ∘ …

优先级队列:通过堆的形式实现

描述: 大顶堆: 小顶堆: 索引位置查找: 代码实现: package com.zy.queue_code.deque;/*** @Author: zy* @Date: 2025-03-05-15:51* @Description:*/ public interface Priority

《OpenCV》—— dlib库

文章目录 dlib库是什么&#xff1f;OpenCV库与dlib库对比dlib库安装dlib——人脸应用实例——人脸检测dlib——人脸应用实例——人脸关键点定位dlib——人脸应用实例——人脸轮廓绘制 dlib库是什么&#xff1f; OpenCV库与dlib库对比 dlib库安装 dlib——人脸应用实例——人脸检…

蓝桥与力扣刷题(蓝桥 旋转)

题目&#xff1a;图片旋转是对图片最简单的处理方式之一&#xff0c;在本题中&#xff0c;你需要对图片顺时针旋转 90 度。 我们用一个 nm的二维数组来表示一个图片&#xff0c;例如下面给出一个 34 的 图片的例子&#xff1a; 1 3 5 7 9 8 7 6 3 5 9 7 这个图片顺时针旋转…

MiniMind用极低的成本训练属于自己的大模型

本篇文章主要讲解&#xff0c;如何通过极低的成本训练自己的大模型的方法和教程&#xff0c;通过MiniMind快速实现普通家用电脑的模型训练。 日期&#xff1a;2025年3月5日 作者&#xff1a;任聪聪 一、MiniMind 介绍 基本信息 在2小时&#xff0c;训练出属于自己的28M大模型。…

区块链中的数字签名:安全性与可信度的核心

数字签名是区块链技术的信任基石&#xff0c;它像区块链世界的身份证和防伪标签&#xff0c;确保每一笔交易的真实性、完整性和不可抵赖性。本文会用通俗的语言&#xff0c;带你彻底搞懂区块链中的数字签名&#xff01; 文章目录 1. 数字签名是什么&#xff1f;从现实世界到区块…

【文生图】windows 部署stable-diffusion-webui

windows 部署stable-diffusion-webui AUTOMATIC1111 stable-diffusion-webui Detailed feature showcase with images: 带图片的详细功能展示: Original txt2img and img2img modes 原始的 txt2img 和 img2img 模式 One click install and run script (but you still must i…

hive之lag函数

从博客上发现两个面试题&#xff0c;其中有个用到了lag函数。整理学习 LAG 函数是 Hive 中常用的窗口函数&#xff0c;用于访问同一分区内 前一行&#xff08;或前 N 行&#xff09;的数据。它在分析时间序列数据、计算相邻记录差异等场景中非常有用。 一、语法 LAG(column,…

【软考-架构】1.3、磁盘-输入输出技术-总线

GitHub地址&#xff1a;https://github.com/tyronczt/system_architect ✨资料&文章更新✨ 文章目录 存储系统&#x1f4af;考试真题输入输出技术&#x1f4af;考试真题第一题第二题 存储系统 寻道时间是指磁头移动到磁道所需的时间&#xff1b; 等待时间为等待读写的扇区…

盛铂科技PDROUxxxx系列锁相介质振荡器(点频源):高精度信号源

——超低相位噪声、宽频覆盖、灵活集成&#xff0c;赋能下一代射频系统 核心价值&#xff1a;以突破性技术解决行业痛点 在雷达、卫星通信、高速数据采集等高端射频系统中&#xff0c;信号源的相位噪声、频率稳定度及集成灵活性直接决定系统性能上限。盛铂科技PDROUxxxx系列锁…

【文献阅读】The Efficiency Spectrum of Large Language Models: An Algorithmic Survey

这篇文章发表于2024年4月 摘要 大语言模型&#xff08;LLMs&#xff09;的快速发展推动了多个领域的变革&#xff0c;重塑了通用人工智能的格局。然而&#xff0c;这些模型不断增长的计算和内存需求带来了巨大挑战&#xff0c;阻碍了学术研究和实际应用。为解决这些问题&…

如何在Github上面上传本地文件夹

前言 直接在GitHub网址上面上传文件夹是不行的&#xff0c;需要一层一层创建然后上传&#xff0c;而且文件的大小也有限制&#xff0c;使用Git进行上传更加方便和实用 1.下载和安装Git Git - Downloads 傻瓜式安装即可 2.获取密钥对 打开自己的Github&#xff0c;创建SSH密钥&…

kafka-web管理工具cmak

一. 背景&#xff1a; 日常运维工作中&#xff0c;采用cli的方式进行kafka集群的管理&#xff0c;还是比较繁琐的(指令复杂&#xff1f;)。为方便管理&#xff0c;可以选择一些开源的webui工具。 推荐使用cmak。 二. 关于cmak&#xff1a; cmak是 Yahoo 贡献的一款强大的 Apac…

数据结构:八大排序(冒泡,堆,插入,选择,希尔,快排,归并,计数)详解

目录 一.冒泡排序 二.堆排序 三.插入排序 四.选择排序 五.希尔排序 六.快速排序 1.Lomuto版本&#xff08;前后指针法&#xff09; 2.Lomuto版本的非递归算法 3.hoare版本&#xff08;左右指针法&#xff09; 4.挖坑法找分界值&#xff1a; 七.归并排序 八.计数排序…

【商城实战(2)】商城架构设计:从底层逻辑到技术实现

【商城实战】专栏重磅来袭&#xff01;这是一份专为开发者与电商从业者打造的超详细指南。从项目基础搭建&#xff0c;运用 uniapp、Element Plus、SpringBoot 搭建商城框架&#xff0c;到用户、商品、订单等核心模块开发&#xff0c;再到性能优化、安全加固、多端适配&#xf…

Mac mini M4安装nvm 和node

先要安装Homebrew&#xff08;如果尚未安装&#xff09;。在终端中输入以下命令&#xff1a; /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)" 根据提示操作完成Homebrew的安装。 安装nvm。在终端中输入以下命令&#xf…

FOC无感开环启动算法

FOC无感开环启动排除掉高频注入这种直接识别当前转子dq轴的位置直接闭环启动&#xff0c;大部分的常规启动方式就是三段式启动&#xff0c;对齐-强拖-观测器介入-观测器误差稳定后平滑过渡-闭环。 这里就只写出I/F&#xff08;V/F&#xff09;启动的角度输出的代码&#xff0c…

Android 自定义View 加 lifecycle 简单使用

前言 本文是自定义view中最简单的使用方法&#xff0c;分别进行 ‘onMeasure’、‘onDraw’、‘自定义样式’、‘lifecycle’的简单使用&#xff0c;了解自定义view的使用。 通过lifecycle来控制 动画的状态 一、onMeasure做了什么&#xff1f; 在onMeasure中获取view 的宽和…

《挑战你的控制力!开源小游戏“保持平衡”开发解析:用HTML+JS+CSS实现物理平衡挑战》​

&#x1f4cc; 大家好&#xff0c;我是智界工具库&#xff0c;致力于分享好用实用且智能的软件以及在JAVA语言开发中遇到的问题&#xff0c;如果本篇文章对你有所帮助请帮我点个小赞小收藏吧&#xff0c;谢谢喲&#xff01;&#x1f618;&#x1f618;&#x1f618; 博主声…

【无标题】FrmImport

文章目录 前言一、问题描述二、解决方案三、软件开发&#xff08;源码&#xff09;四、项目展示五、资源链接 前言 我能抽象出整个世界&#xff0c;但是我不能抽象你。 想让你成为私有常量&#xff0c;这样外部函数就无法访问你。 又想让你成为全局常量&#xff0c;这样在我的…