Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Receive MessageCountDetails for a Subscription #1001

Open
Shaked opened this issue Nov 10, 2019 · 2 comments
Open

Receive MessageCountDetails for a Subscription #1001

Shaked opened this issue Nov 10, 2019 · 2 comments

Comments

@Shaked
Copy link

Shaked commented Nov 10, 2019

Hello,

I'm interested in receiving the MessageCountDetails from your API, as I see that it is possible to do by using the C# SDK)

Basically I'm trying to get the total count of dead letters per subscription.

AFAIU this should be possible: https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-dead-letter-queues#path-to-the-dead-letter-queue

Path to the dead-letter queue
You can access the dead-letter queue by using the following syntax:
/$deadletterqueue
/Subscriptions//$deadletterqueue
If you are using the .NET SDK, you can get the path to the dead-letter queue by using the SubscriptionClient.FormatDeadLetterPath() method. This method takes the topic name/subscription name and suffixes with /$DeadLetterQueue.

However, I could not figure how to get it using the PHP API.

Even when I manually edited the subscription path:

    public function getSubscription($topicPath, $subscriptionName) {
        $httpCallContext = new HttpCallContext();
        $httpCallContext->setMethod(Resources::HTTP_GET);
        $httpCallContext->addStatusCode(Resources::STATUS_OK);
        $subscriptionPath = sprintf(
            Resources::SUBSCRIPTION_PATH . '/$DeadLetterQueue/',
            $topicPath,
            $subscriptionName
        );
        $httpCallContext->setPath($subscriptionPath);
        $response = $this->sendHttpContext($httpCallContext);
        var_dump((string) $response->getBody());die;
        $subscriptionInfo = new SubscriptionInfo();
        $subscriptionInfo->parseXml($response->getBody());

        return $subscriptionInfo;
    }

I ended up with this message:

Bad Request\ndetails (if any): 400The specified HTTP verb (GET) is not valid. To know more visit https://aka.ms/sbResourceMgrExceptions. . TrackingId:9a2587c8-a409-4bdf-bbee-37ae63107c81_G9, SystemTracker:stage-green-eye:Topic:main, Timestamp:2019-11-10T23:43:40.","file":"/private/var/projects/annotation-tool/vendor/microsoft/windowsazure/src/Common/Internal/Http/HttpClient.php","line":405,"0":"WindowsAzure\Common\Internal\Http\HttpClient:throwIfError:301\n","1":"WindowsAzure\Common\Internal\Http\HttpClient:sendAndGetHttpResponse:144\n","2":"WindowsAzure\Common\Internal\RestProxy:sendHttpContext:85\n","3":"WindowsAzure\Common\Internal\ServiceRestProxy:sendHttpContext:709\n","4":"WindowsAzure\ServiceBus\ServiceBusRestProxy:getSubscription:186\n

What can I do in order to get this information?

Thank you
Shaked

@Shaked
Copy link
Author

Shaked commented Nov 11, 2019

After contacting Azure's support, it seems like that the PHP SDK is not updated and is not using the latest API version.

The ideal solution should be something like:

ServiceBusRestProxy.php

  public function getSubscription($topicPath, $subscriptionName) {
        $httpCallContext = new HttpCallContext();
        $httpCallContext->setMethod(Resources::HTTP_GET);
        $httpCallContext->addStatusCode(Resources::STATUS_OK);
        $subscriptionPath = sprintf(
            Resources::SUBSCRIPTION_PATH,
            $topicPath,
            $subscriptionName
        );
        $httpCallContext->setPath($subscriptionPath);
        $httpCallContext->setQueryParameters([
+            'api-version' => '2017-04',
        ]);
        $response = $this->sendHttpContext($httpCallContext);

Which will end up with a larger XML response:

<entry xmlns="http://www.w3.org/2005/Atom"><id>sb://xyz-test.servicebus.windows.net/main/subscriptions/the_tool?api-version=2017-04</id><title type="text">the_tool</title><published>2019-06-18T13:34:15Z</published><updated>2019-07-01T11:20:55Z</updated><link rel="self" href="sb://xyz-test.servicebus.windows.net/main/subscriptions/the_tool?api-version=2017-04"/><content type="application/xml"><SubscriptionDescription xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><LockDuration>PT5M</LockDuration><RequiresSession>false</RequiresSession><DefaultMessageTimeToLive>P10675199DT2H48M5.477S</DefaultMessageTimeToLive><DeadLetteringOnMessageExpiration>false</DeadLetteringOnMessageExpiration><DeadLetteringOnFilterEvaluationExceptions>true</DeadLetteringOnFilterEvaluationExceptions><MessageCount>0</MessageCount><MaxDeliveryCount>10</MaxDeliveryCount><EnableBatchedOperations>true</EnableBatchedOperations><Status>Active</Status><CreatedAt>2019-06-18T13:34:15.9898145Z</CreatedAt><UpdatedAt>2019-07-01T11:20:55.4441927Z</UpdatedAt><AccessedAt>2019-11-11T14:57:09.1763185Z</AccessedAt><CountDetails xmlns:d3p1="http://schemas.microsoft.com/netservices/2011/06/servicebus"><d3p1:ActiveMessageCount>0</d3p1:ActiveMessageCount><d3p1:DeadLetterMessageCount>0</d3p1:DeadLetterMessageCount><d3p1:ScheduledMessageCount>0</d3p1:ScheduledMessageCount><d3p1:TransferMessageCount>0</d3p1:TransferMessageCount><d3p1:TransferDeadLetterMessageCount>0</d3p1:TransferDeadLetterMessageCount></CountDetails><AutoDeleteOnIdle>P10675199DT2H48M5.4775807S</AutoDeleteOnIdle><EntityAvailabilityStatus>Available</EntityAvailabilityStatus></SubscriptionDescription></content></entry>

Are you guys planning to upgrade this SDK at some point?

Thank you
Shaked

EDIT:

I have started to work on a solution: master...Shaked:master (which I'm currently using).

However, I doubt I will have the time to follow this repository's guidelines, as it is way too complex and time consuming. Would have been nice to have an automated docker image for that part with a single entry point.

@Shaked
Copy link
Author

Shaked commented Nov 24, 2019

Hello @sergey-shandar ,

Is this repository still under maintenance/development?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant