Event Hubs

Send events to clients with Event Hubs

Download this Lecture Docs

In this video, we will look at how to send events to clients with Event Hubs.

Code

App

New-UDApp -Content {

    <#
        Connect-PSUEventHub -ComputerName http://localhost:5000 -Hub 'eventhub' -ScriptBlock {
            New-BurntToastNotification -Text $_
        }
    #>

    New-UDForm -Children {
        New-UDTextbox -Id 'message' -Label 'Message'
    } -OnSubmit {
        Send-PSUEvent -Hub 'eventhub' -Data $EventData.Message
        Show-UDToast 'Message sent!'
    }

    <#

        $AppToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiYWRtaW4iLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9oYXNoIjoiNzUzNTEyZDctOTE1Ni00NzkzLThlYzYtYzE1YjE3OTkzMGU3Iiwic3ViIjoiUG93ZXJTaGVsbFVuaXZlcnNhbCIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvcm9sZSI6IkFkbWluaXN0cmF0b3IiLCJuYmYiOjE2OTUwNzUzNjgsImV4cCI6MTcyNjY5Nzc2OCwiaXNzIjoiSXJvbm1hblNvZnR3YXJlIiwiYXVkIjoiUG93ZXJTaGVsbFVuaXZlcnNhbCJ9.7X9CBrtmvFKu5tEf2pBtSUMXytBm4n5V_GIo9W1BcoU'
        [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic.Core")
        Connect-PSUEventHub -ComputerName http://localhost:5000 -Hub 'securehub' -ScriptBlock {
            [Microsoft.VisualBasic.Interaction]::InputBox($_)
        } -AppToken $AppToken
    #>

    New-UDButton -Text 'Ask' -OnClick {
        $Connection = Get-PSUEventHubConnection | Where-Object UserName -EQ 'Admin' | Select-Object -Last 1
        $Result = Send-PSUEvent -Hub 'securehub' -Data 'What should be tell the server?' -ConnectionId $Connection.ConnectionId
        Show-UDToast $Result
    }
}