Skip to content

Instantly share code, notes, and snippets.

@anderbakk
anderbakk / CachedTokenClient.cs
Created July 19, 2017 15:31
Caching TokenResponse from IdentityModel.Client.TokenClient
using System;
using System.Diagnostics;
using IdentityModel.Client;
namespace IfInsurance.Waypoint.Cached.Identity.TokenClient
{
public interface ICachedTokenClient
{
string GetToken(bool forceFreshToken = false);
}
@anderbakk
anderbakk / AzureServiceBusQueueMonitorFunction.cs
Last active July 20, 2017 19:09
Retrieve all Azure Service Bus queues and report the total number of active messages and dead letters. Read more here: http://www.anderbakk.com/simple-monitoring-of-azure-service-bus/
using System.Configuration;
using System.Threading.Tasks;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.ServiceBus;
namespace FunctionApp
{
public static async Task ResendDeadLetters(string servicebusConnectionString, string queueName)
{
var messageFactory = MessagingFactory.CreateFromConnectionString(servicebusConnectionString);
var deadletterReceiver = await messageFactory.CreateMessageReceiverAsync(QueueClient.FormatDeadLetterPath(queueName),
ReceiveMode.PeekLock);
var sender = await messageFactory.CreateMessageSenderAsync(queueName);
const int max = 100;
var current = 0;
//Run until the Dead Letter Queue is empty or take the max number of messages