C# Rabbitmq RPC模式服务器超时解决方案

利用2个task实现,看红字,直接看代码
public string Call(string rpc_queue, byte[] obj)
{
string rstr = “no”;
var channel = this.GetModel(RpcChannel); channel.ContinuationTimeout = TimeSpan.FromSeconds(10);
channel.BasicPublish(exchange: “”, routingKey: rpc_queue, basicProperties: props, body: obj);
channel.BasicConsume(consumer: consumer, queue: replyQueueName, autoAck: true);
Task[] tasks = new Task[2];
tasks[0] = Task.Run(async () =>
{
await Task.Delay(6000);//超时
respQueue.Add(rstr);
//respQueue.CompleteAdding();
});
tasks[1] = Task.Run(() =>
{
rstr = respQueue.Take();
});
try
{
Task.WaitAll(tasks);
}
catch (AggregateException ae)
{
foreach (var ex in ae.InnerExceptions)
Console.WriteLine(” {0}: {1}”, ex.GetType().Name, ex.Message);
}
return rstr;
}

在CentOS7上安装RabbitMQ

在CentOS7上安装RabbitMQ
1、erlang安装
rpm -Uvh https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
yum install erlang

rabbitmq安装
wget https://www.rabbitmq.com/releases/rabbitmq-server/v3.6.15/rabbitmq-server-3.6.15-1.el7.noarch.rpm
yum install rabbitmq-server-3.6.15-1.el7.noarch.rpm

rabbitmq启动
systemctl start rabbitmq-server
rabbitmq管理插件安装
rabbitmq-plugins enable rabbitmq_management
rabbitmq加入开机启动
systemctl enable rabbitmq-server.service
rabbitmq启动服务
systemctl start rabbitmq-server.service
rabbitmq加入管理员和管理组和权限设置
rabbitmqctl add_user admin admin
rabbitmqctl set_user_tags admin administrator
rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"

删除guest用户
rabbitmqctl delete_user guest
开放rabbitmq15672端口
firewall-cmd --zone=public --add-port=15672/tcp --permanent
firewall-cmd --reload

查看rabbitmq安装成功
http://rabbitmq-server:15672/
如果发送订阅没有效果
cd /usr/share/doc/rabbitmq-server-3.7.17/
cp rabbitmq.config.example /etc/rabbitmq/
cd /etc/rabbitmq/
mv rabbitmq.config.example rabbitmq.config
修改rabbitmq.config里面disk_free_limit变量为500M,注意取消注释,重启rabbitmq,注意后面逗号影响重新启动