简体   繁体   中英

Azure Key Vault secrets with ServiceBusTrigger Attribute on Web App Jobs

I have Web App Job project which is configured to pluck messages from an Azure Service Bus and process them.

Presently I have a Functions class and a MessageReceived() method which is used as such:

public async Task MessageReceived( [ServiceBusTrigger("some-queue", Connection="ServiceBusConnectionString")], SomeClass someInstance, int deliveryCount, DateTime enqueuedTimeUtc, string messageId, ILoggerlog) { //message procesing code }

I also have all the KeyVault infrastructure in place, but I don't know how to get the Azure Secrets work with the [ServiceBusTrigger] attribute.

Normally I would use @Microsoft.KeyVault(VaultName=myvault;SecretName=mysecret) in code, but I don't know how to use it with the trigger.

I have tried to pass the Secret to the Attribute, but that wouldn't work because attributes expect constant values.

Any concrete examples would be appreciated.

  • Well, you can directly save the reference of the key vault secret in the application settings in the following format
@Microsoft.KeyVault(VaultName=<Keyvault name>;SecretName=<Secret Name> ;  SecretVersion = <Secret version >)
  • The application settings are under the configuration tab

Here in code my connection string is set to name connection so we must use the same name for the key vault reference.

在此处输入图像描述

output of the service bus trigger:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM