Skip to content

Instantly share code, notes, and snippets.

@paulbatum
Created October 11, 2017 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulbatum/5909ff45271c71f3fa9f50c1b14a17c8 to your computer and use it in GitHub Desktop.
Save paulbatum/5909ff45271c71f3fa9f50c1b14a17c8 to your computer and use it in GitHub Desktop.
Setting PartitionKey in Azure Functions
#r "Microsoft.ServiceBus"
using System;
using System.Text;
using Microsoft.ServiceBus.Messaging;
public static void Run(EventData myEventHubMessage, TraceWriter log)
{
log.Info($"C# Event Hub trigger function processed a message with partition key: {myEventHubMessage.PartitionKey}");
}
2017-10-11T21:00:17 Welcome, you are now connected to log-streaming service.
2017-10-11T21:00:20.041 Function started (Id=1181022f-fb8b-443e-b832-d7352b1f0f5c)
2017-10-11T21:00:20.041 C# Event Hub trigger function processed a message with partition key: abc123
2017-10-11T21:00:20.041 Function completed (Success, Id=1181022f-fb8b-443e-b832-d7352b1f0f5c, Duration=0ms)
2017-10-11T21:00:25.011 Function started (Id=4fbc39a0-ad66-449b-bbf5-b5760ec2685e)
2017-10-11T21:00:25.011 C# Event Hub trigger function processed a message with partition key: abc123
2017-10-11T21:00:25.011 Function completed (Success, Id=4fbc39a0-ad66-449b-bbf5-b5760ec2685e, Duration=0ms)
2017-10-11T21:00:30.030 Function started (Id=7479be7e-ccb5-4060-a936-79bb7c7f8e31)
2017-10-11T21:00:30.030 C# Event Hub trigger function processed a message with partition key: abc123
2017-10-11T21:00:30.030 Function completed (Success, Id=7479be7e-ccb5-4060-a936-79bb7c7f8e31, Duration=0ms)
#r "Microsoft.ServiceBus"
using System;
using System.Text;
using Microsoft.ServiceBus.Messaging;
public static void Run(TimerInfo myTimer, TraceWriter log, ICollector<EventData> output)
{
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
var data = new EventData(Encoding.UTF8.GetBytes("Testing"));
data.PartitionKey = "abc123";
output.Add(data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment