如何使用GO

问题描述 投票:0回答:1

我想在使用Golang派出事件网格事件时运行Azure功能。 但是,我正在尝试测试该功能,但是在使用卷发测试端点时,我会得到500。

-X POST -H 'aeg-event-type: Notification' \ -H "Content-Type: application/json" \ -d @eventgridtriggerschema.json \ 'https://xxxxx.azurewebsites.net/runtime/webhooks/EventGrid?functionName=EventGridTrigger&code=xxxxxx' && echo 500
EventGridTriggerschema.json是一个示例事件网格tigger:

https://learn.microsoft.com/en-us/azure/event-grid/event-grid/event-grid/event-schema#event-schema, 在Log Analytics中查看Azure函数侧的日志,我看不到任何跳出的东西是错误的。我确实看到了我使用卷曲的请求,但是例外并没有真正加起来是错误的,或者对我需要修复的内容提供了任何见解:

---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 404 (Not Found). at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()

我的GO应用程序非常基本,因为我只是想在实现逻辑之前使端点工作:

func eventGridTriggerHandler(w http.ResponseWriter, r *http.Request) {
   log.Printf("Recieved message!")
}

func main() {
  listenAddr := ":8080"
  if val, ok := os.LookupEnv("FUNCTIONS_CUSTOMHANDLER_PORT"); ok {
    listenAddr = ":" + val
  }
  http.HandleFunc("/api/EventGridTrigger", eventGridTriggerHandler)
  log.Printf("About to listen on %s. Go to http://127.0.0.1%s/", listenAddr, listenAddr)
  log.Fatal(http.ListenAndServe(listenAddr, nil))
}
我的函数

{ "bindings": [ { "authLevel": "anonymous", "type": "eventGridTrigger", "direction": "in", "name": "req" } ] }

我的主机。
host.json

有人可以帮助我解决为什么使用EventGridTrigger时此GO功能应用程序不起作用?我正在考虑切换到Python或其他其他东西,但是我想在这里发布,看看是否有人有任何想法,可以将我指向正确的方向。

预先提前帮助
	

我正在考虑切换到python或其他东西


I在GO中尝试了事件网格触发功能,但没有触发。然后,我在Python(V1模型)中尝试了事件网格触发函数,并成功触发了事件。
Init

.py:

{ "version": "2.0", "logging": { "applicationInsights": { "samplingSettings": { "isEnabled": true, "excludedTypes": "Request" } }, "fileLoggingMode": "always", "logLevel": { "default": "Information", "Host.Results": "Error", "Function": "Trace", "Host.Aggregator": "Trace" } }, "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle", "version": "[4.*, 5.0.0)" }, "customHandler": { "description": { "defaultExecutablePath": "handler", "workingDirectory": "", "arguments": [] }, "enableForwardingHttpRequest": true } }

azure go azure-functions azure-eventgrid
1个回答
0
投票

postman:

import json import logging from azure.functions import EventGridEvent def main(event: EventGridEvent): result = json.dumps({ 'id': event.id, 'data': event.get_json(), 'topic': event.topic, 'subject': event.subject, 'event_type': event.event_type, }) logging.info('Python EventGrid trigger processed an event: %s', result)

在标题下,添加了EventGridTopicKey,如下所示, https://kamxxxxxx.eventgrid.azure.net/api/events?api-version=2018-01-01

json身体:

enter image description hereaeg-sas-key : <EventGridTopicKey>

我成功地将事件发送到了Azure事件网格主题。

ZURE函数应用程序Inconcations:

事件网格触发函数成功触发了。

enter image description here

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.