Skip to content

Instantly share code, notes, and snippets.

@rogeralsing
Created May 29, 2018 09:20
Show Gist options
  • Save rogeralsing/8961d3fe2d17fe26b562ed1449ab881b to your computer and use it in GitHub Desktop.
Save rogeralsing/8961d3fe2d17fe26b562ed1449ab881b to your computer and use it in GitHub Desktop.
const EventGridClient = require("azure-eventgrid");
const msRestAzure = require("ms-rest-azure");
const uuid = require("uuid").v4;
const topicCreds = new msRestAzure.TopicCredentials(
"mytopickey"
);
const EGClient = new EventGridClient(topicCreds);
const topicEndpoint = "mytopic.westeurope-1.eventgrid.azure.net";
module.exports = function(context, req) {
context.log("JavaScript HTTP trigger function processed a request.");
let events = [
{
id: uuid(),
subject: "TestSubject",
dataVersion: "1.0",
eventType: "Microsoft.MockPublisher.TestEvent",
eventTime: new Date(),
data: {
field1: "value1",
filed2: "value2"
}
}
];
EGClient.publishEvents(topicEndpoint, events)
.then(result => {
context.res = {
body: "Success " + result
};
context.done(); //this will execute, but it takes a good 60+ seconds sometimes
})
.catch(err => {
console.log("An error ocurred");
console.dir(err, { depth: null, colors: true });
context.res = {
body: "Failure " + err
};
context.done();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment