| | |
| | | |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.utils.redis.QueueUtils; |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | * @version 3.6.0 |
| | | */ |
| | | @Slf4j |
| | | @Tag(name ="有界队列 演示案例", description = "有界队列") |
| | | @Tag(name = "有界队列 演示案例", description = "有界队列") |
| | | @RequiredArgsConstructor |
| | | @RestController |
| | | @RequestMapping("/demo/queue/bounded") |
| | | public class BoundedQueueController { |
| | | |
| | | |
| | | /** |
| | | * 添加队列数据 |
| | | * |
| | | * @param queueName 队列名 |
| | | * @param capacity 容量 |
| | | */ |
| | | @GetMapping("/add") |
| | | public R<Void> add(@Parameter(name = "队列名") String queueName, |
| | | @Parameter(name = "容量") int capacity) { |
| | | public R<Void> add(String queueName, int capacity) { |
| | | // 用完了一定要销毁 否则会一直存在 |
| | | boolean b = QueueUtils.destroyBoundedQueueObject(queueName); |
| | | log.info("通道: {} , 删除: {}", queueName, b); |
| | |
| | | return R.ok("操作成功"); |
| | | } |
| | | |
| | | /** |
| | | * 删除队列数据 |
| | | * |
| | | * @param queueName 队列名 |
| | | */ |
| | | @GetMapping("/remove") |
| | | public R<Void> remove(@Parameter(name = "队列名") String queueName) { |
| | | public R<Void> remove(String queueName) { |
| | | String data = "data-" + 5; |
| | | if (QueueUtils.removeBoundedQueueObject(queueName, data)) { |
| | | log.info("通道: {} , 删除数据: {}", queueName, data); |
| | |
| | | return R.ok("操作成功"); |
| | | } |
| | | |
| | | /** |
| | | * 获取队列数据 |
| | | * |
| | | * @param queueName 队列名 |
| | | */ |
| | | @GetMapping("/get") |
| | | public R<Void> get(@Parameter(name = "队列名") String queueName) { |
| | | public R<Void> get(String queueName) { |
| | | String data; |
| | | do { |
| | | data = QueueUtils.getBoundedQueueObject(queueName); |