.net - Trigger SendGrid message (Azure Functions) when Storage Table is added to -
i have azure function queues storage table records can see in azure storage explorer.
i have azure function sends messages through sendgrid, , is supposed trigger when aforementioned queue added to, not.
i'm guessing there's config issue. they're both in same function app , using same connection string, sendgrid function doesn't trigger. both functions vanilla minus email address changes. there other config use?
httppost(crud)-csharp1
{ "bindings": [ { "type": "httptrigger", "direction": "in", "name": "req", "methods": [ "post" ], "authlevel": "function" }, { "type": "http", "direction": "out", "name": "res" }, { "type": "table", "name": "outtable", "tablename": "orders", "connection": "matching_connection_string", "direction": "out" } ], "disabled": false }
sendgridcsharp1
{ "bindings": [ { "type": "sendgrid", "name": "message", "direction": "out", "subject": "", "text": "" }, { "type": "queuetrigger", "name": "order", "queuename": "orders", "connection": "matching_connection_string", "direction": "in" } ], "disabled": false }
update per @daxaholic's answer
daxaholic suggested writing table triggering queue. updated outbound config (changed last binding type queue
) , i'm receiving error not knowing constructor use: function ($httppost(crud)-csharp1) error: can't figure out ctor call.
tried changing namespace microsoft.windowsazure.storage.queue
, didn't seem have effect.
code below:
#r "microsoft.windowsazure.storage" using system.net; using microsoft.windowsazure.storage.table; public static async task<httpresponsemessage> run(httprequestmessage req, icollector<order> outtable, tracewriter log) { var formdata = await req.content.readasformdataasync(); if(string.isnullorwhitespace(formdata.get("name"))) { return req.createresponse(httpstatuscode.badrequest, new { error = "no 'name' property" }); } string name = formdata["name"].tostring(); outtable.add(new order() { partitionkey = "functions", rowkey = guid.newguid().tostring(), orderid = string.format("order{0}", name), customername = name, customeremail = string.format("{0}@{1}.com", name, name) }); return req.createresponse(httpstatuscode.created); } public class order : tableentity { public string orderid { get; set; } public string customername { get; set; } public string customeremail { get; set; } }
i guess problem trigger based on azure storage queue writing azure storage table former not triggered. said, try replace outbound binding azure storage table binding appropriate queue (see here reference)
{ "bindings": [ { "type": "httptrigger", "direction": "in", "name": "req", "methods": [ "post" ], "authlevel": "function" }, { "type": "http", "direction": "out", "name": "res" }, { "type": "queue", "name": "outtable", "queuename": "orders", "connection": "matching_connection_string", "direction": "out" } ], "disabled": false }
update outbound code to:
#r "microsoft.windowsazure.storage" using system.net; using microsoft.windowsazure.storage.queue; public static async task<httpresponsemessage> run(httprequestmessage req, icollector<order> outqueue, tracewriter log) { var formdata = await req.content.readasformdataasync(); if(string.isnullorwhitespace(formdata.get("name"))) { return req.createresponse(httpstatuscode.badrequest, new { error = "no 'name' property" }); } string name = formdata["name"].tostring(); outqueue.add(new order() { orderid = string.format("order{0}", name), customername = name, customeremail = string.format("{0}@{1}.com", name, name) }); return req.createresponse(httpstatuscode.created); } public class order { public string orderid { get; set; } public string customername { get; set; } public string customeremail { get; set; } }
Comments
Post a Comment