feat: add client name option for user identification in system events

This commit is contained in:
wenzuhuai
2026-02-03 11:12:47 +08:00
parent 9161052033
commit 59800438b3
2 changed files with 14 additions and 3 deletions

View File

@@ -31,8 +31,16 @@ public class NatsClientOptions {
private var clientCertificate: URL? = nil
private var clientKey: URL? = nil
private var inboxPrefix: String = "_INBOX."
private var clientName: String = ""
public init() {}
/// Sets the client name sent to the server during CONNECT.
/// This name appears in system events and can be used to identify the client.
public func name(_ name: String) -> NatsClientOptions {
self.clientName = name
return self
}
/// Sets the prefix for inbox subjects used for request/reply.
/// Defaults to "_INBOX."
@@ -195,7 +203,8 @@ public class NatsClientOptions {
clientCertificate: clientCertificate,
clientKey: clientKey,
rootCertificate: rootCertificate,
retryOnFailedConnect: initialReconnect
retryOnFailedConnect: initialReconnect,
name: clientName
)
return client
}