Skip to content

Instantly share code, notes, and snippets.

@ankitvijay
Last active September 22, 2019 05:42
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 ankitvijay/684e078d745dfbdab56a3d5df7104090 to your computer and use it in GitHub Desktop.
Save ankitvijay/684e078d745dfbdab56a3d5df7104090 to your computer and use it in GitHub Desktop.
TimerTriggerAzureFunction- Modified
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
namespace DemoNServiceBusSubscriberAndAzureFunctionPublisher
{
public static class TimerTriggerAzureFunction
{
[FunctionName("QueueMessageToWorker")]
public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer,
[ServiceBus("%AzureServiceBusQueue%", Connection = "AzureServiceBusConnectionString")]
ICollector<string> collectors,
ILogger log)
{
collectors.Add(Serialize(new ExecuteSomeCommand(Guid.NewGuid().ToString())));
}
private static string Serialize(ExecuteSomeCommand command)
{
return JsonConvert.SerializeObject(command, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.All
});
}
}
public class ExecuteSomeCommand
{
public ExecuteSomeCommand(string id)
{
Id = id;
}
public string Id { get; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment