我创建了Azure Function,只要将新邮件添加到Azure ServiceBus队列,就会触发该SO Post。 使用此代码可以正常工作:
#r "Newtonsoft.Json"
#load "..\shared\person.csx"
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
public static void Run(string message, TraceWriter log)
{
var person = JsonConvert.DeserializeObject<Person>(message,
new JsonSerializerSettings() {ContractResolver = new CamelCasePropertyNamesContractResolver()});
log.Verbose($"From DeserializeObject: {person.FirstName} {person.LastName}");
}
我已经看到我也可以将消息绑定到这样的POCO:
public static void Run(Person message, TraceWriter log)
{
log.Verbose($"From DeserializeObject: {message.FirstName} {message.LastName}");
}
现在我想将消息绑定到BrokeredMessage
,因为我需要访问消息的属性。
答案 0 :(得分:16)
修改新SDK使用#r directive
支持servicebus sdk
#r "Microsoft.ServiceBus"
using Microsoft.ServiceBus.Messaging;
public static void Run(BrokeredMessage msg, TraceWriter log)
{
log.Info($"C# ServiceBus queue trigger function processed message: {msg}");
}
旧版
只有两个步骤:
我已创建project.json
文件以添加对WindowsAzure.ServiceBus
Nuget包的引用(请参阅https://msdn.microsoft.com/en-us/mt429383.aspx):
{
"frameworks": {
"net46":{
"dependencies": {
"WindowsAzure.ServiceBus": "2.7.6"
}
}
}
}
我已经添加了对代理消息的引用:
using Microsoft.ServiceBus.Messaging;
public static void Run(BrokeredMessage message, TraceWriter log)
{
log.Verbose("Function has been triggered !!!");
}
答案 1 :(得分:2)
我试过托马斯&#39;解决方案似乎不再适用。
此外,以下程序集是特殊的,可以通过simplename引用(例如#r&#34; AssemblyName&#34;):
- ...
- Microsoft.ServiceBus
因此,如果不触及project.json文件,则可以进行以下操作:
#r "Microsoft.ServiceBus"
using Microsoft.ServiceBus.Messaging;
public static void Run(BrokeredMessage msg, TraceWriter log)
{
log.Info($"C# ServiceBus queue trigger function processed message: {msg}");
}