Configuring the Azure Functions Application Settings

June 8, 2020 ยท View on GitHub

The solution requires a set of application settings on the Azure Functions environment.

Configurations

Cosmos DB configuration

PropertyDescription
CosmosDbConnectionStringThe Cosmos DB connection string. It must be in the following format: AccountEndpoint=https://<database name>.documents.azure.com:443/;AccountKey=<key>
CosmosDbDatabaseNameThe Cosmos DB database name
CosmosDbOrchestratorCollectionNameThe collection name on Cosmos DB for the Saga Orchestrator service
CosmosDbValidatorCollectionNameThe collection name on Cosmos DB for the Validator service
CosmosDbTransferCollectionNameThe collection name on Cosmos DB for the Transfer service
CosmosDbReceiptCollectionNameThe collection name on Cosmos DB for the Receipt service
CosmosDbSagaCollectionNameThe collection name on Cosmos DB for Saga observability

Event Hubs Configuration

PropertyDescription
EventHubsNamespaceConnectionThe Event Hubs namespace connection string. It must be in the following format: Endpoint=sb://<namespace name>.servicebus.windows.net/;SharedAccessKeyName=<key name>;SharedAccessKey=<key>
ValidatorEventHubNameThe Event Hub name for the Validator service
TransferEventHubNameThe Event Hub name for the Transfer service
ReceiptEventHubNameThe Event Hub name for the Receipt service
ReplyEventHubNameThe Event Hub name for the Saga Event Processor service

Retry configuration

PropertyDescription
EventHubsProducerMaxRetryAttemptsMax number of retry attempts for producing commands and events to Event Hubs
ActivityMaxRetryAttemptsMax number of retry attempts for calling the Command Producer Activity and Saga Orchestrator Activity functions
ActivityRetryIntervalRetry interval in seconds for calling the Command Producer Activity and Saga Orchestrator Activity functions

Circuit Breaker configuration

PropertyDescription
EventHubsProducerExceptionsAllowedBeforeBreakingMax number of exceptions allowed on producing commands and events to Event Hubs before breaking the circuit
EventHubsProducerBreakDurationDuration in seconds of the break on the Event Hubs producer

Timeout configuration

PropertyDescription
ValidatorTimeoutSecondsTimeout in seconds for waiting a state response from the Validator service in the orchestrator
TransferTimeoutSecondsTimeout in seconds for waiting a state response from the Transfer service in the orchestrator
ReceiptTimeoutSecondsTimeout in seconds for waiting a state response from the Receipt service in the orchestrator

Receipt service configuration

In order to simplify the simulation of compensating transaction scenarios, two additional properties were added:

PropertyDescription
CreateRandomReceiptResultFlag for creating random state results (successful or failed operations). If the flag is set to false, the Receipt service will always return successful operations.
ReceiptSuccessProbabilitySuccess probability percentage on random state results for the Receipt service. When set to 100, means that 100% of the requests will generate successful operations, while 0 mean that all requests will generate failed operations.

Updating settings

For running the solution locally, make sure you have the local.settings.json file under the Saga.Orchestration and Saga.Participants projects.

{
  "IsEncrypted": false,
  "Values": {
    "CosmosDbConnectionString": "AccountEndpoint=https://<database name>.documents.azure.com:443/;AccountKey=<key>",
    "CosmosDbDatabaseName": "sagadb",
    "CosmosDbOrchestratorCollectionName": "orchestrator",
    "CosmosDbValidatorCollectionName": "validator",
    "CosmosDbTransferCollectionName": "transfer",
    "CosmosDbReceiptCollectionName": "receipt",
    "CosmosDbSagaCollectionName": "saga",
    
    "EventHubsNamespaceConnection": "Endpoint=sb://<namespace name>.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=<key>",
    "ValidatorEventHubName": "validator",
    "TransferEventHubName": "transfer",
    "ReceiptEventHubName": "receipt",
    "ReplyEventHubName": "saga-reply",

    "EventHubsProducerMaxRetryAttempts": 3,
    "ActivityMaxRetryAttempts": 3,
    "ActivityRetryInterval": 5,

    "EventHubsProducerExceptionsAllowedBeforeBreaking": 5,
    "EventHubsProducerBreakDuration": 10,

    "ValidatorTimeoutSeconds": 30,
    "TransferTimeoutSeconds": 30,
    "ReceiptTimeoutSeconds": 30,

    "CreateRandomReceiptResult": true,
    "ReceiptSuccessProbability": 0,

    "AzureWebJobsStorage": "<storage connection string>",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet"
  }
}

Note: AzureWebJobsStorage can be set to use an Azure storage account or to use an Azure Storage Emulator that acts as a single storage account. For setting up the emulator, follow the Use the Azure storage emulator for development and testing instructions.