문제

클라이언트 애플리케이션에서 RabbitMQ 대기열의 메시지 수를 확인하는 방법이 있는지 아는 사람이 있습니까?

.NET 클라이언트 라이브러리를 사용하고 있습니다.

도움이 되었습니까?

해결책

실제로 클라이언트를 통해 이것을 검색 할 수 있습니다. 수행 할 때 queue_declare 작업 RabbitMQ 작동은 3 개의 튜플을 포함합니다 (<queue name>, <message count>, <consumer count>). 그만큼 passive queue_declare에 대한 인수를 사용하면 서버 상태를 수정하지 않고 큐가 존재하는지 확인할 수 있습니다. 그래서 당신은 사용할 수 있습니다 queue_declare 이랑 passive 대기열 길이를 확인하는 옵션. .NET에 대해서는 잘 모르겠지만 파이썬에서는 다음과 같습니다.

name, jobs, consumers = chan.queue_declare(queue=queuename, passive=True)

다른 팁

나는 2 년이 너무 늦었지만 직접 찾고 있었고 Rabbitmq는 rabbitmq의 시작 스크립트가있는 sbin 폴더에서 Erlang 노드와 통신 할 간단한 스크립트를 제공한다는 것을 알았습니다. 기본적으로 말할 수 있습니다.

./rabbitmqctl list_queues

이것은 대기열과 마찬가지로 해당 대기열에 계류중인 메시지 수와 함께 대기열을 표시합니다.

./rabbitmqctl list_channels
./rabbitmqctl list_connections

자세한 정보는 방문 할 수 있습니다 여기

.NET 에서이 작업을 수행하려면 사용중인 클라이언트 라이브러리 버전을 확인하십시오.

나는 사용하고있다 2.2.0 버전과 나는 basicget (큐, noack)을 사용해야했습니다.
이 버전의 라이브러리에서 queuedeclare ()는 큐 이름이 포함 된 문자열 만 반환합니다.

BasicGetResult result = channel.BasicGet("QueueName", false);
uint count = result != null ? result.MessageCount : 0;


나는 알고있다 2.6.1 버전, QueuedeClare ()는 QueuedeClareok 유형의 객체를 반환합니다.

QueueDeclareOk result = channel.QueueDeclare();
uint count = result.MessageCount;


또는 명령 줄에서 호출 할 수 있습니다.

<InstallPathToRabbitMq>\sbin\rabbitmqctl.bat list_queues

그리고 당신은 다음과 같은 출력을 볼 수 있습니다.

목록 대기열 ...
QueueName 1
...완료.

HTH

버전을 사용하고 있습니다 3.3.1 .NET 클라이언트 라이브러리의.

Ralph Willgoss Second 제안과 매우 유사하지만 큐 이름을 인수로 제공 할 수 있습니다.

QueueDeclareOk result = channel.QueueDeclarePassive(queueName);
uint count = result != null ? result.MessageCount : 0;

업데이트 : Mmalone의 매우 유용한 게시물 이후 Queue_declare (..)의 Pika 구현이 변경된 것으로 보입니다.

Python/Pika (v0.9.5)에서는 여전히 Pika를 통해 큐 깊이를 확인할 수 있지만 약간 더 간접적 인 접근이 필요합니다.

queue_declare (...)는 메소드 객체를 콜백 함수로 전달한 다음 검사 할 수 있습니다. 예를 들어, 이름이 지정된 대기열의 메시지 수와 소비자 수를 확인합니다. 'myQueue':

def cbInspect(qb):
    messagesInQueue = qb.method.message_count
    print "There are %d messages in myQueue" % messagesInQueue

    consumersInQueue = qb.method.consumer_count
    print "There are %d consumers in myQueue" % consumersInQueue

    return

myChannel = channel.queue_declare(callback=cbInspect, queue='myQueue', passive=True)

이것이 도움이되기를 바랍니다.

여기에 문서화 된 Imodel의 MessageCount 메소드를 사용할 수 있습니다.

http://www.rabbitmq.com/releases/rabbitmq-dotnet-client/v3.6.4/rabbitmq-dotnet-3.6.4-client-htmldoc/html/type-rabbitmq.client.html#method- M : RabbitMq.client.Imodel.MessAgeCount (System.String)

편집 : 나는 이것이 매우 오래된 게시물이라는 것을 알고 있지만, 그것은 첫 번째 Google 응답이기 때문에 앞으로이 답변을 찾는 사람들이 도움이되기를 바랍니다.

myydrralls의 대답을 기반으로 한 작은 스 니펫. 그가 그의 대답에 코드를 가지고 있다면 훨씬 더 빨리 알았을 것입니다.

public uint GetMessageCount(string queueName)
{
    using (IConnection connection = factory.CreateConnection())
    using (IModel channel = connection.CreateModel())
    {
        return channel.MessageCount(queueName);
    }
}

적어도 RabbitMQ 3.3.5에서 RabbitMQ Management http API를 호출하여 RabbitMQ 클라이언트 라이브러리없이 C# 프로그램 에서이 작업을 수행 할 수 있습니다.

// The last segment of the URL is the RabbitMQ "virtual host name". 
// The default virtual host name is "/", represented urlEncoded by "%2F".
string queuesUrl = "http://MY_RABBITMQ_SERVER:15672/api/queues/%2F";

WebClient webClient = new WebClient { Credentials = new NetworkCredential("MY_RABBITMQ_USERNAME", "MY_RABBITMQ_PASSWORD") };
string response = webClient.DownloadString(queuesUrl);

사용자 이름과 암호는 RabbitMQ Management Console UI에 로그인하는 데 사용하는 것과 동일합니다.

응답은 메시지 수를 포함하여 큐 목록이있는 JSON 문자열입니다. (원한다면 라이브러리와 같은 라이브러리를 사용하여 JSON을 C# 객체로 사정 할 수 있습니다. json.net.)

API 문서는 RabbitMQ Management Console과 함께 설치되며 해당 서버에서 사용할 수 있어야합니다. http : // my_rabbitmq_server : 15672/api .

Python 프로그램에서 큐의 크기/깊이를 얻을 수있었습니다. 1. py_rabbit 사용

    from pyrabbit.api import Client
    cl = Client('10.111.123.54:15672', 'userid', 'password',5)
    depth = cl.get_queue_depth('vhost', 'queue_name')
  1. Kombu [Python 패키지는 일반적으로 셀러리 설치와 함께 제공
conn = kombu.Connection('amqp://userid:password@10.111.123.54:5672/vhost')
conn.connect()
client = conn.get_manager()
queues = client.get_queues('vhost')
for queue in queues:
    if queue == queue_name:
    print("tasks waiting in queue:"+str(queue.get("messages_ready")))
    print("tasks currently running:"+str(queue.get("messages_unacknowledged")))

IP 주소는 예입니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top