0
votes

I'm testing out Azure Event Grid with a Azure Relay, Hybrid Connection handler. It's not working for me.

I can see messages being published to Azure Event Grid. So far so good.

I've set up a subscription to the Event Grid topic and I've configured it to send events to a handler specified as an Azure Relay with a Hybrid Connection endpoint.

Looking at the metrics for the subscription with the Hybrid Connection handler, I see the following telemetri:

  • Matched Events
  • Delivery Failed
  • Expired Events

… but I see no Delivery Succeeded event???

Also, the Hybrid Connection listener (just a simple Console App) connected to the Azure Relay receives nothing. I've tested the listener by sending some test messages directly to the Relay and that works fine.

The logical conclusion, is that the events published to the Event Grid are not being delivered probably to the Relay Hybrid Connection handler. But why? There are not that many parameters, so I not sure what I'm doing wrong. It seems rather straight forward to configure this.

I'm a the point where I'm beginning to believe that the Event Grid / Hybrid Connection scenario is currently not working. It is in preview after all, so that could explain it.

I know that there is not much to go on here, but I was hoping that others might have some experience with this?

The issue still remains. The issues seems to be related to the formating of the json being passed from the Event Grid Subscription to the Hybrid Connect.

Update

I finally had some time to look more carefully into this.

I set up the Event Grid Tester and every time the Event Grid recieves a message I can see this error in the log:

HybridConnection: Message processing failed - Unable to cast object of type 'Newtonsoft.Json.Linq.JValue' to type 'Newtonsoft.Json.Linq.JObject'.

I'm still not able to fix this, as I do not control the message. The message is generated by Azure Logic App and send to the Event Grid using the Event Grid connector. The Event Grid Connector in Azure Logic Apps is in preview, so that might explain the challenges I'm seeing.

enter image description here

enter image description here

2
Subscription with Hybrid Connection endpoint is working very well. I do recommend to look at this simple-http server/client implementation for test purposes, github.com/Azure/azure-relay/tree/master/samples/…Roman Kiss
I think maybe the issue is introduced by Logic App, producing some json that causes challenges further down the chain. See update.1iveowl
see my answer, where using a http POST to the hybrid connection url can help you with the hybridconnection subscriber.Roman Kiss

2 Answers

1
votes

I've successfully tested Event Grid subscriber locally using Azure Relay and documented it here. It is based on a sample Microsoft is providing and implemented using WCF variant of client, not the .NET Standard version.

1
votes

you can simulate an Event Grid message to the HybridConnection url using a http POST request:

POST https://{myNamespace}.servicebus.windows.net/{myHybridConnectionName}

headers:
    content-type: application/json
    x-ms-version: 2015-07-08
    Aeg-Event-Type: Notification
    Authorization: SharedAccessSignature sr=xxx&sig=xxxx&se=11111111&skn=xxxxx

body:
    {
       "id": "123456",
       "eventTime": "2018-07-22T13:09:07.5164877Z",
       "eventType": "recordInserted",
       "dataVersion": "1.0",
       "metadataVersion": "1",
       "subject": "/myapp/vehicles/motorcycles",
       "data": {
          "make": "Ducati",
          "model": "Monster"
       }
   }

Note, that the sasToken for authorization header can be copied from the Azure Event Grid Tester log panel, when the HybridConnection has been opened.

the other option is to generate it by the following code:

using Microsoft.Azure.Relay;
// ... 
var tokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider("hybridconnectionPolicyName", "hybridconnectionPrimaryKey");
var token = tokenProvider.GetTokenAsync("https://{myNamespace}.servicebus.windows.net/{myHybridConnectionName}", TimeSpan.FromDays(10)).Result.TokenString;