コード例 #1
0
        public NsqLookupConsumer(ConsumerOptions options)
        {
            _options = options;

            foreach (var lookupEndPoint in options.LookupEndPoints)
            {
                _lookupServers.Add(new NsqLookup(lookupEndPoint.Host, lookupEndPoint.Port));
            }

            _firstConnectionTask = _firstConnectionTaskCompletionSource.Task;
        }
コード例 #2
0
        public NsqTcpConnection(DnsEndPoint endPoint, ConsumerOptions options, IBackoffStrategy backoffStrategy)
        {
            _endPoint = endPoint;
            _options = options;
            _backoffStrategy = backoffStrategy;

            _connectionClosedSource = new CancellationTokenSource();

            _workerThread = new Thread(WorkerLoop);
            _workerThread.Name = "Turbocharged.NSQ Worker";
        }
コード例 #3
0
 public static INsqConsumer Create(ConsumerOptions options)
 {
     if (options.LookupEndPoints.Any())
     {
         return new NsqLookupConsumer(options);
     }
     else
     {
         return new NsqTcpConnection(options.NsqEndPoint, options);
     }
 }
コード例 #4
0
ファイル: Identify.cs プロジェクト: jennings/Turbocharged.NSQ
 public Identify(ConsumerOptions options)
 {
     _identifyRequest = new IdentifyRequest
     {
         client_id = options.ClientId,
         hostname = options.HostName,
         feature_negotiation = true,
         tls_v1 = false,
         snappy = false,
         deflate = false,
     };
 }
コード例 #5
0
 public NsqTcpConnection(DnsEndPoint endPoint, ConsumerOptions options)
     : this(endPoint, options, new ExponentialBackoffStrategy(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(30)))
 {
 }
コード例 #6
0
        /// <summary>
        /// Parses a connection string into a <c>ConsumerOptions</c> instance.
        /// </summary>
        /// <param name="connectionString">A semicolon-delimited list of key=value pairs of connection options.</param>
        /// <returns></returns>
        public static ConsumerOptions Parse(string connectionString)
        {
            var options = new ConsumerOptions();
            var parts = ParseIntoSegments(connectionString);

            var sb = new StringBuilder();

            if (parts.Contains(LOOKUPD_KEY))
            {
                foreach (var endPoint in ParseEndPoints(parts[LOOKUPD_KEY], DEFAULT_LOOKUPD_HTTP_PORT))
                {
                    options.LookupEndPoints.Add(endPoint);
                }

            }
            else if (parts.Contains(NSQD_KEY))
            {
                options.NsqEndPoint = ParseEndPoints(parts[NSQD_KEY], DEFAULT_NSQD_TCP_PORT).Last();
            }
            else
            {
                throw new ArgumentException("Must provide either nsqlookupd or nsqd endpoints");
            }

            if (parts.Contains(CLIENTID_KEY))
            {
                options.ClientId = parts[CLIENTID_KEY].Last();
            }

            if (parts.Contains(HOSTNAME_KEY))
            {
                options.HostName = parts[HOSTNAME_KEY].Last();
            }

            if (parts.Contains(LOOKUPPERIOD_KEY))
            {
                options.LookupPeriod = TimeSpan.FromSeconds(int.Parse(parts[LOOKUPPERIOD_KEY].Last()));
            }

            if (parts.Contains(TOPIC_KEY))
            {
                options.Topic = parts[TOPIC_KEY].Last();
            }

            if (parts.Contains(CHANNEL_KEY))
            {
                options.Channel = parts[CHANNEL_KEY].Last();
            }

            if (parts.Contains(RECONNECTIONDELAY_KEY))
            {
                options.ReconnectionDelay = TimeSpan.FromSeconds(int.Parse(parts[RECONNECTIONDELAY_KEY].Last()));
            }

            if (parts.Contains(RECONNECTIONMAXDELAY_KEY))
            {
                options.ReconnectionMaxDelay = TimeSpan.FromSeconds(int.Parse(parts[RECONNECTIONMAXDELAY_KEY].Last()));
            }

            return options;
        }