# demo-rocketmq **Repository Path**: lzh2019/demo-rocketmq ## Basic Information - **Project Name**: demo-rocketmq - **Description**: SpringBoot整合RocketMq测试项目 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-08-02 - **Last Updated**: 2021-08-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 工程简介 SpringBoot整合RocketMq测试项目 ``` Producer端-消息发送方式 RocketMQTemplate.syncSend -发送同步消息 :这种可靠性同步地发送方式使用的比较广泛, 比如:重要的消息通知,短信通知 RocketMQTemplate.asyncSend 发送异步消息: 异步消息通常用在对响应时间敏感的业务场景, 即发送端不能容忍长时间地等待Broker的响应 RocketMQTemplate.sendOneWay单向发送消息: 这种方式主要用在不特别关心发送结果的场景, 例如日志发送。 ``` --- ``` Consumer端-消息接收方式 RocketMQListener接口 可以接收: 1. 广播消息 @RocketMQMessageListener注解,必须配置项入下group,topic ,MessageModel.BROADCASTING 2. 顺序消费 @RocketMQMessageListener注解,必须配置项入下group,topic ,ConsumeMode.ORDERLY 3. 普通消费 @RocketMQMessageListener注解,必须配置项入下group,topic RocketMQReplyListener接口 可以接收: 1. 自动答复消息 使用@RocketMQMessageListener注解,必须配置项入下group,topic,selectorExpression 2. RPC消息 使用@RocketMQMessageListener注解,必须配置项入下group,topic,selectorExpression ``` --- ``` 发送java对象 GET http://localhost:2808/messageSend/sendObject?id=1&name=xiaoming&action=go2&ags=3 发送Message对象封装过的java对象 GET http://localhost:2808/messageSend/sendMessage?id=2&name=xiaoming&action=des&ags=3 发送 集合(List>) GET http://localhost:2808/messageSend/sendCollection?id=2&name=xiaoming&action=des&ags=3 发送同步消息 GET http://localhost:2808/messageSend/syncSend?id=2&name=xiaoming&action=des&ags=3 发送异步消息 GET http://localhost:2808/messageSend/asyncSend?id=2&name=xiaoming&action=des&ags=3 单向发送消息 GET http://localhost:2808/messageSend/oneWaySend?id=2&name=xiaoming&action=des&ags=3 发送事务消息 GET http://localhost:2808/messageSend/transactionMessage?id=2&name=xiaoming&action=des&arg=1 GET http://localhost:2808/messageSend/transactionMessage?id=2&name=xiaoming&action=des&arg=2 GET http://localhost:2808/messageSend/transactionMessage?id=2&name=xiaoming&action=des&arg=3 ``` # 延伸阅读 ``` 消息有序-指的是可以按照消息的发送顺序来消费(FIFO)。 RocketMQ可以严格的保证消息有序,可以分为分区有序或者全局有序。 顺序消费的原理解析, 在默认的情况下消息发送会采取Round Robin轮询方式把消息发送到不同的queue(分区队列); 而消费消息的时候从多个queue上拉取消息,这种情况发送和消费是不能保证顺序。 但是如果控制发送的顺序消息只依次发送到同一个queue中, 消费的时候只从这个queue上依次拉取,则就保证了顺序。 当发送和消费参与的queue只有一个,则是全局有序; 如果多个queue参与,则为分区有序,即相对每个queue,消息都是有序的 ``` 官方案例 https://github.com/apache/rocketmq/blob/master/docs/cn/RocketMQ_Example.md