RabbitMQ的基本使用到高階特性

2022-01-20 11:30:09 字數 2144 閱讀 4295

這裡需要增加乙個使用者,並且設定使用者為administrator,更多命令可以參考rabbitmq更多命令,這裡開始我本來是想用guest使用者,埠是:15672,但是在建立連線的時候是連線不上的,查資料後發現是必須開放5672埠,並且不能使用guest預設使用者

rabbitmqctl add_user allen pwd   //增加使用者

rabbitmqctl set_user_tags allen administrator //設定使用者許可權

rabbitmqctl change_password allen newpass //修改密碼

開啟5672埠

firewall-cmd --zone=public --add-port=5672/tcp --permanent

firewall-cmd --reload

連線之前可以看到,rabbitmq的ui介面是沒有連線的

send發布者的**

/// /// 傳送訊息

///

public class send

", message);}}

} }}

rabbitmquri的value相當於:

未建立連線時:

建立連線後:

傳送訊息

可以看到rabbitmq的ui管理介面的訊息有:

receive消費者收到的訊息:

receive的**:

/// /// 接收訊息

///

public class receive

", message);

};channel.basicconsume(queue, true, consumer); //開啟消費者與通道、佇列關聯

console.readline();

}}

}

如果遇到這種情況:

operationinterruptedexception: the amqp operation was interrupted: amqp close-reason, initiated by peer, code=530, text="not_allowed - access to vhost 'test' refused for user 'allen'", classid=10, methodid=40, cause=
這是許可權問題,儘管我們已經設定了allen使用者為administrator管理員,也就是:使用者『allen』沒有許可權訪問『/』

解決方案:

#sudo rabbitmqctl list_users

列出使用者許可權

該命令使使用者allen具有『/』這個virtual host中所有資源的配置、寫、讀許可權以便管理其中的資源

最後,附上原始碼位址,包括rabbitmq的基本用法,發布訂閱,高階特性demo

rabbitmq的基本使用

現在微服務盛行,我們通常會進行解耦,這時候就需要非同步的訊息佇列來幫助各個服務之間解耦 rabbitmq的基本概念有訊息producer 訊息生產者 exchange 交換機 queue 佇列 consumer 消費者 routingkey 圖中的p是producer,即訊息生產者,中簡的serve...

rabbitmq的基本使用

現在微服務盛行,我們通常會進行解耦,這時候就需要非同步的訊息佇列來幫助各個服務之間解耦 rabbitmq的基本概念有訊息producer 訊息生產者 exchange 交換機 queue 佇列 consumer 消費者 routingkey 圖中的p是producer,即訊息生產者,中簡的serve...

rabbitmq基本使用

生產者 public class rabbitmqhelper port 5672 using var connection factory.createconnection using var channel connection.createmodel t.tojsonstring 消費者 cl...