| | |
| | | |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.utils.redis.QueueUtils; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.ApiParam; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | |
| | | * @version 3.6.0 |
| | | */ |
| | | @Slf4j |
| | | @Api(value = "延迟队列 演示案例", tags = {"延迟队列"}) |
| | | @Tag(name ="延迟队列 演示案例", description = "延迟队列") |
| | | @RequiredArgsConstructor |
| | | @RestController |
| | | @RequestMapping("/demo/queue/delayed") |
| | | public class DelayedQueueController { |
| | | |
| | | @ApiOperation("订阅队列") |
| | | @Operation(summary = "订阅队列") |
| | | @GetMapping("/subscribe") |
| | | public R<Void> subscribe(@ApiParam("队列名") String queueName) { |
| | | public R<Void> subscribe(@Parameter(name = "队列名") String queueName) { |
| | | log.info("通道: {} 监听中......", queueName); |
| | | // 项目初始化设置一次即可 |
| | | QueueUtils.subscribeBlockingQueue(queueName, (String orderNum) -> { |
| | |
| | | return R.ok("操作成功"); |
| | | } |
| | | |
| | | @ApiOperation("添加队列数据") |
| | | @Operation(summary = "添加队列数据") |
| | | @GetMapping("/add") |
| | | public R<Void> add(@ApiParam("队列名") String queueName, |
| | | @ApiParam("订单号") String orderNum, |
| | | @ApiParam("延迟时间(秒)") Long time) { |
| | | public R<Void> add(@Parameter(name = "队列名") String queueName, |
| | | @Parameter(name = "订单号") String orderNum, |
| | | @Parameter(name = "延迟时间(秒)") Long time) { |
| | | QueueUtils.addDelayedQueueObject(queueName, orderNum, time, TimeUnit.SECONDS); |
| | | // 观察发送时间 |
| | | log.info("通道: {} , 发送数据: {}", queueName, orderNum); |
| | | return R.ok("操作成功"); |
| | | } |
| | | |
| | | @ApiOperation("删除队列数据") |
| | | @Operation(summary = "删除队列数据") |
| | | @GetMapping("/remove") |
| | | public R<Void> remove(@ApiParam("队列名") String queueName, |
| | | @ApiParam("订单号") String orderNum) { |
| | | public R<Void> remove(@Parameter(name = "队列名") String queueName, |
| | | @Parameter(name = "订单号") String orderNum) { |
| | | if (QueueUtils.removeDelayedQueueObject(queueName, orderNum)) { |
| | | log.info("通道: {} , 删除数据: {}", queueName, orderNum); |
| | | } else { |
| | |
| | | return R.ok("操作成功"); |
| | | } |
| | | |
| | | @ApiOperation("销毁队列") |
| | | @Operation(summary = "销毁队列") |
| | | @GetMapping("/destroy") |
| | | public R<Void> destroy(@ApiParam("队列名") String queueName) { |
| | | public R<Void> destroy(@Parameter(name = "队列名") String queueName) { |
| | | // 用完了一定要销毁 否则会一直存在 |
| | | QueueUtils.destroyDelayedQueue(queueName); |
| | | return R.ok("操作成功"); |