Check if a queue Exists


Is there any way to check if a queue exists ?

Checking in a queue exists is a slightly vague term so I’m going to assume that you want to check that a queue is currently being processed by a worker. The Servers() method on the IMonitoringApi returns a list of servers which haven’t timed out along with the queues they are processing:

IMonitoringApi monitoringApi = JobStorage.Current.GetMonitoringApi();
IList<ServerDto> servers = monitoringApi .Servers();

const queueName = "Default";
bool queueIsBeingProcessed = servers.Any(
    s => s.Queues.Contains(queueName, StringComparer.InvariantCultureIgnoreCase)
1 Like

yes thank you

Actually before your response I have implemented it as below

public bool ExistQueue(string queueName)
            var result = new List<ServerDto>();
        UseConnection<IList<ServerDto>>(connection =>
            var servers = connection.Query<Entities.Server>(
                @"select * from HangFire.Server")

            foreach (var server in servers)
                var data = JobHelper.FromJson<ServerData>(server.Data);
                result.Add(new ServerDto
                    Name = server.Id,
                    Heartbeat = server.LastHeartbeat,
                    Queues = data.Queues,
                    StartedAt = data.StartedAt.HasValue ? data.StartedAt.Value : DateTime.MinValue,
                    WorkersCount = data.WorkerCount

            return result;
        return result.Count(x => x.Queues.Contains(queueName)) == 1;