Skip to content

HTTP Streaming Adapter

This is a synthetic example for a device with REST commands, a long-lived event stream, and periodic health polling.

Event Flow

alert stream -> stream manager -> transport callback -> event routing -> Thing function methods

Command Flow

PQ command -> generated dispatcher -> handler -> protocol queue -> HTTP request

Transport Sketch

public partial class Transport
{
    private HttpClient? _http;

    public HttpClient Http => _http ?? throw new InvalidOperationException();
}

Protocol Sketch

public partial class Protocol
{
    public Task<XDocument> GetStatus() => Enqueue(async _ =>
    {
        var xml = await Transport.Http.GetStringAsync("/status");
        return XDocument.Parse(xml);
    });
}

Notes

  • serialize protocol access unless the device explicitly supports concurrent requests
  • keep parsing, routing, and command logic separate