Hololens + Azure eventhub real time data

Looking for some assistance here. I have been chopping away for over a week now and seem to go in circles. I can get this to work in a none unity app no problem.

setup:
unity 2018.1
VS 2017
Hololens
Azure account(setup to receive and transmit realtime data)

Steps:

  1. Create Hololens Unity app per the Microsoft instructions : Install the tools - Mixed Reality | Microsoft Learn
  2. setup a simple scene with basic holographic capabilities + internet/client/server compatibility.
  3. copy the Azure sample code from : azure-event-hubs/samples/DotNet/Microsoft.Azure.EventHubs/SampleEphReceiver at master · Azure/azure-event-hubs · GitHub
  4. Translate it to be Unity acceptable
  5. build in to App folder and open UWP project.
  6. build for hololens and see that while the scene appears that after a short time the async fails and tosses an error.

So here is what I think is happening.

  1. I call the Async function from Start().
  2. This creates a new EventProcessorHost
  3. inside the async is a Try/Catch that runs the SimpleEventProcessor script
  4. I change the text readout in immersive view to show " TEMPERATURE: " as a place holder
  5. The Try does calls simpleeventprocessor but only the Open and Close functions. I get no data.
  6. Scratch my head and try again

The App deploys fine to Hololens and I can see in immersive view that the “Receiver” script is working as it updates the UI TextMesh, however I don’t get the data from eventhub.

I used the same code in a VS console app and I retrieve the data correctly.

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.EventHubs;
#if UNITY_UWP
using Microsoft.Azure.EventHubs.Processor;
#endif
using UnityEngine;

public class Receiver : MonoBehaviour
{
    private const string EventHubConnectionString = "XXXXXX";
    private const string EventHubName = "XXXXXX";
    private const string StorageContainerName = "XXXXXX";
    private const string StorageAccountName = "XXXXXX";
    private const string StorageAccountKey = "XXXXXXX";

    private static readonly string StorageConnectionString = string.Format("XXXXXX");

    public static TextMesh textMesh;
    public static string data;

    public async void Start()
    {
        textMesh = gameObject.GetComponent<TextMesh>();
        textMesh.text = "Temp: " ;
        textMesh.fontSize = 18;
        //await MainAsync();
        await RunTheMethod();
    }

    public async Task RunTheMethod()
    {
        while (true)
        {
        await MainAsync();
        }
    }


    public static async Task MainAsync()
    {
#if UNITY_UWP
        var eventProcessorHost = new EventProcessorHost(
            EventHubName,
            PartitionReceiver.DefaultConsumerGroupName,
            EventHubConnectionString,
            StorageConnectionString,
            StorageContainerName);
            try
            {
                textMesh.text += "\ntry: ";

                // Registers the Event Processor Host and starts receiving messages
                await eventProcessorHost.RegisterEventProcessorAsync<SimpleEventProcessor>();
                data = SimpleEventProcessor.tempData;
                textMesh.text += "\nTemperature: " + data;
            }

            catch
            {
                textMesh.text = "ERROR: ";

            }
            //textMesh.text += "\n Outof TRy/Catch: " + data;

            // Disposes of the Event Processor Host
            await eventProcessorHost.UnregisterEventProcessorAsync();
            data = SimpleEventProcessor.tempData;

            textMesh.text += "\nreturned to receiver: " + data.ToString();
#endif
    }
#if UNITY_UWP
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.EventHubs;
using Microsoft.Azure.EventHubs.Processor;
using UnityEngine;

public class SimpleEventProcessor : IEventProcessor
{
    public static string tempData;

    public Task CloseAsync(PartitionContext context, CloseReason reason)
    {
        return Task.CompletedTask;
    }

    public Task OpenAsync(PartitionContext context)
    {
        tempData += "\n OpenAsync";

        return Task.CompletedTask;
    }

    public Task ProcessErrorAsync(PartitionContext context, Exception error)
    {
        tempData += "\nprocessError";
        return Task.CompletedTask;
    }

    public Task ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> messages)
    {
        tempData += "\n processing";
        foreach (var eventData in messages)
        {
            var data = Encoding.UTF8.GetString(eventData.Body.Array, eventData.Body.Offset, eventData.Body.Count);
            tempData += "\n SUCCESS" ;
        }

        return context.CheckpointAsync();
    }
}
#endif

I am trying to receive data from azure event hub in unity…able to send but not receive. Does anyone tried the same would be really helpful?

Hi,

I have the same problem 3 years later :-(, did you resolve the problem?

I can use Eventhub in the Unity 3d editor, receive the events. Also, I can deploy the project into HoloLens and works all but Eventhub receive events functionality.

Did you find the problem?

Thanks and regards.