forked from Azure/azure-sdk-for-net
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Storage] Webjobs extension sample apps. (Azure#18358)
* nest sample tests? * queues sample app. * nesting. * new link. * blobs sample. * fix build. * fix build. * does this fix the build ?
- Loading branch information
1 parent
d59d904
commit 2d0be7b
Showing
19 changed files
with
241 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
sdk/storage/Microsoft.Azure.WebJobs.Extensions.Storage.Blobs/samples/Directory.Build.props
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<!-- Signal that samples are building in the repo as opposed to a standalone download from Samples Browser --> | ||
<IsSamplesProject>true</IsSamplesProject> | ||
<IsPackable>false</IsPackable> | ||
<ExcludeFromCodeCoverage>true</ExcludeFromCodeCoverage> | ||
<WarnOnPackingNonPackableProject>false</WarnOnPackingNonPackableProject> | ||
</PropertyGroup> | ||
|
||
<Import Project="..\..\Directory.Build.props" /> | ||
|
||
<PropertyGroup> | ||
<InheritDocEnabled>false</InheritDocEnabled> | ||
</PropertyGroup> | ||
</Project> |
21 changes: 21 additions & 0 deletions
21
.../functionapp/Microsoft.Azure.WebJobs.Extensions.Storage.Blobs.Samples.Function.App.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<RequiredTargetFrameworks>netcoreapp3.1</RequiredTargetFrameworks> | ||
<TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks> | ||
<AzureFunctionsVersion>v3</AzureFunctionsVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Microsoft.Azure.WebJobs.Extensions.Storage.Blobs.csproj" /> | ||
<PackageReference Include="Microsoft.NET.Sdk.Functions" VersionOverride="3.0.9" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Update="host.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="local.settings.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
<CopyToPublishDirectory>Never</CopyToPublishDirectory> | ||
</None> | ||
</ItemGroup> | ||
</Project> |
6 changes: 6 additions & 0 deletions
6
.../Microsoft.Azure.WebJobs.Extensions.Storage.Blobs/samples/functionapp/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Sample Azure Function App for Azure Azure WebJobs Storage Blobs | ||
|
||
This sample Azure Function application shows usage of Azure Azure WebJobs Storage Blobs extension. | ||
`SampleFunctions` contains a pair of functions that work with an Azure Storage Blobs | ||
as well as sample configuration files `host.json` and `local.settings.json`. Settings present in `host.json` are optional and used values can be different than defaults. | ||
Connection string present in `local.settings.json` points to [Azurite](https://github.com/Azure/Azurite), however any valid connection string will work. |
40 changes: 40 additions & 0 deletions
40
...e/Microsoft.Azure.WebJobs.Extensions.Storage.Blobs/samples/functionapp/SampleFunctions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.Azure.WebJobs.Extensions.Storage.Blobs.Samples.Function.App | ||
{ | ||
/// <summary> | ||
/// A pair of sample functions. First that updates a blob on schedule and second that listens to blob changes. | ||
/// </summary> | ||
public static class SampleFunctions | ||
{ | ||
/// <summary> | ||
/// This function executes on schedule, produces a new content and udpates the blob. | ||
/// </summary> | ||
[FunctionName("SampleBlobContentUpdater")] | ||
[return: Blob("sample-container/sample-blob")] | ||
public static string UpdateSampleBlobContent([TimerTrigger("*/30 * * * * *")] TimerInfo timerInfo, ILogger logger) | ||
{ | ||
if (timerInfo.IsPastDue) | ||
{ | ||
logger.LogInformation("Timer is running late!"); | ||
} | ||
var now = DateTime.Now; | ||
logger.LogInformation($"C# Timer trigger function executed at: {now}"); | ||
|
||
return $"Sample blob content produced at: {now}"; | ||
} | ||
|
||
/// <summary> | ||
/// This functions is executed when blob is modified. | ||
/// </summary> | ||
[FunctionName("SampleBlobUpdateListener")] | ||
public static void OnBlobUpdate([BlobTrigger("sample-container/sample-blob")] string content, ILogger logger) | ||
{ | ||
logger.LogInformation("Blob has been updated, content: {content}", content); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
sdk/storage/Microsoft.Azure.WebJobs.Extensions.Storage.Blobs/samples/functionapp/host.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"version": "2.0", | ||
"logging": { | ||
"applicationInsights": { | ||
"samplingExcludedTypes": "Request", | ||
"samplingSettings": { | ||
"isEnabled": true | ||
} | ||
} | ||
}, | ||
"extensions": { | ||
"blobs": { | ||
"maxDegreeOfParallelism": "5" | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
.../Microsoft.Azure.WebJobs.Extensions.Storage.Blobs/samples/functionapp/local.settings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"IsEncrypted": false, | ||
"Values": { | ||
"AzureWebJobsStorage": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;", | ||
"FUNCTIONS_WORKER_RUNTIME": "dotnet" | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
sdk/storage/Microsoft.Azure.WebJobs.Extensions.Storage.Queues/samples/Directory.Build.props
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<!-- Signal that samples are building in the repo as opposed to a standalone download from Samples Browser --> | ||
<IsSamplesProject>true</IsSamplesProject> | ||
<IsPackable>false</IsPackable> | ||
<ExcludeFromCodeCoverage>true</ExcludeFromCodeCoverage> | ||
<WarnOnPackingNonPackableProject>false</WarnOnPackingNonPackableProject> | ||
</PropertyGroup> | ||
|
||
<Import Project="..\..\Directory.Build.props" /> | ||
|
||
<PropertyGroup> | ||
<InheritDocEnabled>false</InheritDocEnabled> | ||
</PropertyGroup> | ||
</Project> |
21 changes: 21 additions & 0 deletions
21
...functionapp/Microsoft.Azure.WebJobs.Extensions.Storage.Queues.Samples.Function.App.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<RequiredTargetFrameworks>netcoreapp3.1</RequiredTargetFrameworks> | ||
<TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks> | ||
<AzureFunctionsVersion>v3</AzureFunctionsVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Microsoft.Azure.WebJobs.Extensions.Storage.Queues.csproj" /> | ||
<PackageReference Include="Microsoft.NET.Sdk.Functions" VersionOverride="3.0.9" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Update="host.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="local.settings.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
<CopyToPublishDirectory>Never</CopyToPublishDirectory> | ||
</None> | ||
</ItemGroup> | ||
</Project> |
6 changes: 6 additions & 0 deletions
6
...Microsoft.Azure.WebJobs.Extensions.Storage.Queues/samples/functionapp/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Sample Azure Function App for Azure Azure WebJobs Storage Queues | ||
|
||
This sample Azure Function application shows usage of Azure Azure WebJobs Storage Queues extension. | ||
`SampleFunctions` contains a pair of producer and consumer that work with an Azure Storage Queue | ||
as well as sample configuration files `host.json` and `local.settings.json`. Settings present in `host.json` are optional and used values can be different than defaults. | ||
Connection string present in `local.settings.json` points to [Azurite](https://github.com/Azure/Azurite), however any valid connection string will work. |
40 changes: 40 additions & 0 deletions
40
.../Microsoft.Azure.WebJobs.Extensions.Storage.Queues/samples/functionapp/SampleFunctions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.Azure.WebJobs.Extensions.Storage.Queues.Samples.Function.App | ||
{ | ||
/// <summary> | ||
/// A pair of sample functions. First that produces messages on schedule and second that consumes them. | ||
/// </summary> | ||
public static class SampleFunctions | ||
{ | ||
/// <summary> | ||
/// This function executes on schedule, produces a message and inserts it into the queue. | ||
/// </summary> | ||
[FunctionName("SampleQueueMessageProducer")] | ||
[return: Queue("sample-queue")] | ||
public static string ProduceSampleQueueMessage([TimerTrigger("*/10 * * * * *")] TimerInfo timerInfo, ILogger logger) | ||
{ | ||
if (timerInfo.IsPastDue) | ||
{ | ||
logger.LogInformation("Timer is running late!"); | ||
} | ||
var now = DateTime.Now; | ||
logger.LogInformation($"C# Timer trigger function executed at: {now}"); | ||
|
||
return $"Sample queue message produced at: {now}"; | ||
} | ||
|
||
/// <summary> | ||
/// This functions is executed as new messages appear on the queue and consumes them. | ||
/// </summary> | ||
[FunctionName("SampleQueueMessageConsumer")] | ||
public static void ConsumeSampleQueueMessage([QueueTrigger("sample-queue")] string message, ILogger logger) | ||
{ | ||
logger.LogInformation("Queue message received: {message}", message); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
sdk/storage/Microsoft.Azure.WebJobs.Extensions.Storage.Queues/samples/functionapp/host.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"version": "2.0", | ||
"logging": { | ||
"applicationInsights": { | ||
"samplingExcludedTypes": "Request", | ||
"samplingSettings": { | ||
"isEnabled": true | ||
} | ||
} | ||
}, | ||
"extensions": { | ||
"queues": { | ||
"messageEncoding": "none", | ||
"maxPollingInterval": "00:00:02", | ||
"visibilityTimeout": "00:00:30", | ||
"batchSize": 16, | ||
"maxDequeueCount": 5, | ||
"newBatchThreshold": 8 | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...Microsoft.Azure.WebJobs.Extensions.Storage.Queues/samples/functionapp/local.settings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"IsEncrypted": false, | ||
"Values": { | ||
"AzureWebJobsStorage": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;", | ||
"FUNCTIONS_WORKER_RUNTIME": "dotnet" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters