forked from microsoft/azure-tools-for-java
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #733 from JetBrains/232-mb-templates
Azure Functions: Update file templates #730
- Loading branch information
Showing
38 changed files
with
899 additions
and
237 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
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
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
72 changes: 72 additions & 0 deletions
72
...ellisense/Templates/File/CSharp/DefaultWorker/CS_Dapr_Publish_Output_Binding.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,72 @@ | ||
--- | ||
guid: a50d2862-4c19-4ab2-90d8-4b61be652e5f | ||
type: File | ||
reformat: True | ||
shortenReferences: True | ||
image: AzureFunctionsTrigger | ||
customProperties: Extension=cs, FileName=DaprPublishOutputBinding, ValidateFileName=True | ||
scopes: InAzureFunctionsCSharpProject;MustUseAzureFunctionsDefaultWorker | ||
parameterOrder: (HEADER), (NAMESPACE), (CLASS), PUBSUBNAME, TOPICVALUE, (SCHEDULE) | ||
HEADER-expression: fileheader() | ||
NAMESPACE-expression: fileDefaultNamespace() | ||
CLASS-expression: getAlphaNumericFileNameWithoutExtension() | ||
TOPICVALUE-expression: constant("topic") | ||
PUBSUBNAME-expression: constant("pubsub") | ||
SCHEDULE-expression: constant("*/10 * * * * *") | ||
--- | ||
|
||
# Dapr Publish Output Binding | ||
|
||
``` | ||
$HEADER$using System.Threading.Tasks; | ||
using CloudNative.CloudEvents; | ||
using Microsoft.Azure.Functions.Extensions.Dapr.Core; | ||
using Microsoft.Azure.WebJobs; | ||
using Microsoft.Azure.WebJobs.Extensions.Dapr; | ||
using Microsoft.Extensions.Logging; | ||
namespace $NAMESPACE$ | ||
{ | ||
public static class $CLASS$ | ||
{ | ||
/// <summary> | ||
/// Visit https://aka.ms/azure-functions-dapr to learn how to use the Dapr extension. | ||
/// These tasks should be completed prior to running : | ||
/// 1. Install Dapr | ||
/// Start function app with Dapr: dapr run --app-id functionapp --app-port 3001 --dapr-http-port 3501 -- func host start | ||
/// Function will be invoked by Timer trigger and publish messages to message bus. | ||
/// </summary> | ||
/// <param name="log">Function logger.</param> | ||
[FunctionName("$CLASS$")] | ||
// we can try using Function timer trigger. | ||
// Rename the template to PublishTemplate | ||
public static void Run([TimerTrigger("$SCHEDULE$")] TimerInfo myTimer, | ||
[DaprPublish(PubSubName = "$PUBSUBNAME$", Topic = "$TOPICVALUE$")] out DaprPubSubEvent pubEvent, | ||
ILogger log) | ||
{ | ||
log.LogInformation("C# DaprPublish output binding function processed a request."); | ||
pubEvent = new DaprPubSubEvent("Invoked by Timer trigger: " + $"Hello, World! The time is {System.DateTime.UtcNow}");$END$ | ||
} | ||
} | ||
// Below Azure function will receive message published on topic $TOPICVALUE$, and it will log the message | ||
public static class $CLASS$TopicTrigger | ||
{ | ||
/// <summary> | ||
/// Visit https://aka.ms/azure-functions-dapr to learn how to use the Dapr extension. | ||
/// This function will get invoked when a message is published on topic $TOPICVALUE$ | ||
/// </summary> | ||
/// <param name="subEvent">Cloud event sent by Dapr runtime.</param> | ||
/// <param name="log">Function logger.</param> | ||
[FunctionName("$CLASS$TopicTrigger")] | ||
public static async Task RunAsync( | ||
[DaprTopicTrigger("$PUBSUBNAME$", Topic = "$TOPICVALUE$")] CloudEvent subEvent, | ||
ILogger log) | ||
{ | ||
log.LogInformation("C# Dapr Topic Trigger function processed a request from the Dapr Runtime."); | ||
log.LogInformation($"Topic A received a message: {subEvent.Data}."); | ||
} | ||
} | ||
} | ||
``` |
88 changes: 88 additions & 0 deletions
88
...sense/Templates/File/CSharp/DefaultWorker/CS_Dapr_Service_Invocation_Trigger.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,88 @@ | ||
--- | ||
guid: 6a12542b-e634-41c1-a11b-804f08792e6e | ||
type: File | ||
reformat: True | ||
shortenReferences: True | ||
image: AzureFunctionsTrigger | ||
customProperties: Extension=cs, FileName=DaprServiceInvocationTrigger, ValidateFileName=True | ||
scopes: InAzureFunctionsCSharpProject;MustUseAzureFunctionsDefaultWorker | ||
parameterOrder: (HEADER), (NAMESPACE), (CLASS) | ||
HEADER-expression: fileheader() | ||
NAMESPACE-expression: fileDefaultNamespace() | ||
CLASS-expression: getAlphaNumericFileNameWithoutExtension() | ||
--- | ||
|
||
# Dapr Service Invocation Trigger | ||
|
||
``` | ||
$HEADER$using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Azure.Functions.Extensions.Dapr.Core; | ||
using Microsoft.Azure.WebJobs; | ||
using Microsoft.Azure.WebJobs.Extensions.Dapr; | ||
using Microsoft.Azure.WebJobs.Extensions.Http; | ||
using Microsoft.Extensions.Logging; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
namespace $NAMESPACE$ | ||
{ | ||
public static class $CLASS$ | ||
{ | ||
/// <summary> | ||
/// Visit https://aka.ms/azure-functions-dapr to learn how to use the Dapr extension. | ||
/// These tasks should be completed prior to running : | ||
/// 1. Install Dapr | ||
/// Start function app with Dapr: dapr run --app-id functionapp --app-port 3001 --dapr-http-port 3501 -- func host start | ||
/// Invoke function app by dapr cli: dapr invoke --app-id functionapp --method {yourFunctionName} --data '{ \"data\": {\"value\": { \"orderId\": \"41\" } } }' | ||
/// Invoke function app by http trigger: | ||
/// curl 'http://localhost:7071/api/invoke/functionapp/{yourFunctionName}' ` | ||
/// --header 'Content-Type: application/json' ` | ||
/// --data '{ | ||
/// "data": { | ||
/// "value": { | ||
/// "orderId": "41" | ||
/// } | ||
/// } | ||
/// }' | ||
/// <param name="payload">Payload of dapr service invocation trigger.</param> | ||
/// <param name="log">Function logger.</param> | ||
/// </summary> | ||
[FunctionName("$CLASS$")] | ||
public static async Task RunAsync( | ||
[DaprServiceInvocationTrigger] string payload, | ||
ILogger log) | ||
{ | ||
log.LogInformation("Azure function triggered by Dapr Service Invocation Trigger."); | ||
log.LogInformation($"Dapr service invocation trigger payload: {payload}");$END$ | ||
} | ||
} | ||
public static class $CLASS$InvokeOutputBinding | ||
{ | ||
/// <summary> | ||
/// Sample to use a Dapr Invoke Output Binding to perform a Dapr Server Invocation operation hosted in another Darp'd app. | ||
/// Here this function acts like a proxy | ||
/// </summary> | ||
[FunctionName("$CLASS$InvokeOutputBinding")] | ||
public static async Task<IActionResult> RunAsync( | ||
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "invoke/{appId}/{methodName}")] HttpRequest req, | ||
[DaprInvoke(AppId = "{appId}", MethodName = "{methodName}", HttpVerb = "post")] IAsyncCollector<InvokeMethodParameters> output, | ||
ILogger log) | ||
{ | ||
log.LogInformation("C# HTTP trigger function processed a request."); | ||
string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); | ||
var outputContent = new InvokeMethodParameters | ||
{ | ||
Body = requestBody | ||
}; | ||
await output.AddAsync(outputContent); | ||
return new OkObjectResult("Successfully performed service invocation using Dapr invoke output binding."); | ||
} | ||
} | ||
} | ||
``` |
55 changes: 55 additions & 0 deletions
55
...Azure.Intellisense/Templates/File/CSharp/DefaultWorker/CS_Dapr_Topic_Trigger.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,55 @@ | ||
--- | ||
guid: e0938da7-d4be-412b-aa79-a23745721fda | ||
type: File | ||
reformat: True | ||
shortenReferences: True | ||
image: AzureFunctionsTrigger | ||
customProperties: Extension=cs, FileName=DaprTopicTrigger, ValidateFileName=True | ||
scopes: InAzureFunctionsCSharpProject;MustUseAzureFunctionsDefaultWorker | ||
parameterOrder: (HEADER), (NAMESPACE), (CLASS), PUBSUBNAME, TOPICVALUE, STATESTORE, STATESTOREKEY | ||
HEADER-expression: fileheader() | ||
NAMESPACE-expression: fileDefaultNamespace() | ||
CLASS-expression: getAlphaNumericFileNameWithoutExtension() | ||
TOPICVALUE-expression: constant("topic") | ||
PUBSUBNAME-expression: constant("pubsub") | ||
STATESTORE-expression: constant("statestore") | ||
STATESTOREKEY-expression: constant("product") | ||
--- | ||
|
||
# Dapr Topic Trigger | ||
|
||
``` | ||
$HEADER$using System.Text.Json; | ||
using System.Threading.Tasks; | ||
using CloudNative.CloudEvents; | ||
using Microsoft.Azure.WebJobs; | ||
using Microsoft.Azure.WebJobs.Extensions.Dapr; | ||
using Microsoft.Extensions.Logging; | ||
namespace $NAMESPACE$ | ||
{ | ||
public static class $CLASS$ | ||
{ | ||
/// <summary> | ||
/// Visit https://aka.ms/azure-functions-dapr to learn how to use the Dapr extension. | ||
/// These tasks should be completed prior to running : | ||
/// 1. Install Dapr | ||
/// Start function app with Dapr: dapr run --app-id functionapp --app-port 3001 --dapr-http-port 3501 -- func host start | ||
/// Invoke function app: dapr publish --pubsub pubsub --publish-app-id functionapp --topic $TOPICVALUE$ --data '{\"value\": { \"orderId\": \"42\" } }' | ||
/// </summary> | ||
/// <param name="subEvent">Cloud event sent by Dapr runtime.</param> | ||
/// <param name="value">Value will be saved against the given key in state store.</param> | ||
/// <param name="log">Function logger.</param> | ||
[FunctionName("$CLASS$")] | ||
public static void Run( | ||
[DaprTopicTrigger("$PUBSUBNAME$", Topic = "$TOPICVALUE$")] CloudEvent subEvent, | ||
[DaprState("$STATESTORE$", Key = "$STATESTOREKEY$")] out object value, | ||
ILogger log) | ||
{ | ||
log.LogInformation("C# DaprTopic trigger with DaprState output binding function processed a request from the Dapr Runtime."); | ||
value = subEvent.Data;$END$ | ||
} | ||
} | ||
} | ||
``` |
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
Oops, something went wrong.