如何在函数内将消息推送到 Azure 服务总线

How to push a message onto azure service bus within a function

我需要用 C# 编写的 azure 函数来将消息推送到服务总线上。我在网上看到的示例展示了如何在出现新消息时触发 azure 函数。

有例子吗?

当前 azure 函数 (C#)

[FunctionName("IHandleMessage")]
        public void Run([ServiceBusTrigger("my.topic", "my.subscription", Connection = "mybus_SERVICEBUS")]string mySbMsg, ILogger log)
        {

            // send new message?

        }

非常感谢! J

更新

如何在 azure 函数中创建新消息

        public void Run([ServiceBusTrigger("my.topic", "my.subscription", Connection = "mybus_SERVICEBUS")]string mySbMsg, ILogger log)
        {            
            ServiceBusOutput("hello", log);  // Create a new message
        }

        [FunctionName("AnotherEvent")]
        [return: ServiceBus("my.other.queue", Connection = "mySERVICEBUS")]
        public static string ServiceBusOutput([HttpTrigger] dynamic input, ILogger log)
        {
            log.LogInformation($"C# function processed: {input.Text}");
            return input.Text;
        }

您需要查找 output binding 个示例。

The following example shows a C# function that sends a Service Bus queue message:

[FunctionName("ServiceBusOutput")]
[return: ServiceBus("myqueue", Connection = "ServiceBusConnection")]
public static string ServiceBusOutput([HttpTrigger] dynamic input, ILogger log)
{
    log.LogInformation($"C# function processed: {input.Text}");
    return input.Text;
}

Here's C# script code that creates multiple messages:

public static async Task Run(TimerInfo myTimer, ILogger log, IAsyncCollector<string> outputSbQueue)
{
    string message = $"Service Bus queue messages created at: {DateTime.Now}";
    log.LogInformation(message); 
    await outputSbQueue.AddAsync("1 " + message);
    await outputSbQueue.AddAsync("2 " + message);
}