示例#1
0
        public IActionResult GetResults(string actionType, string workerId)
        {
            var routingKey = RoutingKeys.FormatKey(actionType, workerId);
            var results    = ImMemResultsStorage.Results.Where(m => m.RoutingKey == routingKey);

            return(new JsonResult(results));
        }
示例#2
0
 /// <summary>
 /// Determines if this queue has any related routing keys
 /// </summary>
 /// <returns></returns>
 public bool HasRoutingKeys()
 {
     if (RoutingKeys == null)
     {
         return(false);
     }
     return(RoutingKeys.Any());
 }
        public string[] GetRoutingKeysAsArray()
        {
            if (string.IsNullOrEmpty(RoutingKeys))
            {
                return(new string[0]);
            }

            return(RoutingKeys.Split(new [] { " " }, StringSplitOptions.RemoveEmptyEntries));
        }
示例#4
0
        /// <summary>
        /// 获取路由键
        /// </summary>
        /// <param name="routingKey">路由键</param>
        /// <returns>路由键</returns>
        public string GetRoutingKey(string routingKey = null)
        {
            if (RoutingKeys.IsNullOrLength0())
            {
                return(routingKey);
            }

            return(string.IsNullOrWhiteSpace(routingKey) ? RoutingKeys[0] : routingKey);
        }
示例#5
0
 public override int GetHashCode()
 {
     unchecked
     {
         // ReSharper disable NonReadonlyFieldInGetHashCode
         int hashCode = (Reason != null ? Reason.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Queue != null ? Queue.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Exchange != null ? Exchange.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (RoutingKeys != null ? RoutingKeys.GetHashCode() : 0);
         return(hashCode);
         // ReSharper restore NonReadonlyFieldInGetHashCode
     }
 }
示例#6
0
        private async Task StartQueueReader()
        {
            lock (_sync)
            {
                Data      = new List <CustomQueueItem <T> >();
                _isActive = true;
            }

            var factory = new ConnectionFactory
            {
                Uri = new Uri(_connectionString)
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    channel.BasicQos(0, (ushort)_prefetchCount, false);

                    channel.QueueDeclare(QueueName, true, false, IsQueueAutoDelete);

                    if (RoutingKeys.Any())
                    {
                        foreach (var key in RoutingKeys)
                        {
                            channel.QueueBind(QueueName, ExchangeName, key);
                        }
                    }
                    else
                    {
                        channel.QueueBind(QueueName, ExchangeName, "");
                    }
                    var consumer = new EventingBasicConsumer(channel);

                    consumer.Received += CreateOnMessageReceivedEventHandler(channel);

                    var tag = channel.BasicConsume(QueueName, false, consumer);

                    var writerTask = StartHandler(connection);

                    while (!_cancellationTokenSource.IsCancellationRequested && connection.IsOpen)
                    {
                        await Task.Delay(100);
                    }

                    await writerTask;

                    channel.BasicCancel(tag);
                    connection.Close();
                }
        }
示例#7
0
        public void BindQueue(IModel channel)
        {
            if (string.IsNullOrEmpty(ExchangeName))
            {
                return;
            }

            if (RoutingKeys.Count == 0)
            {
                RoutingKeys = new List <string>(new[] { "" });
            }

            RoutingKeys
            .ForEach(x => channel.QueueBind(QueueName, ExchangeName, x, null));
        }
示例#8
0
 public override int GetHashCode()
 {
     unchecked
     {
         int result = (Broker != null ? Broker.GetHashCode() : 0);
         result = (result * 397) ^ (VirtualHost != null ? VirtualHost.GetHashCode() : 0);
         result = (result * 397) ^ (Username != null ? Username.GetHashCode() : 0);
         result = (result * 397) ^ (Password != null ? Password.GetHashCode() : 0);
         result = (result * 397) ^ (Exchange != null ? Exchange.GetHashCode() : 0);
         result = (result * 397) ^ (QueueName != null ? QueueName.GetHashCode() : 0);
         result = (result * 397) ^ (RoutingKeys != null ? RoutingKeys.GetHashCode() : 0);
         result = (result * 397) ^ RouteByType.GetHashCode();
         return(result);
     }
 }
示例#9
0
 public bool Equals(RabbitMqXDeath other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return
         (Count == other.Count &&
          string.Equals(Exchange, other.Exchange) &&
          string.Equals(Queue, other.Queue) &&
          string.Equals(Reason, other.Reason) &&
          RoutingKeys.All(other.RoutingKeys.Contains) &&
          Time == other.Time);
 }
示例#10
0
 public void AddRouteKey(string key)
 {
     RoutingKeys.Add(key);
 }