ovation22
ovation22

Reputation: 731

Azure Event Grid consume events from Hybrid Connection with Node

Can someone point me in the right direction? I'm working with a client who is looking to have 3rd parties receive event data from them (blob created, etc). The C# example works great:

https://azure.microsoft.com/en-us/resources/samples/event-grid-dotnet-publish-consume-events/

However, some of their clients are using Node and we're having trouble getting them connected. The samples work great when there is a sender/listener, but the listener is effectively swallowing Event Grid events, as they are sent with a "request" key, and the sender/listener events are sent with an "accept" key.

https://github.com/Azure/azure-relay/tree/master/samples/hybrid-connections/node

I can point directly to the line within each Node sample (HybridConnectionWebSocktServer.js, etc.) where the event is being processed, and subsequently ignored.

I've also found and tried this function example, but haven't been successful receiving Event Grid events locally:

https://azure.microsoft.com/is-is/resources/samples/event-grid-node-publish-consume-events/

Is there a better example? Is there a better method? Should we be approaching this from another direction?

Any help, guidance, or nudge in the right direction would be greatly appreciated.

Upvotes: 0

Views: 422

Answers (1)

ovation22
ovation22

Reputation: 731

I reached out to all available avenues to try to resolve my issue quickly. I wanted to post the answer here in case anyone else has the same trouble I did.

Huge thanks to those at Microsoft that were able to point me in the right direction and help me solve the issue.

Event Grid is built exclusively on HTTP so it makes sense that you’re getting the events with a request gesture. Incase you haven’t found it, the doc on the interaction model for Hybrid Connections is available here.

The sample you’re looking at uses the hyco-ws package which is for websockets only. The package you want to be using is hyco-https which allows listening to HTTP messages. This sample shows how to use Hybrid Connections with HTTP.

I had tried this example as well, but didn't see (or know how to access) the event data.

A little more digging I was able to find a way to data by adding the req.on lines:

        (req, res) => {
        console.log('request accepted: ' + req.method + ' on ' + req.url);

        req.on('data', function(chunk) {
            var bodydata = chunk.toString('utf8');
            console.log(bodydata);
        });

        res.setHeader('Content-Type', 'text/html');
        res.end('<html><head><title>Hey!</title></head><body>Relayed Node.js Server!</body></html>');
    });

This wrote out the event I was expecting to see to the console.

Upvotes: 2

Related Questions