65 lines
2.3 KiB
C#
65 lines
2.3 KiB
C#
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.Intrinsics.X86;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
|
using ServerCore;
|
|
|
|
|
|
namespace ServerBase;
|
|
|
|
public abstract partial class RabbitMqConnector : RabbitMQConnectorBase, IRabbitMqSession, IModule
|
|
{
|
|
public class ConfigParam : IConfigParam
|
|
{
|
|
public string ServiceType { get; set; } = string.Empty;
|
|
public string ServiceName { get; set; } = string.Empty;
|
|
public string HostName { get; set; } = string.Empty;
|
|
public string UserName { get; set; } = string.Empty;
|
|
public string Password { get; set; } = string.Empty;
|
|
public ushort Port { get; set; } = 0;
|
|
public bool UseSSL { get; set; } = false;
|
|
|
|
public RabbitMqConnector.FnServerMessageRecvFromConsumer? fnServerMessageRecvFromConsumer { get; set; }
|
|
|
|
public Result tryReadFromJsonOrDefault(JObject jObject)
|
|
{
|
|
var result = new Result();
|
|
var err_msg = string.Empty;
|
|
|
|
try
|
|
{
|
|
var rabbit_mq = jObject["Rabbitmq"];
|
|
NullReferenceCheckHelper.throwIfNull(rabbit_mq, () => $"rabbit_mq is null !!!");
|
|
HostName = rabbit_mq["HostName"]?.Value<string>() ?? HostName;
|
|
UserName = rabbit_mq["UserName"]?.Value<string>() ?? UserName;
|
|
Password = rabbit_mq["Password"]?.Value<string>() ?? Password;
|
|
Port = rabbit_mq["Port"]?.Value<ushort>() ?? Port;
|
|
UseSSL = rabbit_mq["SSL"]?.Value<bool>() ?? UseSSL;
|
|
|
|
return result;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
var error_code = ServerErrorCode.TryCatchException;
|
|
err_msg = $"Exception !!!, Failed to perform in tryReadFromJsonOrDefault() !!! : errorCode:{error_code}, exception:{e} - {this.getTypeName()}";
|
|
result.setFail(error_code, err_msg);
|
|
Log.getLogger().error(err_msg);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public string toBasicString()
|
|
{
|
|
return $"ConfigParam: ServiceType:{ServiceType}, ServiceName:{ServiceName}, HostAddress:{HostName}, Port:{Port}, UserName:{UserName}, Password:{Password}, UseSsl:{UseSSL}";
|
|
}
|
|
}
|
|
};
|