c# - 如何将动态值传递给EventHub属性Azure函数c#

标签 c# azure azure-functions azure-eventhub

函数触发器的类型为HttpTrigger,我希望将数据发送到EventHuboutputEventHubMessage。

public class AzureTestFunc 
{
    private readonly ConfigSettings _settings;
    public AzureTestFunc(IOptions<ConfigSettings> options)
    {
        _settings = options.Value;
    }

     [FunctionName("test")]
     public HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "get","post", Route = null)] HttpRequest req,
     [EventHub("eventhubname-test", Connection = "connectionstring-test")] out string outputEventHubMessage, ILogger log, ExecutionContext ctx) 
     {
                
            return new HttpResponseMessage
            {
                StatusCode = System.Net.HttpStatusCode.BadRequest,
                Content = new StringContent(validationError)

            };
      }
    
}

如何使用 [EventHub(?, ?)] 属性中的 _settings 对象动态传递 EventHubName 和连接字符串值? _settings 对象包含 EventHubName 和 Connection 的值,例如_settings.EventHubName & _settings.Connection

最佳答案

对于 EventHubName,请使用“%YourEventHubSettingName%”格式从应用设置中提取。

对于连接,只需提供包含连接字符串的应用程序设置名称,不带 %。

引用:EventHub trigger binding

关于c# - 如何将动态值传递给EventHub属性Azure函数c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72993240/

相关文章:

.net - "A severe error occurred on the current command. The results, if any, should be discarded."SQL Azure 错误是什么意思?

azure - 在 Azure VM 的本地 SSD(临时驱动器)中设置交换文件

c# - 如何将输出值绑定(bind)到我的异步 Azure Functions?

c# - 如何修复 "Could not load type ' System.Runtime.Remoting.Messaging.CallContext'"

c# - HtmlTextWriter 到 String - 我是否忽略了什么?

javascript - 以 JSON 形式返回字典并使用 JS 函数成功访问其内容 - C#

c# - PdfSharp 克隆页面 : An item with the same key has already been added

c# - Soap Webservice 透明 WSDL 更改

linux - 用于 Linux 计算机的 azure 命令行工具,用于向 Azure 存储上传/下载数据

javascript - 在 Azure Function 中处理 POST 请求以将文件上传到 Blob 存储