如何在功能内将消息推送到Azure服务总线上 [英] How to push a message onto azure service bus within a function

查看:63
本文介绍了如何在功能内将消息推送到Azure服务总线上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need my azure function written in C# to push a message onto the service bus. The examples I've seen online show how an azure function can be triggered when a new message happens.

有没有可用的示例?

当前的天蓝色函数(C#)

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

            // send new message?

        }

非常感谢!J

更新

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

How to create a new message within an azure function

        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;
        }

推荐答案

您需要查找

以下示例显示了一个C#函数,该函数发送服务总线队列消息:

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;
}

这是创建多个消息的C#脚本代码:

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);
}

这篇关于如何在功能内将消息推送到Azure服务总线上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆