Azure ServiceBus REST API total messages in a queue - azure

I have been following the Azure Service Bus REST API documentation located at https://learn.microsoft.com/en-us/rest/api/servicebus/
I'm required to know the total number of messages in a queue before reading the first message. However, I cannot see a request/command to simply get the total/count number of messages in a given queue.
Is this not possible via the REST API and only available to SDK?
Thanks

You can certainly get this information through REST API. In fact, there are two different REST APIs using which you can get this information.
Using Azure Resource Manager REST API - It is newer and recommended way to work with Service Bus Namespaces. The operation you would want to perform is Queues - Get. The response body will contain the details about the messages count. This API would require you to get an Azure AD access token which is then used for authorization.
Using Old REST API - Though not recommended but you can use old Service Bus REST API to get the information. The operation you would to perform is Get Entity. This API would require you to use your Service Bus Namespace's shared access key for authorization.
Having said this, it is still recommended that you use the SDKs instead of consuming the REST API directly as SDKs are simply wrapper over REST APIs.

Yes you can you need to access it via the management API, more specifically this https://www.nuget.org/packages/Microsoft.Azure.Management.ServiceBus.Fluent/
Here is a great link explaining exactly how to use that package and get the counters you are after
https://www.florinciubotariu.com/retrieving-number-of-messages-in-service-bus-in-net-core/

Related

Azure APIM as forward proxy

I am looking for some design guidance in using Azure APIM as a forward proxy between backend services (such as function apps or logic apps) and external clients.
We have a function app that processes invoice requests (for an order previously placed) from a mainframe system, does some transformations and sends them to an external party via HTTP. I have two options with the sending process.
Store external HTTP endpoint as an app setting in function app and let function app send the
transformed message directly to external party.
Send the transformed message to Azure APIM with the external HTTP endpoint set as the backend service (using set-backend-service APIM policy) and let APIM forward it to external party.
Now, are there are any real benefits with the second approach if the requirement is only to forward requests to external party from a security or operational standpoint? There are no requirements to enrich the outgoing message (add or remove headers, modify message body etc).
Personally, all I see is an extra hop with the second approach. But some of my teammates seem to think the second approach can offer some benefits in the way of analytics. There are some metrics available under APIM --> Analytics tab that lets you see the number of successful, failed requests etc. But I think this information is also available to Application Insights tied to the function app.
Just interested to see some insights around this so we can make an informed decision.
I guess using Azure API Management would be an over-engineering in your case, assuming the Azure Function is only going to be the caller of the Azure API Management instance.
Even though Azure API management provides analytics, url-rewrites, transformations, analytics etc - it makes more sense when you use it to govern the API. Ask yourself a question on, how many of the Azure API management functionalities are going to be leveraged fully in your case.
Remember Azure API management by design is an API governance tool where you can perform throttling, monetizing your API by giving access to it to different 3rd party with segregated subscription keys. In my opinion, Azure API management comes into the scene where you need to distribute some API to 3rd party applications, which clearly not in your case.

Azure REST Service Cost

Is there any cost associated in sending API calls to the service endpoints mentioned at the following URL: https://learn.microsoft.com/en-us/rest/api/azure/ provided by Azure using Postman?
No, there's no cost associated with calling these APIs (at least API calls to manage Azure Resources Control Plane). However, please keep in mind that there's a limit on how many API calls you can make. You can read more about those limits here: https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-request-limits.

how can i detect and get email notification of traffic in azure api management

i have question regarding Azure API Management again : ).
i am using API management which is API Gateway doing HTTPS to Azure Storage REST API directly
and is there any way that i cant get email notification when there are massive requests or high latency at response ??
Thanx for reading : )
You can configure alert notifications either in the portal or via the REST API or .NET SDK to monitor for specific Azure Storage Metrics that you want.
See https://azure.microsoft.com/en-us/documentation/articles/insights-receive-alert-notifications/ for more details.
For massive requests, you might want to consider using "TotalRequests" or "TotalBillableRequests" in a specific time period.
For high response latency, you can track "AverageE2ELatency" or "AverageServerLatency" in a specific time period.
See https://azure.microsoft.com/en-us/documentation/articles/storage-monitoring-diagnosing-troubleshooting/#monitoring-performance for more details on these specific metrics and how they relate to performance monitoring.
Hope this helps.
Sriprasad's answer makes sense for configuration from the Storage side. From the API Management side, you cannot currently set a notification on any event other than the built-in ones (subscription requests, new subscriptions, application gallery requests, new issues/comments, approaching of user subscription quota limit).
You can use Log-To-Eventhub policy to log a message to event hub for every request and consume it in a custom or third party solution like AppInsights/Runscopee to fire an alert.
Refer
https://azure.microsoft.com/en-us/documentation/articles/api-management-log-to-eventhub-sample/
If your requirement is to get report/metrics from API Management you can use the management rest api's for APIM.
https://msdn.microsoft.com/en-us/library/dn781421.aspx
Specifically you might want to look at reportByAPI (which gives you useful metrics in response like callcounts, apiTimeAvg) based on which you can setup alerts/email notification.
https://msdn.microsoft.com/en-us/library/dn781421.aspx#ReportByAPI

Azure Api Management Join Payloads and to provide customer

I have a question about the use of the Azure Management Api. The architecture of the single responssabilidade Api predicts domain to perform the functions of the business area. See image structure.
enter image description here
1. I wonder if the Azure Api Management operates as a management or I have the possibility of using it as a Geteway add results of many APIs in one (
orchestrating) and available to the client that made the request?
2. The responsability to gather this data is the Web Application?
3. Is there a pattern?
Azure API management can do both, it started as a management tool, but has received some updates so it can act as a gateway as well.
Read about the different API managment policies you can create here: https://azure.microsoft.com/en-us/documentation/articles/api-management-policy-reference/
Or take a look at the advanced policies, with the control flow and the send request
https://msdn.microsoft.com/library/azure/dn894085.aspx
For an example of sending requests to gather information from multiple sources see this:
https://azure.microsoft.com/nl-nl/documentation/articles/api-management-sample-send-request/

How do I dead-letter a message with the Azure Service Bus HTTP API

I'm trying to integrate with the Azure Service Bus to perform brokered messaging. I've used the managed .NET API successfully before, but this time I need to use the HTTP API.
When processing a message, if I determine that a message is poisonous (i.e. it can never be processed successfully), I want to move the message to the dead-letter queue.
In the managed API, I'd call BrokeredMessage.DeadLetterAsync() which lets me specify the reasons for dead-lettering the message and moves it to the dead-letter queue as an atomic operation.
Having been reading through the HTTP API documentation, I've found and invoked operations to perform the other actions, such as peek-lock, delete a locked message or abandon a lock, but I can't find an explicit operation to dead-letter a message.
Does this operation exist in the HTTP API?
DeadLetter operation today is not supported thru the http/rest API. We will add that support in an upcoming release. When the max delivery count for any message is reached and it is still not completed then it will be automatically deadlettered if that is enabled for the queue/subscription. The connectivity mode mentioned above is for the .NET API where the SBMP service bus protocol is tunneled over a http/port80 connection so it is not using REST APIs for that.
Even though I did not find any documentation for it, you can access dead letter messages via:
https://{servicebusnamespace}/{topic}/subscriptions/{subscriptionname}/$deadletterqueue/messages/head
I took a look at the REST Api Reference too and I could not find a way. There's a comparative table that shows features that are available through REST Api and features available through .NET SDK.
http://msdn.microsoft.com/en-us/library/windowsazure/hh780771.aspx
It sounds strange for me because I thought that .NET SDK calls a REST API Resource.
I believe that you must apply Peek-Lock on a message and after the processing, delete it.
Peek-lock message:
http://msdn.microsoft.com/en-us/library/windowsazure/hh780735.aspx
Delete:
http://msdn.microsoft.com/en-us/library/windowsazure/hh780768.aspx

Resources