Skip to content

Commit

Permalink
[Storage] Webjobs extension sample apps. (Azure#18358)
Browse files Browse the repository at this point in the history
* nest sample tests?

* queues sample app.

* nesting.

* new link.

* blobs sample.

* fix build.

* fix build.

* does this fix the build ?
  • Loading branch information
kasobol-msft authored and jongio committed Feb 9, 2021
1 parent d59d904 commit 2d0be7b
Show file tree
Hide file tree
Showing 19 changed files with 241 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ public static class BlobFunction_EnumerateBlobs_BlobClient
}
```

### Configuring the extension

Please refer to [sample functions app]<!--(https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/storage/Microsoft.Azure.WebJobs.Extensions.Storage.Blobs/samples/functionapp) TODO (kasobol-msft) uncomment post merge.-->.

## Troubleshooting

Please refer to [Monitor Azure Functions](https://docs.microsoft.com/azure/azure-functions/functions-monitoring) for troubleshooting guidance.
Expand Down
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>
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>
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.
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);
}
}
}
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"
}
}
}
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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Microsoft.Azure.WebJobs.Extensions.Storage.Common\tests\Microsoft.Azure.WebJobs.Extensions.Storage.Common.Tests.csproj" />
<ProjectReference Include="..\src\Microsoft.Azure.WebJobs.Extensions.Storage.Blobs.csproj" />
<ProjectReference Include="..\..\..\Microsoft.Azure.WebJobs.Extensions.Storage.Common\tests\Microsoft.Azure.WebJobs.Extensions.Storage.Common.Tests.csproj" />
<ProjectReference Include="..\..\src\Microsoft.Azure.WebJobs.Extensions.Storage.Blobs.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ public static class Function_BindingToQueueClient
}
```

### Configuring the extension

Please refer to [sample functions app]<!--(https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/storage/Microsoft.Azure.WebJobs.Extensions.Storage.Queues/samples/functionapp) TODO (kasobol-msft) uncomment post merge.-->.

## Troubleshooting

Please refer to [Monitor Azure Functions](https://docs.microsoft.com/azure/azure-functions/functions-monitoring) for troubleshooting guidance.
Expand Down
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>
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>
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.
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);
}
}
}
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
}
}
}
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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Microsoft.Azure.WebJobs.Extensions.Storage.Common\tests\Microsoft.Azure.WebJobs.Extensions.Storage.Common.Tests.csproj" />
<ProjectReference Include="..\src\Microsoft.Azure.WebJobs.Extensions.Storage.Queues.csproj" />
<ProjectReference Include="..\..\..\Microsoft.Azure.WebJobs.Extensions.Storage.Common\tests\Microsoft.Azure.WebJobs.Extensions.Storage.Common.Tests.csproj" />
<ProjectReference Include="..\..\src\Microsoft.Azure.WebJobs.Extensions.Storage.Queues.csproj" />
</ItemGroup>
</Project>
16 changes: 14 additions & 2 deletions sdk/storage/Microsoft.Azure.WebJobs.Extensions.Storage.sln
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.WebJobs.Ext
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.Azure", "..\extensions\Microsoft.Extensions.Azure\src\Microsoft.Extensions.Azure.csproj", "{CB002B93-3D25-42DD-B1A6-472C10B99BA7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.WebJobs.Extensions.Storage.Blobs.Samples.Tests", "Microsoft.Azure.WebJobs.Extensions.Storage.Blobs\samples\Microsoft.Azure.WebJobs.Extensions.Storage.Blobs.Samples.Tests.csproj", "{77860E78-4770-4C48-8C2B-AF6B42A8D067}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.WebJobs.Extensions.Storage.Blobs.Samples.Tests", "Microsoft.Azure.WebJobs.Extensions.Storage.Blobs\samples\readmes\Microsoft.Azure.WebJobs.Extensions.Storage.Blobs.Samples.Tests.csproj", "{77860E78-4770-4C48-8C2B-AF6B42A8D067}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.WebJobs.Extensions.Storage.Queues.Samples.Tests", "Microsoft.Azure.WebJobs.Extensions.Storage.Queues\samples\Microsoft.Azure.WebJobs.Extensions.Storage.Queues.Samples.Tests.csproj", "{A7A937E4-F4E1-47B7-8D25-AA5FB6BDE010}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.WebJobs.Extensions.Storage.Queues.Samples.Tests", "Microsoft.Azure.WebJobs.Extensions.Storage.Queues\samples\readmes\Microsoft.Azure.WebJobs.Extensions.Storage.Queues.Samples.Tests.csproj", "{A7A937E4-F4E1-47B7-8D25-AA5FB6BDE010}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.WebJobs.Extensions.Storage", "Microsoft.Azure.WebJobs.Extensions.Storage\src\Microsoft.Azure.WebJobs.Extensions.Storage.csproj", "{022028DA-6134-4648-881C-9503E3034995}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.WebJobs.Extensions.Storage.Queues.Samples.Function.App", "Microsoft.Azure.WebJobs.Extensions.Storage.Queues\samples\functionapp\Microsoft.Azure.WebJobs.Extensions.Storage.Queues.Samples.Function.App.csproj", "{342E84D9-3073-4536-A895-0F843782BA97}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.WebJobs.Extensions.Storage.Blobs.Samples.Function.App", "Microsoft.Azure.WebJobs.Extensions.Storage.Blobs\samples\functionapp\Microsoft.Azure.WebJobs.Extensions.Storage.Blobs.Samples.Function.App.csproj", "{22D974DB-0B34-48F5-90EC-F65F9902E7D3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -104,6 +108,14 @@ Global
{022028DA-6134-4648-881C-9503E3034995}.Debug|Any CPU.Build.0 = Debug|Any CPU
{022028DA-6134-4648-881C-9503E3034995}.Release|Any CPU.ActiveCfg = Release|Any CPU
{022028DA-6134-4648-881C-9503E3034995}.Release|Any CPU.Build.0 = Release|Any CPU
{342E84D9-3073-4536-A895-0F843782BA97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{342E84D9-3073-4536-A895-0F843782BA97}.Debug|Any CPU.Build.0 = Debug|Any CPU
{342E84D9-3073-4536-A895-0F843782BA97}.Release|Any CPU.ActiveCfg = Release|Any CPU
{342E84D9-3073-4536-A895-0F843782BA97}.Release|Any CPU.Build.0 = Release|Any CPU
{22D974DB-0B34-48F5-90EC-F65F9902E7D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{22D974DB-0B34-48F5-90EC-F65F9902E7D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{22D974DB-0B34-48F5-90EC-F65F9902E7D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{22D974DB-0B34-48F5-90EC-F65F9902E7D3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 2d0be7b

Please sign in to comment.