Skip to content

Instantly share code, notes, and snippets.

@xximjasonxx
Created May 9, 2020 01:11
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 xximjasonxx/de022b115d4e7893dc70660862621416 to your computer and use it in GitHub Desktop.
Save xximjasonxx/de022b115d4e7893dc70660862621416 to your computer and use it in GitHub Desktop.
[FunctionName("GenerateNamesTimerFunction")]
[return: ServiceBus("newnames-queue", Connection = "ServiceBusConnection")]
public static async Task<string> RunTrigger(
[TimerTrigger("*/3 * * * * *")]TimerInfo myTimer,
[EventHub("names", Connection = "EventHubSendConnection")] IAsyncCollector<string> outputEvents,
ILogger log
)
{
var names = await GetNames();
foreach (var nameRecord in names)
{
await outputEvents.AddAsync(nameRecord.ToString());
}
return (new JObject(
new JProperty("id", Guid.NewGuid().ToString()),
new JProperty("data", names.Select(name => new JObject(
new JProperty("name", name)
)))
)).ToString();
}
[FunctionName("DequeueGeneratedNames")]
[return: Blob("raw-names/{id}.txt", FileAccess.Write, Connection = "AzureWebJobsStorage")]
public static string Run(
[ServiceBusTrigger("newnames-queue", Connection = "ServiceBusConnection")]NamesGenerationRecord msg,
ILogger log)
{
return msg.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment