NutzCN Logo
问答 rabbitmq和nutz集成,重复消费
发布于 1951天前 作者 qq_9a12783d 1554 次浏览 复制 上一个帖子 下一个帖子
标签:

产生和消费消息

 @Aop("rabbitmq") // 会自动管理Connection/Channel的开启和关闭.
    public void publish(byte[] body, QueueEnum queue) throws Exception {
        channel().queueDeclare(queue.getQueueName(), false, false, false, null);
        channel().basicPublish("", queue.getQueueName(), null, body);
        Logs.get().debug("加入队列");
    }

    @Aop("rabbitmq")
    public String get(QueueEnum queue){
        try {
            GetResponse response = channel().basicGet(queue.getQueueName(),true);
            if(response!=null){
                byte[] body = response.getBody();
                String str = new String(body,"utf-8");
                Logs.get().debug("获取消息=>" + str);
                return str;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

多线程消费

public  void tt(){
    	for(int i=0;i<10;i++) {
    		Tasks.scheduleAtFixedRate(new Runnable() {
                @Override
                public void run() {
                	 String str = rabbitService.get(queue);
                }
            }, i,1000, TimeUnit.MILLISECONDS);
    	}
        
    }

这样会造成多次消费,请问大神们这个需要怎么修改
使用的是rabbitmq的默认设置。

1 回复

ack方式,rabbitmq的使用问题自行查资料

添加回复
请先登陆
回到顶部