Azure / azure-notificationhubs-dotnet

.NET SDK for Azure Notification Hubs
MIT License
70 stars 122 forks source link

Handle DNS changes #107

Closed PeterOscarsson closed 4 years ago

PeterOscarsson commented 4 years ago

I use the NotificationHubClient as a Singleton in my long-running service. (> 1 month) When the DNS (IP) for the HUB changes (a few times per year) this is not reflected in the singleton NotificationHubClient (due to "new HttpClient()") and I'll get exceptions in my code and have to restart the whole service to reflect the DNS change.

What is the correct way to solve this in code right now and is there any plans to use the IHttpClientFactory to create the HttpClient instead, which also should solve the problem.

nesterenko-kv commented 4 years ago

@marstr I can take care of this. This can be solved by constructor overload which takes HttpClient.

stankovski commented 4 years ago

It is actually possible today. Constructor accepts an instance of NotificationHubClientSettings which has a property MessageHandler. If that property is set, HttpClient will use that handler. https://github.com/Azure/azure-notificationhubs-dotnet/blob/master/src/Microsoft.Azure.NotificationHubs/NotificationHubClient.cs#L78