In the blog post Creating a Power BI Streaming Dataflows Solution the example C# app to send JSON messages to an Azure Event Hub was originally a Visual Studio C# Forms application. There is now another version of this application available which runs using Visual Studio Code and is a console application.

GitHub Link

Link to the C# app is here.

App Overview

The C# app generates a series of JSON messages to synthesis a user browsing an e-commerce website, viewing products, and putting products in their shopping basket. An example of the message is as follows:

{"UserID":5039,"EventType":"browseproduct","EventDateTime":"2021-08-01T09:00:00","ProductID":963,"URL":"/product/963","Device":"mobile","SessionViewSeconds":19}
{"UserID":5027,"EventType":"browseproduct","EventDateTime":"2021-08-01T09:00:00","ProductID":953,"URL":"/product/953","Device":"pc","SessionViewSeconds":11}
{"UserID":5081,"EventType":"putinbasket","EventDateTime":"2021-08-01T09:00:00","ProductID":879,"URL":"/product/879","Device":"pc","SessionViewSeconds":10}
{"UserID":5097,"EventType":"putinbasket","EventDateTime":"2021-08-01T09:00:00","ProductID":818,"URL":"/product/818","Device":"mobile","SessionViewSeconds":13}
{"UserID":5007,"EventType":"browseproduct","EventDateTime":"2021-08-01T09:00:00","ProductID":895,"URL":"/product/895","Device":"mobile","SessionViewSeconds":13}

App Logic

The C# app logic is as follows:

  • User Variables (provided by the user) specify the following:
    • connectingString: Endpoint=sb://<string>
    • eventHubNameWebVisits: name of event hub
    • dateValue: datetime to start messages from. E.G 2021-08-01 09:00:00
    • dateloopcounter: how many days to generate
    • minimumdailysessionblocks: set minimum randomly generated message blocks per day
    • maximumdailysessionblocks: set maximum randomly generated message blocks per day
    • minimumdailymessagesperblock: set minimum randomly generated messages per block
    • maximumdailymessagesperblock: set maximum randomly generated messages per block

For example if the following values were set:

  • dateValue: 2021-08-01 09:00:00
  • dateloopcounter: 1
  • minimumdailysessionblocks: 5
  • maximumdailysessionblocks: 10
  • minimumdailymessagesperblock: 50
  • maximumdailymessagesperblock: 100

Then the logic would:

  • Send messages for a single day
  • Generate a random number between 5 and 10 for the daily session blocks. E.G if the number was 7 then for each day there will be 7 blocks of messages sent with a time increment per block to differentiate each block
  • Generate a random number between 50 and 100 for the number of messages per block (this is generated per block loop). E.G if the number was 89 then the first block would have 89 messages. For each block (in this example 7) this random number would be re-generated.

Requirements

  • Visual Studio Code (from here)
  • C# extension
  • DotNet 5.0 SDK (from here)

Changes from Original Version

  • Console application therefore no front-end form
  • Generates a single JSON message per “Web Visit”
  • Removed SessionID and replaced with UserID
  • Added SessionVIewSeconds which is a metric to show how long the user spent looking at the specific product web page
  • Added an event called putinbasket to generate a message to show a user has put a product in their basket

References