void IReqRepImpl.SetupConnection(ClientContextBase ctx) { Original.Options opts = ConnectionUtils.GetDefaultOptions(); var cf = new Original.ConnectionFactory(); ctx.Connection = cf.CreateConnection(opts); }
public NatsConnection(ConnectionFactory factory, IOptions <NatsOptions> options, ILogger <NatsConnection> logger) { _logger = logger; _factory = factory; var settings = options.Value; _opts = ConnectionFactory.GetDefaultOptions(); _opts.Servers = settings.Servers; _opts.MaxReconnect = settings.RetryCount; if (!string.IsNullOrEmpty(settings.Username)) { _opts.User = settings.Username; } if (!string.IsNullOrEmpty(settings.Password)) { _opts.Password = settings.Password; } if (!string.IsNullOrEmpty(settings.Token)) { _opts.Token = settings.Token; } _opts.DisconnectedEventHandler += (sender, args) => { _logger.LogWarning("Connection to NATS disconnected. Trying to reconnect..."); VerifyConnection(); }; }
/// <summary> /// CreateSecureConnection will attempt to connect to the NATS server using TLS. /// The url can contain username/password semantics. /// </summary> /// <param name="url">connect url</param> /// <returns>A new connection to the NATS server</returns> public IConnection CreateSecureConnection(string url) { Options opts = new Options(); opts.Url = url; opts.Secure = true; return CreateConnection(opts); }
public FlowmakerConnection(string natsServerUrl = null) { var factorty = new NC.ConnectionFactory(); _natsOptions = NC.ConnectionFactory.GetDefaultOptions(); _natsOptions.Url = natsServerUrl == null ? "demo.nats.io:4222" : natsServerUrl; _connection = factorty.CreateConnection(_natsOptions); }
public static Original.Options GetDefaultOptions() { Original.Options opts = Original.ConnectionFactory.GetDefaultOptions(); opts.PingInterval = 30000; opts.Timeout = 5000; opts.Servers = servers; return(opts); }
private void ProducingWorker(object state) { var ctx = (MyWorkerContext)state; Original.Options opts = ConnectionUtils.GetDefaultOptions(); var cf = new Original.ConnectionFactory(); using (Original.IConnection conn = cf.CreateConnection(opts)) { Workers.RunPublisher(conn, ctx); } }
private void ConsumingWorker(object state) { var ctx = (MyWorkerContext)state; Original.Options opts = ConnectionUtils.GetDefaultOptions(); var cf = new Original.ConnectionFactory(); using (Original.IConnection conn = cf.CreateConnection(opts)) { Workers.RunParallelPassiveConsumer(conn, ctx, ConsumingAgentCount); //Workers.RunParallelReactiveConsumer(conn, ctx, ConsumingAgentCount); } }
// Copy constructor internal Options(Options o) { this.allowReconnect = o.allowReconnect; this.AsyncErrorEventHandler = o.AsyncErrorEventHandler; this.ClosedEventHandler = o.ClosedEventHandler; this.DisconnectedEventHandler = o.DisconnectedEventHandler; this.maxPingsOut = o.maxPingsOut; this.maxReconnect = o.maxReconnect; if (o.name != null) { this.name = new string(o.name.ToCharArray()); } this.noRandomize = o.noRandomize; this.pedantic = o.pedantic; this.pingInterval = o.pingInterval; this.ReconnectedEventHandler = o.ReconnectedEventHandler; this.reconnectWait = o.reconnectWait; this.secure = o.secure; this.verbose = o.verbose; if (o.servers != null) { this.servers = new string[o.servers.Length]; Array.Copy(o.servers, this.servers, o.servers.Length); } this.subChanLen = o.subChanLen; this.timeout = o.timeout; this.TLSRemoteCertificationValidationCallback = o.TLSRemoteCertificationValidationCallback; if (o.url != null) { this.url = new String(o.url.ToCharArray()); } if (o.certificates != null) { this.certificates = new X509Certificate2Collection(o.certificates); } }
public void InitConnSetup(CfServerSetting setting, string roomKey) { Debug.Log(setting); GDServiceConfig = setting.GameDuelService; main_ch = new Channel( setting.GameDuelService.Host, setting.GameDuelService.Port, ChannelCredentials.Insecure ); GDSClient = new GameDuelService.GameDuelServiceClient(main_ch); var streamSet = setting.GameDuelService.StreamSetting; natOpt = ConnectionFactory.GetDefaultOptions(); natOpt.Url = $"{streamSet.Connector}://{streamSet.Host}:{streamSet.Port}"; Debug.Log(natOpt.Url); RoomKey = roomKey; natConn = new ConnectionFactory().CreateConnection(natOpt); // natConn.SubscribeAsync($"ULZ.GDSvc/{RoomKey}", OnSubMsgHandle); }
public bool InitSetup(CfServerSetting setting) { config = setting; // main_ch = new Channel( // setting.Host + ":" + setting.Port.ToString() + "/room-service", // ChannelCredentials.Insecure // ); main_ch = new Channel( setting.RoomService.Host, setting.RoomService.Port, ChannelCredentials.Insecure ); client = new RoomService.RoomServiceClient(main_ch); CurrentUser = new RmUserInfo { Id = setting.UserInfo.Id, Name = setting.UserInfo.Name, Level = setting.UserInfo.Level, Rank = setting.UserInfo.Rank, }; natOpt = ConnectionFactory.GetDefaultOptions(); natOpt.Url = $"{setting.RoomService.StreamSetting.Connector}://{setting.RoomService.StreamSetting.Host}:{setting.RoomService.StreamSetting.Port}"; return(false); }
internal Connection(Options opts) { this.opts = new Options(opts); this.pongs = createPongs(); this.ps = new Parser(this); PING_P_BYTES = System.Text.Encoding.UTF8.GetBytes(IC.pingProto); PING_P_BYTES_LEN = PING_P_BYTES.Length; PONG_P_BYTES = System.Text.Encoding.UTF8.GetBytes(IC.pongProto); PONG_P_BYTES_LEN = PONG_P_BYTES.Length; PUB_P_BYTES = Encoding.UTF8.GetBytes(IC._PUB_P_); PUB_P_BYTES_LEN = PUB_P_BYTES.Length; CRLF_BYTES = Encoding.UTF8.GetBytes(IC._CRLF_); CRLF_BYTES_LEN = CRLF_BYTES.Length; // predefine the start of the publish protocol message. buildPublishProtocolBuffer(Defaults.scratchSize); }
internal EncodedConnection(Options opts) : base(opts) { this.onSerialize = defaultSerializer; this.onDeserialize = defaultDeserializer; }
internal Connection(Options opts) { this.opts = opts; this.pongs = createPongs(); this.ps = new Parser(this); this.pingProtoBytes = System.Text.Encoding.UTF8.GetBytes(IC.pingProto); this.pingProtoBytesLen = pingProtoBytes.Length; this.pongProtoBytes = System.Text.Encoding.UTF8.GetBytes(IC.pongProto); this.pongProtoBytesLen = pongProtoBytes.Length; }
/// <summary> /// CreateConnection will attempt to connect to the NATS server. /// The url can contain username/password semantics. /// Comma seperated arrays are also supported, e.g. urlA, urlB. /// </summary> /// <param name="url">The url</param> /// <returns>A new connection to the NATS server</returns> public IConnection CreateConnection(string url) { Options opts = new Options(); opts.processUrlString(url); return CreateConnection(opts); }
// Copy constructor internal Options(Options o) { allowReconnect = o.allowReconnect; AsyncErrorEventHandler = o.AsyncErrorEventHandler; ClosedEventHandler = o.ClosedEventHandler; DisconnectedEventHandler = o.DisconnectedEventHandler; maxPingsOut = o.maxPingsOut; maxReconnect = o.maxReconnect; if (o.name != null) { name = new string(o.name.ToCharArray()); } noRandomize = o.noRandomize; pedantic = o.pedantic; pingInterval = o.pingInterval; ReconnectedEventHandler = o.ReconnectedEventHandler; reconnectWait = o.reconnectWait; secure = o.secure; user = o.user; password = o.password; token = o.token; verbose = o.verbose; subscriberDeliveryTaskCount = o.subscriberDeliveryTaskCount; if (o.servers != null) { servers = new string[o.servers.Length]; Array.Copy(o.servers, servers, o.servers.Length); } subChanLen = o.subChanLen; timeout = o.timeout; TLSRemoteCertificationValidationCallback = o.TLSRemoteCertificationValidationCallback; if (o.url != null) { url = new String(o.url.ToCharArray()); } if (o.certificates != null) { certificates = new X509Certificate2Collection(o.certificates); } }
/// <summary> /// CreateConnection to the NATs server using the provided options. /// </summary> /// <param name="opts">NATs client options</param> /// <returns>A new connection to the NATS server</returns> public IConnection CreateConnection(Options opts) { Connection nc = new Connection(opts); nc.connect(); return nc; }
/// <summary> /// CreateEncodeedConnection will attempt to connect to the NATS server. /// The url can contain username/password semantics. /// </summary> /// <param name="url">The url</param> /// <returns>A new connection to the NATS server</returns> public IEncodedConnection CreateEncodedConnection(string url) { Options opts = new Options(); opts.Url = url; return CreateEncodedConnection(opts); }
internal void makeTLS(Options options) { RemoteCertificateValidationCallback cb = null; if (stream == null) throw new NATSException("Internal error: Cannot create SslStream from null stream."); cb = options.TLSRemoteCertificationValidationCallback; if (cb == null) cb = remoteCertificateValidation; sslStream = new SslStream(stream, false, cb, null, EncryptionPolicy.RequireEncryption); try { SslProtocols protocol = (SslProtocols)Enum.Parse(typeof(SslProtocols), "Tls12"); sslStream.AuthenticateAsClientAsync(hostName, options.certificates, protocol, true).Wait(); } catch (Exception ex) { closeClient(client); throw new NATSConnectionException("TLS Authentication error", ex); } }
/// <summary> /// CreateEncodedConnection to the NATs server using the provided options. /// </summary> /// <param name="opts">NATs client options</param> /// <returns>A new connection to the NATS server</returns> public IEncodedConnection CreateEncodedConnection(Options opts) { EncodedConnection nc = new EncodedConnection(opts); nc.connect(); return nc; }
internal Connection(Options options) { opts = new Options(options); pongs = createPongs(); PING_P_BYTES = Encoding.UTF8.GetBytes(IC.pingProto); PING_P_BYTES_LEN = PING_P_BYTES.Length; PONG_P_BYTES = Encoding.UTF8.GetBytes(IC.pongProto); PONG_P_BYTES_LEN = PONG_P_BYTES.Length; PUB_P_BYTES = Encoding.UTF8.GetBytes(IC._PUB_P_); PUB_P_BYTES_LEN = PUB_P_BYTES.Length; CRLF_BYTES = Encoding.UTF8.GetBytes(IC._CRLF_); CRLF_BYTES_LEN = CRLF_BYTES.Length; // predefine the start of the publish protocol message. buildPublishProtocolBuffer(Defaults.scratchSize); callbackScheduler.Start(); }