0
votes

Only just noticed that over a year ago the "Registration Time to Live" was able to be increased from 90 days to forever. I want to configure live hubs to maximum, but it can't be edited in the portal, something has to be written to do it.

I use the hub rest APIs extensively in Powershell and there's a PUT API to Update Notification Hub;

https://{namespace}.servicebus.windows.net/{Notification Hub}?api-version=2015-01

Haven't used this particular API previously and can't seem to figure out exactly how to get it to work in Powershell (already sorted with the authorization token).

Is there anyone out there prepared to share a Powershell example showing the correct parameters, in particular the structure of the request body, to effect the RTL change on a notification hub..?

It's only a oncer, because new hubs are created with the default unlimited RTL.

Any help most appreciated. Cheers!

1

1 Answers

0
votes

Finally figured this out as below with a complete example string that updates the hub, in this case changing the "Time to Live" to 365 days. Hope others find this useful. Be aware that you must include all parameters are required in your hub, or they'll be blown away. Be especially careful to update with and keep your primary key for updates and access, otherwise you'll lock yourself out of your hub and have to manually update your key in the portal.

$RegURI = "https://mightyhubs.servicebus.windows.net/bing?api-version=2015-01";
$ContentType = "application/xml;type=entry;charset=utf-8"
Sub routine to create your $Token in here...

$HubUpdateString = @"
<?xml version="1.0" encoding="utf-8"?>
<entry
    xmlns="http://www.w3.org/2005/Atom">
    <content type="application/xml">
    <NotificationHubDescription
        xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
        <RegistrationTtl>P365D</RegistrationTtl>
        <AuthorizationRules>
            <AuthorizationRule i:type="SharedAccessAuthorizationRule">
                <ClaimType>SharedAccessKey</ClaimType>
                <ClaimValue>None</ClaimValue>
                <Rights>
                    <AccessRights>Listen</AccessRights>
                    <AccessRights>Manage</AccessRights>
                    <AccessRights>Send</AccessRights>
                </Rights>
                <KeyName>DefaultFullSharedAccessSignature</KeyName>
     <PrimaryKey>FULLKEY1232F94807DC72465F298CBE5201197CA40</PrimaryKey>
     <SecondaryKey>FULLKEY2232F94807DC72465F298CBE5201197CA40</SecondaryKey>
            </AuthorizationRule>
            <AuthorizationRule i:type="SharedAccessAuthorizationRule">
                <ClaimType>SharedAccessKey</ClaimType>
                <ClaimValue>None</ClaimValue>
                <Rights>
                    <AccessRights>Listen</AccessRights>
                </Rights>
                <KeyName>DefaultListenSharedAccessSignature</KeyName>
   <PrimaryKey>LISTENKEY1232F94807DC72465F298CBE5201197CA40</PrimaryKey>
   <SecondaryKey>LISTENKEY2232F94807DC72465F298CBE5201197CA40</SecondaryKey>
            </AuthorizationRule>
        </AuthorizationRules>
        <GcmCredential>
            <Properties>
                <Property>
                    <Name>googleApiKey</Name>
                    <Value>12345678910</Value>
                </Property>
            </Properties>
        </GcmCredential>
    </NotificationHubDescription>
    </content>
</entry>
"@

$encodedContent = [System.Text.Encoding]::UTF8.GetBytes($HubUpdateString);
$webRequest = [System.Net.WebRequest]::Create($RegURI);

$webRequest.Method = "Put";
$webRequest.ContentType = $ContentType;
$webRequest.ContentLength = $encodedContent.length;

$webRequest.Headers.Add("Authorization","$Token");
$webRequest.Headers.Add("x-ms-version", "2015-01");
$webRequest.Headers.Add("If-Match", “*”);

$requestStream = $webRequest.GetRequestStream();
$requestStream.Write($encodedContent, 0, $encodedContent.length);
$requestStream.Close();