java 编程技术异步通信_java异步消息通知机制(1)

本文介绍了在Java中使用ActiveMQ实现消息队列的异步通信,详细讲解了如何与SpringBoot整合,以及在支付业务模块中的具体应用,包括支付成功通知、订单状态更新和库存系统交互。同时强调了系统化学习和团队合作的重要性。
摘要由CSDN通过智能技术生成

注册服务

ln -s /opt/activemq/bin/activemq /etc/init.d/activemqchkconfig --add activemq

复制代码

启动服务

service activemq start

关闭服务

service activemq stop

通过 netstat 查看端口

activemq 两个重要的端口,一个是提供消息队列的默认端口:61616

另一个是控制台端口 8161

通过控制台测试

启动消费端

进入网页控制台

账号/密码默认: admin/admin

点击 Queues

观察客户端

在 Java 中使用消息队列

3.1 在 gmall-service-util 中导入依赖坐标

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-activemq</artifactId><exclusions><exclusion><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.apache.activemq</groupId><artifactId>activemq-pool</artifactId><version>5.15.2</version><exclusions><exclusion><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId></exclusion></exclusions></dependency>

复制代码

3.2 producer 端

public static void main(String[] args) {ConnectionFactory connect = new ActiveMQConnectionFactory("tcp://192.168.67.163:61616");try {Connection connection = connect.createConnection();connection.start();//第一个值表示是否使用事务,如果选择true,第二个值相当于选择0Session session = connection.createSession(true, Session.SESSION_TRANSACTED);Queue testqueue = session.createQueue("TEST1");MessageProducer producer = session.createProducer(testqueue);TextMessage textMessage=new Active
  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值