c# - 在 C# 脚本 Azure Function 中使用 ServiceBus 作为输出参数

标签 c# azure

我想要一个用 C# 脚本编写的 azure 函数,该函数由 http 请求触发,然后将消息发送到 Azure ServiceBus 主题。当 out 参数设置为字符串时,一切正常,但我希望能够在发送消息时设置消息的元数据,例如 To 。 我想我应该将字符串类型更改为 Message(来自 ServiceBus)来实现这一目标,但我不知道如何包含该包。 我的代码function.json:

    {
  "bindings": [
    {
      "authLevel": "function",
      "name": "req",
      "type": "httpTrigger",
      "direction": "in",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "name": "$return",
      "type": "http",
      "direction": "out"
    },
    {
      "connection": "AzureServiceBus",
      "name": "outputSbMsg",
      "topicName": "producttest",
      "direction": "out",
      "type": "serviceBus"
    }
  ]
}

和函数定义:

#r "Newtonsoft.Json"

using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;  
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;  

public static async Task<IActionResult> Run(HttpRequest req, ICollector<Message> outputSbMsg, ILogger log)

我遇到错误:找不到类型或命名空间名称“Message”(您是否缺少 using 指令或程序集引用?) 我找不到正确的 include 和 #r 组合来使其工作

最佳答案

在文件顶部添加 using Microsoft.Azure.ServiceBus;

关于c# - 在 C# 脚本 Azure Function 中使用 ServiceBus 作为输出参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67024198/

相关文章:

c# - .Net HttpListener.GetContext() 给客户端 "503 Service Unavailable"

c# - 用于下载大文件的 Asmx Web 服务

c# - 为什么 LinqToEntities Skip/Take oracle 实现如此缓慢

c# - 我可以、如何向 Azure Function 提供设置文件?

azure - 标准逻辑应用运行超时设置不起作用

azure - Azure 上管理大量数据并将其按订单交付给许多订阅者的最佳服务是什么

c# - TurnContext Respond 如何使用 Waterfalldialogs 工作?

C# 冲突时设置默认命名空间

wcf - 将 HTTP-Push 技术 "Reliable Secure Profile"迁移到 Azure

azure - 如何通过Azure REST API获取IOT Edge模块的运行状态? (不是来自 'Get Modules on Device' API 调用的连接状态或状态)