2017-05-10 14 views
1

カウント取得キューからのカウントを取得する古い方法は、このようなものだった。もはや私は良いを見つけることではないのですAMQP 1.0.NetCore AzureのServicebusは、現在のメッセージが

で.netCoreで動作します。この

CloudQueue q = queueClient.GetQueueReference(QUEUE_NAME); 
      q.FetchAttributes(); 
      qCnt = q.ApproximateMessageCount; 

メッセージ数を得る方法。私が逃しているものについてのアイデアは何ですか?

+0

これは、Azureのサービスを見ていませんバスコードスニペットではなく、ストレージキュー。 –

+0

確かに、ServiceBusのQueueにあるアイテムの数を取得するための同等の機能は何ですか? – w2olves

+0

Google "azure service bus queue get message count"と文字通り、最初の結果はあなたの質問に対する答えです:D http://stackoverflow.com/questions/16254951/determining-how-many-messages-are-on- the-azure-service-bus-queue –

答えて

2

プレビューバージョンであるMicrosoft.Azure.Management.ServiceBus Libaryがあり、100%互換性があります.Netcore。ここではdetailをもっと得ることができます。

Preparetion:

Registry Azure Active Directory application and assign Role

ステップ:

.NETのコアコンソールプロジェクトを作成し、次のコードを追加します。アズールporatalから

var tenantId = "tenantid"; 
      var context = new AuthenticationContext($"https://login.windows.net/{tenantId}"); 
      var clientId = "Client"; 
      var clientSecret = "Secret"; 
      var subscriptionId = "subscriptionId"; 
      var result = context.AcquireTokenAsync(
       "https://management.core.windows.net/", 
       new ClientCredential(clientId, clientSecret)).Result; 

      var creds = new TokenCredentials(result.AccessToken); 
      var sbClient = new ServiceBusManagementClient(creds) 
      { 
       SubscriptionId = subscriptionId 
      }; 
      var queueParams = new QueueCreateOrUpdateParameters() 
      { 
       Location = "East Asia", 
       EnablePartitioning = true 
      }; 

      var queue = sbClient.Queues.ListAll("groupname", "namespace").ToList().FirstOrDefault(x => x.Name.Equals("queuename")); 
      var messagecount = queue.MessageCount; 

enter image description here

、我々は、キュー内のメッセージを確認

enter image description here

Project.jsonファイル:

{ 
    "version": "1.0.0-*", 
    "buildOptions": { 
    "emitEntryPoint": true 
    }, 

    "dependencies": { 
    "Microsoft.Azure.Management.ServiceBus": "0.2.0-preview", 
    "Microsoft.IdentityModel.Clients.ActiveDirectory": "3.13.9", 
    "Microsoft.NETCore.App": { 
     "type": "platform", 
     "version": "1.0.1" 
    } 
    }, 

    "frameworks": { 
    "netcoreapp1.0": { 
     "imports": "dnxcore50" 
    } 
    } 
} 
+0

上記は機能しました。これに遭遇する他の誰かのために、groupnameはあなたのResourcegroup名であり、NameSpaceはQueue Namespaceです。 – w2olves

+0

私はこのようなメッセージをキューに送ります。 queueClient = new QueueClient(ServiceBusConnectionString、QueueName、ReceiveMode.PeekLock); //新しい中継メッセージを作成してキューに送信する var message = new Message($ "Message {precheckMessage}"); //メッセージをキューに送信 await queueClient.SendAsync(message); メッセージをプッシュするときにQueueIDを取得する簡単な方法はありますか?文脈のように? – w2olves

+0

上記のコードを使用している場合は、queueidを簡単に取得することができます。var queue = sbClient.Queues.ListAll( "groupname"、 "namespace")ToList()。FirstOrDefault(x => x.Name.Equals( "queuename")) ; '' var id = queue.id'とすると、**/subscriptions/subscriptionId/resourceGroups/resource groupname/providers/Microsoft.ServiceBus/namespaces/servicebusname/queues/queuenameというキューIDを取得できます。 –

関連する問題