none
EventHub REST issue RRS feed

  • Question

  • I reported this issue...

    https://github.com/Azure/azure-event-hubs/issues/325

    a week ago, and there has been no response. This call...

    https://docs.microsoft.com/en-us/rest/api/eventhub/get-event-hub

    is returning an absolutely invalid response when passed a hub name that does not exist. Do I need to create a service ticket?

    Wednesday, July 26, 2017 6:57 PM

All replies

  • If the resource does not exist, API will return a 404.

    Check the below link on Create or update a new Event Hub as a nested resource within a Namespace and let us know.

    https://docs.microsoft.com/en-us/rest/api/eventhub/eventhubs#EventHubs_CreateOrUpdate

    ------------------------------------------------------------------------------------------------------------------

    Do click on "Mark as Answer" on the post that helps you, this can be beneficial to other community members.


    • Edited by Sheethal J S Thursday, July 27, 2017 4:27 AM
    • Proposed as answer by Sheethal J S Thursday, July 27, 2017 4:28 AM
    Thursday, July 27, 2017 4:27 AM
  • "If the resource does not exist, API will return a 404."

    That's the problem, it's not returning 404, it's returning 200. If I pass the following code a hub that exists, it returns the hub info. If I pass it a hub that doesn't exist, I get a 200 and this...

    "<title type="text">Publicly Listed Services</title>This is the list of publicly-listed services currently available.uuid:bac15d84-2363-40a9-a508-0c1a7edb9389;id=10782017-07-18T20:48:27ZService Bus 1.1"

            private static async Task<string> GetHubViaRESTAsync(string namespaceName, string keyName, string key, string hubName)
            {
                string sas = createToken($"https://{namespaceName}.servicebus.windows.net/{hubName}", keyName, key);
    
                using (HttpClient httpClient = new HttpClient())
                {
                    httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("SharedAccessSignature", sas);
    
                    Uri requestUri = new Uri($"https://{namespaceName}.servicebus.windows.net/{hubName}?timeout=60&api-version=2017-04");
    
                    httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Host", $"{namespaceName}.servicebus.windows.net");
    
                    HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, requestUri);
    
                    var response = await httpClient.SendAsync(message);
    
                    string responseContent = await response.Content.ReadAsStringAsync();
    
                    switch (response.StatusCode)
                    {
                        case HttpStatusCode.OK:
                            XDocument doc = XDocument.Parse(responseContent);
    
                            if(doc.Root.Name == "{http://www.w3.org/2005/Atom}entry")
                            {
                                return ParseHubEntry(doc.Root);
                            }
    
                            else
                            {
                                return null;
                            }
    
                        default:
                            throw new Exception(responseContent);
                    }
                }
            }
            private static string createToken(string resourceUri, string keyName, string key)
            {
                TimeSpan sinceEpoch = DateTime.UtcNow - new DateTime(1970, 1, 1);
                var week = 60 * 60 * 24 * 7;
                var expiry = Convert.ToString((int)sinceEpoch.TotalSeconds + week);
                string stringToSign = HttpUtility.UrlEncode(resourceUri) + "\n" + expiry;
                HMACSHA256 hmac = new HMACSHA256(Encoding.UTF8.GetBytes(key));
                var signature = Convert.ToBase64String(hmac.ComputeHash(Encoding.UTF8.GetBytes(stringToSign)));
                var sasToken = String.Format(CultureInfo.InvariantCulture, "sr={0}&sig={1}&se={2}&skn={3}", HttpUtility.UrlEncode(resourceUri), HttpUtility.UrlEncode(signature), expiry, keyName);
                return sasToken;
            }
    
            private static string ParseHubEntry(XElement entryElement)
            {
                string name = entryElement.Element("{http://www.w3.org/2005/Atom}title").Value;
    
                return name;
            }

    Thursday, July 27, 2017 6:44 AM
  • I was able to reproduce the issue. Thanks for pointing this. I will track this with the team.
    Tuesday, August 1, 2017 6:47 PM
  • Here is why it doesn't fail with 404. GET call to Service Bus with the URI is a "populate entities" call under given path. So, a GET call isn't always a read description for the given entity in the URI path.

    Please check the content type of the HTTP response. If content type is "feed" you should take it as "entity not exist" when looking for a particular EventHubs. If entity is located then content type will be "entry".

    Tuesday, August 1, 2017 7:11 PM
  • Hi Serkant,

    Please excuse my disgust, but seriously? If I were requesting a list of things, and got an empty collection back, that would be fine. In this case, I'm asking for a SPECIFIC RESOURCE. This isn't really a REST interface if I need to be looking at response headers to figure out if the resource actually exists. But ignoring all that, if you're going to expose a bizarro REST interface, fine. But in that case you've got to document the **** out of it, which clearly hasn't happened here. The fact that Sheethal ASSUMED it would return a 404 is proof that the API is somewhat flawed. This reflects EXTREMELY poorly on the EventHub team.

    As always, I appreciate you taking the time to investigate this issue. Thanks.

    Tuesday, August 1, 2017 7:48 PM
  • I agree this needs to be fixed. Service should be able to distinguish between get-description and populate calls. We are tracking the issue in the team. Btw, this is not related to EventHubs only. Same issue applies to queues/topics and relay as well.
    Wednesday, August 2, 2017 6:19 PM