Skip to main content

1E 8.1 (on-premises)

Offloading data to an external target

How to set up a Tachyon consumer to offload data to an external target and then invoke an instruction which sends the data to that target.

The Tachyon Platform supports the execution of instructions with the option to offload the instruction results to a different API. When this is specified, the results from an instruction are not stored in the Tachyon responses database. Instead, they are sent to an API device which has been defined for the appropriate consumer specified when the instruction was invoked.

Exploring offloading

To explore this feature, we start by configuring one of the existing Tachyon consumers to support an optional offloading device.

Note

In a production environment you should create a new consumer to support this functionality. However, in a test lab you can override the functionality of an existing consumer if desired.

From the settings application, modify the RunInstructionUI consumer to add an offload target URL as shown below. Change the server name to be the name of the machine on which you are going to run the test PowerShell cmdlet.

Also disable Use Windows Authentication.

233276696.png

We will now stand up a web server on this device. Take the PowerShell code included as an attachment to this page and run in PowerShell under an administrator prompt.

Note

Change the server name appropriately to match the above consumer configuration. If you have something running already bound to port 80, you can always set a different port, and be sure to also configure the consumer appropriately.

If the Tachyon server is not running on the same machine as the PowerShell script, you may need to open an inbound port on your firewall.

# This is a super **SIMPLE** example of how to create a very basic powershell webserver
 
# Http Server
$http = New-Object System.Net.HttpListener
 
# Hostname and port to listen on
$http.Prefixes.Add("http://urth-dev.urth.local:80/") # change this to match the device you're running on.
 
# Start the Http Server
$http.Start()
 
# Log ready message to terminal
if ($http.IsListening)
{
    write-host " HTTP Server Ready!  " -f 'black' -b 'gre'
}
 
# INFINITE LOOP
# Used to listen for requests
while ($http.IsListening)
{
    # Get Request Url
    # When a request is made in a web browser the GetContext() method will return a request object
    # Our route examples below will use the request object properties to decide how to respond
    $context = $http.GetContext()
 
    if ($context.Request.RawUrl -eq '/Kill')
    {
        write-host "Kill received, exiting"
        break
    }
 
    if ($context.Request.HttpMethod -eq 'POST' -and $context.Request.RawUrl -eq '/Foo')
    {
        write-host "post"
        $streamReader = New-Object System.IO.StreamReader -ArgumentList $context.Request.InputStream
        $FormContent = $streamReader.ReadToEnd()
 
        # We can log the request to the terminal
        write-host "$($context.Request.UserHostAddress)  =>  $($context.Request.Url)" -f 'mag'
        Write-Host $FormContent -f 'Green'
       
        $buffer = [System.Text.Encoding]::UTF8.GetBytes("OK")
        $context.Response.ContentLength64 = $buffer.Length
        $context.Response.OutputStream.Write($buffer, 0, $buffer.Length) #stream to browser
        $context.Response.OutputStream.Close() # close the response
    }
 
    # powershell will continue looping and listen for new requests...
}
 
# here if we break from the loop (by receiving a Kill request)
$http.stop()
 
# Note:
# To end the loop you have to kill the powershell terminal. ctrl-c wont work :/



You should now see that the web server is ready to accept requests.

233276695.png

Note

The server will remain running until you terminate it. You cannot terminate it with ctrl+C, so use:

curl http://urth-dev.urth.local/kill

which will terminate the web server if you wish to shut it down.

With the web server now running, first change the default consumer to RunInstructionUI, then use the invoke-tachyoninstruction cmdlet to invoke an instruction against that consumer, specifying that the results should be offloaded.

233276694.png

You will see the offloaded data sent to the listening web server as shown below.

233276693.png

Note

If you invoke an instruction and specify the -Offload parameter, then if the listening device is not accepting data, the Tachyon Platform will not update the received count for the instruction statistics. This will cause the invoke-tachyoninstruction cmdlet to wait until a timeout occurs. You can of course interrupt the cmdlet with ctrl+C at any time.