예제 #1
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);

            if (parts.Contains(LookupdKey))
            {
                foreach (var endPoint in ParseEndPoints(parts[LookupdKey], DefaultLookupdHttpPort))
                {
                    options.LookupEndPoints.Add(endPoint);
                }
            }
            else if (parts.Contains(NsqdKey))
            {
                options.NsqEndPoint = ParseEndPoints(parts[NsqdKey], DefaultNsqdTcpPort).Last();
            }
            else
            {
                throw new ArgumentException("Must provide either nsqlookupd or nsqd endpoints");
            }

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

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

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

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

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

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

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

            if (parts.Contains(MessagetimeoutKey))
            {
                options.MessageTimeout = int.Parse(parts[MessagetimeoutKey].Last());
            }

            return(options);
        }
예제 #2
0
 public NsqTcpConnection(DnsEndPoint endPoint, ConsumerOptions options)
     : this(endPoint, options, new ExponentialBackoffStrategy(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(30)))
 {
 }
예제 #3
0
 public NsqLookupConsumer(string connectionString)
     : this(ConsumerOptions.Parse(connectionString))
 {
 }
예제 #4
0
 public NsqLookupConsumer(string connectionString, ILogger logger)
     : this(ConsumerOptions.Parse(connectionString), logger)
 {
 }
예제 #5
0
 public static INsqConsumer Create(ConsumerOptions options)
 {
     return(Create(options, null));
 }
예제 #6
0
 public static INsqConsumer Create(string connectionString, ILogger logger)
 {
     return(Create(ConsumerOptions.Parse(connectionString), logger));
 }
예제 #7
0
 public static INsqConsumer Create(string connectionString)
 {
     return(Create(ConsumerOptions.Parse(connectionString)));
 }