1.1使用内嵌服务
(1)在pom.xml中引入activemq起步依赖
?
1
2
3
4
|
<dependency>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-starter-activemq</artifactid>
</dependency>
|
(2)创建消息生产者
?
1
2
3
4
5
6
7
8
9
10
11
12
13
|
/**
* 消息生产者
* @author administrator
**/
@restcontroller
public class queuecontroller {
@autowired
private jmsmessagingtemplate jmsmessagingtemplate;
@requestmapping ( "/send" )
public void send(string text){
jmsmessagingtemplate.convertandsend( "itcast" , text);
}
}
|
(3)创建消息消费者
?
1
2
3
4
5
6
7
|
@component
public class consumer {
@jmslistener (destination= "itcast" )
public void readmessage(string text){
system.out.println( "接收到消息:" +text);
}
}
|
测试:启动服务后,在浏览器执行http://localhost:8088/send.do?text=aaaaa即可看到控制台输出消息提示。spring boot内置了activemq的服务,所以我们不用单独启动也可以执行应用程序。
1.2使用外部服务
在src/main/resources下的application.properties增加配置, 指定activemq的地址spring.activemq.broker-url=tcp://192.168.25.135:61616
运行后,会在activemq中看到发送的queue
1.3.3发送map信息
(1)修改queuecontroller.java
?
1
2
3
4
5
6
7
|
@requestmapping ( "/sendmap" )
public void sendmap(){
map map= new hashmap<>();
map.put( "mobile" , "13900001111" );
map.put( "content" , "恭喜获得10元代金券" );
jmsmessagingtemplate.convertandsend( "itcast_map" ,map);
}
|
(2)修改consumer.java
?
1
2
3
4
|
@jmslistener (destination= "itcast_map" )
public void readmap(map map){
system.out.println(map);
}
|
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对快网idc的支持。如果你想了解更多相关内容请查看下面相关链接
原文链接:https://blog.csdn.net/qq_43193797/article/details/83585907
相关文章
猜你喜欢
- 64M VPS建站:怎样优化以提高网站加载速度? 2025-06-10
- 64M VPS建站:是否适合初学者操作和管理? 2025-06-10
- ASP.NET自助建站系统中的用户注册和登录功能定制方法 2025-06-10
- ASP.NET自助建站系统的域名绑定与解析教程 2025-06-10
- 个人服务器网站搭建:如何选择合适的服务器提供商? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-29 32
-
2025-06-04 52
-
使用VPS搭建小说网站:安装与配置WordPress的最佳实践
2025-05-27 32 -
2025-05-25 36
-
2025-05-25 60
热门评论