|
|
|
@ -1,9 +1,11 @@
|
|
|
|
|
package org.dromara.demo.controller.queue;
|
|
|
|
|
|
|
|
|
|
import cn.dev33.satoken.annotation.SaIgnore;
|
|
|
|
|
import org.dromara.common.core.domain.R;
|
|
|
|
|
import org.dromara.common.redis.utils.QueueUtils;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.redisson.api.RBoundedBlockingQueue;
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
@ -19,6 +21,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
* @author Lion Li
|
|
|
|
|
* @version 3.6.0
|
|
|
|
|
*/
|
|
|
|
|
@SaIgnore
|
|
|
|
|
@Slf4j
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
@RestController
|
|
|
|
@ -35,7 +38,7 @@ public class BoundedQueueController {
|
|
|
|
|
@GetMapping("/add")
|
|
|
|
|
public R<Void> add(String queueName, int capacity) {
|
|
|
|
|
// 用完了一定要销毁 否则会一直存在
|
|
|
|
|
boolean b = QueueUtils.destroyQueue(queueName);
|
|
|
|
|
boolean b = QueueUtils.destroyBoundedQueue(queueName);
|
|
|
|
|
log.info("通道: {} , 删除: {}", queueName, b);
|
|
|
|
|
// 初始化设置一次即可
|
|
|
|
|
if (QueueUtils.trySetBoundedQueueCapacity(queueName, capacity)) {
|
|
|
|
@ -64,7 +67,7 @@ public class BoundedQueueController {
|
|
|
|
|
@GetMapping("/remove")
|
|
|
|
|
public R<Void> remove(String queueName) {
|
|
|
|
|
String data = "data-" + 5;
|
|
|
|
|
if (QueueUtils.removeQueueObject(queueName, data)) {
|
|
|
|
|
if (QueueUtils.removeBoundedQueueObject(queueName, data)) {
|
|
|
|
|
log.info("通道: {} , 删除数据: {}", queueName, data);
|
|
|
|
|
} else {
|
|
|
|
|
return R.fail("操作失败");
|
|
|
|
@ -81,7 +84,7 @@ public class BoundedQueueController {
|
|
|
|
|
public R<Void> get(String queueName) {
|
|
|
|
|
String data;
|
|
|
|
|
do {
|
|
|
|
|
data = QueueUtils.getQueueObject(queueName);
|
|
|
|
|
data = QueueUtils.getBoundedQueueObject(queueName);
|
|
|
|
|
log.info("通道: {} , 获取数据: {}", queueName, data);
|
|
|
|
|
} while (data != null);
|
|
|
|
|
return R.ok("操作成功");
|
|
|
|
|