The following example shows how to publish an event to Azure Event Grid based on CloudEvents Schema, using SendEvent method.
&CloudEvent is CloudEvent SDT.
&endpoint = !"https://eventgridcloud.eastus-1.eventgrid.azure.net/api/events"
&accesskey = !"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
&EventRouter = AzureEventGrid.EventGridRouterProvider.Connect(&endpoint,&accesskey,&errorMessages,&IsSuccess)
&CloudEvent = new()
&CloudEvent.source = !"GeneXusApp"
&CloudEvent.type = !"Test"
&CloudEvent.data = '{' +\
'"employee": {' +\
'"name": "Sofia",' +\
'"salary": 19000,' +\
'"married": true' +\
'}' +\
'}'
&isOK = &EventRouter.SendEvent(&CloudEvent,&isBinary,&errorMessages)
if not &isOK
msg(format("Error %1(%2)",&errorMessages.Item(1).Description, &errorMessages.Item(1).Id), status)
endif
The following example shows how to send a collection of events using CloudEvent Schema for the representation of them.
The method used is SendEvents.
&CloudEvent = new()
&CloudEvent.source = !"GeneXusAppTest3"
&CloudEvent.type = !"Test3"
&CloudEvent.data = '{' +\
'"employee": {' +\
'"name": "maria",' +\
'"salary": 59000,' +\
'"married": true' +\
'}' +\
'}'
&CloudEventCollection.Add(&CloudEvent)
&CloudEvent = new()
&CloudEvent.source = !"GeneXusAppTest4"
&CloudEvent.type = !"Test4"
&CloudEvent.datacontenttype = !"application/json"
&CloudEvent.data = '{' +\
'"employee": {' +\
'"name": "ana",' +\
'"salary": 59800,' +\
'"married": false' +\
'}' +\
'}'
&CloudEventCollection.Add(&CloudEvent)
&isBinary = false
&isOK = &EventRouter.SendEvents(&CloudEventCollection,&isBinary,&errorMessages)