Skip to content

Commit

Permalink
[feat] 支持TLS通信,设置SSL协议类型以及证书。#84
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Dec 1, 2024
1 parent 9fe5c51 commit 41b8335
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
7 changes: 6 additions & 1 deletion NewLife.RocketMQ/ClusterClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ protected void EnsureCreate()
client.Add(new MqCodec { Timeout = Timeout });

// 关闭Tcp延迟以合并小包的算法,降低延迟
if (client is TcpSession tcp) tcp.NoDelay = true;
if (client is TcpSession tcp)
{
tcp.SslProtocol = Config.SslProtocol;
tcp.Certificate = Config.Certificate;
tcp.NoDelay = true;
}

try
{
Expand Down
15 changes: 15 additions & 0 deletions NewLife.RocketMQ/MqBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Reflection;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using NewLife.Log;
using NewLife.Net;
using NewLife.RocketMQ.Protocol;
Expand Down Expand Up @@ -53,6 +55,19 @@ public abstract class MqBase : DisposeBase
/// <summary>序列化类型。默认Json,支持RocketMQ二进制</summary>
public SerializeType SerializeType { get; set; } = SerializeType.JSON;

/// <summary>SSL协议。默认None</summary>
public SslProtocols SslProtocol { get; set; } = SslProtocols.None;

/// <summary>X509证书。用于SSL连接时验证证书指纹,可以直接加载pem证书文件,未指定时不验证证书</summary>
/// <remarks>
/// 可以使用pfx证书文件,也可以使用pem证书文件。
/// 服务端必须指定证书。
/// </remarks>
/// <example>
/// var cert = new X509Certificate2("file", "pass");
/// </example>
public X509Certificate? Certificate { get; set; }

Check warning on line 69 in NewLife.RocketMQ/MqBase.cs

View workflow job for this annotation

GitHub Actions / build-test

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 69 in NewLife.RocketMQ/MqBase.cs

View workflow job for this annotation

GitHub Actions / build-test

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 69 in NewLife.RocketMQ/MqBase.cs

View workflow job for this annotation

GitHub Actions / build-test

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 69 in NewLife.RocketMQ/MqBase.cs

View workflow job for this annotation

GitHub Actions / build-test

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 69 in NewLife.RocketMQ/MqBase.cs

View workflow job for this annotation

GitHub Actions / build-publish

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 69 in NewLife.RocketMQ/MqBase.cs

View workflow job for this annotation

GitHub Actions / build-publish

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 69 in NewLife.RocketMQ/MqBase.cs

View workflow job for this annotation

GitHub Actions / build-publish

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

//public Boolean VipChannelEnabled { get; set; } = true;

/// <summary>是否可用</summary>
Expand Down

0 comments on commit 41b8335

Please sign in to comment.