programing

Azure 서비스 버스 큐에 있는 메시지 수 확인

elecom 2023. 4. 23. 10:05
반응형

Azure 서비스 버스 큐에 있는 메시지 수 확인

Azure Queue(Store Account)에는 메시지 수(또는 대략적인 수)를 판별하는 방법이 있습니다만, Azure Service Bus 큐에서 보류 중인 메시지 수를 조회하는 방법이 있습니까?

var nsmgr = Microsoft.ServiceBus.NamespaceManager.CreateFromConnectionString(connectionString);
long count = nsmgr.GetQueue(queueName).MessageCount;

이것은 Messages Count Details라고 불립니다.Active Message Count.큐내의 액티브메시지 수를 반환합니다.데드 레터 메시지가 몇 개 있을 수 있습니다.

var msg = Microsoft.ServiceBus.NamespaceManager.CreateFromConnectionString(Settings.Default.ConnectionString);
numofmessages.Text = msg.GetQueue(QueueName).MessageCountDetails.ActiveMessageCount.ToString();

2020년 기준 정답+

새로운 패키지의 사용법은 다음과 같습니다.

<PackageReference Include="Azure.Messaging.ServiceBus" Version="x.x.x" />

또한 동일한 패키지에 두 개의 네임스페이스가 있습니다.

using Azure.Messaging.ServiceBus;
using Azure.Messaging.ServiceBus.Administration;

그런 다음 새 클래스 ServiceBus AdministrationClient를 사용할 수 있습니다.

var administrationClient = new ServiceBusAdministrationClient("connectionString");
var props = await administrationClient.GetQueueRuntimePropertiesAsync("queue");
var messageCount = props.Value.ActiveMessageCount;

Queue Description API를 살펴보셨습니까?'그냥'이라는 게 있어요MessageCount.

여기 가 있습니다.NET SDK 레퍼런스 매뉴얼 페이지도 참조할 수 있습니다.

조셉이 가지고 있던 답을 바탕으로 토픽과 구독에 대해 생각해 냈습니다.

public async Task<long> GetCounterMessages()
        {
            var client = new ManagementClient(ServiceBusConnectionString);    
            var subs = await client.GetSubscriptionRuntimeInfoAsync(TopicName, SubscriptionName);
            var countForThisSubscription = subs.MessageCount;  //// (Comes back as a Long.)               
            return countForThisSubscription;
        }

죽은 편지 줄에서 숫자를 알아내려다 같은 문제에 부딪혔어요.데드레터 큐에서는 카운트를 직접 취득할 수 없는 것 같습니다.일반 큐의 Message Count Details에서 카운트를 가져옵니다.

string connectionString = ConfigurationManager.AppSettings["Microsoft.ServiceBus.Connstr"].ToString();
NamespaceManager nsmgr = Microsoft.ServiceBus.NamespaceManager.CreateFromConnectionString(connectionString);
return nsmgr.GetQueue(QueueName).MessageCountDetails.DeadLetterMessageCount;

다음은 Azure Portal Cloud Shell에서 사용되는 큐 길이를 지속적으로 주시하는 PowerShell의 예입니다.

cd "Azure:\<MySubscription>\"
while (1) {(Get-AzureRmServiceBusQueue -ResourceGroup <myRG> -NamespaceName <myNS> -QueueName <myQueueName>).CountDetails | Select -expand ActiveMessageCount}

.net core 와 Microsoft 를 사용하고 있는 유저에게, 그것을 입수하기 위해서, 2시간이나 문서를 조사했습니다.Azure.ServiceBus nuget 패키지, 코드는 다음과 같습니다.

var managementClient = new ManagementClient("queue connection string"));
var runtimeInfo = await managementClient.GetQueueRuntimeInfoAsync("queueName");

var messagesInQueueCount = runtimeInfo.MessageCountDetails.ActiveMessageCount;

즉시 QueueRuntime에서 모든 카운트(데드레터, 액티브 등)에 대한 정보를 얻을 수 있습니다.이전 QueueDescription 개체 대신 Info 개체.

Microsoft 의 권장 사항에 따라서, Microsoft 를 사용하는 것을 추천합니다.Azure.ServiceBus를 사용하면 메시지 수를 쉽게 가져올 수 있습니다.

var managementClient = new ManagementClient("connection string for queue");
var queue = await managementClient.GetQueueRuntimeInfoAsync("queue name");
var messages = queue.MessageCount;

또한 Azure Management Portal에서 보류 중인 메시지를 대시보드에서 확인할 수 있습니다. 서비스 버스 대기열...잽싸게 훑어보면서...큐 길이를 확인할 수 있습니다.대시보드 페이지 로드 시 길이의 현재 메시지 또는 메시지 수입니다.

언급URL : https://stackoverflow.com/questions/16254951/determining-how-many-messages-are-on-the-azure-service-bus-queue

반응형