src/09_MessageQueue/MessageQueue.RabbitMQ/RabbitMQClient.cs
(开头部分) 7KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Text;
using Mkh.Utils.Json;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
namespace Mkh.MessageQueue.RabbitMQ;
// ReSharper disable once InconsistentNaming
/// <summary>
/// RabbitMQ客户端
/// </summary>
public class RabbitMQClient : IDisposable
{
//发送连接
private IConnection _sendConnection;
//接收连接
private IConnection _receiveConnection;
private readonly RabbitMQConfig _config;
private readonly JsonHelper _jsonHelper;
public RabbitMQClient(RabbitMQConfig config, JsonHelper jsonHelper)
{
_config = config;
_jsonHelper = jsonHelper;
CreateConnection();
}
internal void CreateConnection()
{
Check.NotNull(_config.UserName, nameof(_config.UserName), "用户名不能为空");
Check.NotNull(_config.Password, nameof(_config.Password), "密码不能为空");
if (_config.HostName.IsNull())
_config.HostName = "localhost";
if (_config.Port < 1 || _config.Port > 65535)
_config.Port = 5672;
var factory = new ConnectionFactory
{
HostName = _config.HostName,
Port = _config.Port,
UserName = _config.UserName,
Password = _config.Password,
AutomaticRecoveryEnabled = true,
NetworkRecoveryInterval = TimeSpan.FromSeconds(10)
};
if (_config.VirtualHost.NotNull())
factory.VirtualHost = _config.VirtualHost;
_sendConnection = factory.CreateConnection();
_receiveConnection = factory.CreateConnection();
}
后面还有 167 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
