Skip to content

About

Elixir/OTP client for the Lightstreamer TLCP real-time streaming protocol over WebSockets

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

11 Commits

Folders and files

Repository files navigation

Lightstreamer

Hex.pm Docs CI

An unofficial Elixir/OTP client for Lightstreamer, implementing TLCP 2.5.0 over WebSocket.

Designed for long-lived, real-time streaming connections:

  • subscription-based data delivery using ordinary Elixir messages
  • transparent server-driven session rebinds
  • automatic reconnection with capped exponential backoff
  • automatic restoration of subscriptions after connection loss
  • straightforward integration with OTP processes and supervision trees

The client is vendor-agnostic: it implements the published TLCP protocol rather than any particular Lightstreamer deployment. Adapter sets, item names, field semantics and authentication formats are defined by the server being connected to.

Note

"Lightstreamer" is a trademark of Lightstreamer Srl. This project is not affiliated with or endorsed by Lightstreamer Srl.

Installation

Add lightstreamer to your dependencies in mix.exs:

def deps do
  [
    {:lightstreamer, "~> 0.1"}
  ]
end

Quick start

Stream live stock quotes from Lightstreamer's public demo server:

{:ok, session} =
  Lightstreamer.connect(
    "https://push.lightstreamer.com",
    adapter_set: "DEMO"
  )

{:ok, sub} =
  Lightstreamer.subscribe(
    session,
    data_adapter: "QUOTE_ADAPTER",
    items: ["item1", "item2", "item3"],
    fields: ["stock_name", "last_price", "time"]
  )

for _ <- 1..10 do
  receive do
    {:lightstreamer, ^sub, {:update, %Lightstreamer.Update{} = update}} ->
      IO.inspect(update.values, label: update.item)
  end
end

Lightstreamer.close(session)

The first updates are the subscription snapshot, followed by live changes as the simulated market moves.

Updates are delivered as ordinary Elixir messages, so consumers can integrate the stream directly into normal OTP processes.

How it fits into an OTP application

A subscription update is delivered in this form:

{:lightstreamer, subscription, {:update, %Lightstreamer.Update{} = update}}

That means a real application can consume updates inside a GenServer, supervision tree, Broadway pipeline, or another OTP process without needing a callback framework specific to this library.

For example:

def handle_info(
      {:lightstreamer, _subscription, {:update, %Lightstreamer.Update{} = update}},
      state
    ) do
  process_update(update)

  {:noreply, state}
end

This keeps the Lightstreamer connection at the edge of the application while allowing the rest of the system to use ordinary Elixir message passing and OTP patterns.

Connection recovery

Sessions recover automatically by default.

Server-directed rebinds are handled transparently. If the underlying connection is lost, the session reconnects using capped exponential backoff and restores its active subscriptions.

This allows consumers to treat the Lightstreamer session as a long-lived resource rather than rebuilding connection and subscription state themselves.

Features

  • TLCP 2.5.0 over WebSocket
  • session creation and lifecycle management
  • subscription-based streaming
  • snapshot and live update delivery
  • ordinary Elixir message delivery
  • transparent server-driven session rebinds
  • automatic reconnection
  • capped exponential backoff
  • automatic subscription restoration after connection loss
  • structured Lightstreamer.Update messages
  • OTP-friendly integration

See the Lightstreamer module documentation for the full API, connection options and delivery-message contract.

Why this library?

Lightstreamer provides a mature protocol for real-time, subscription-based data delivery.

This library provides an Elixir-native client that maps that streaming model onto ordinary OTP processes and message passing.

The implementation deliberately stays close to the TLCP protocol so it can be used with different Lightstreamer servers without embedding assumptions about a particular vendor integration, adapter set, item naming scheme, field semantics or authentication format.

Typical use cases

The library is suitable anywhere an Elixir application needs to consume a long-lived real-time Lightstreamer feed, including:

  • market-data and pricing streams
  • sports and betting feeds
  • telemetry
  • dashboards
  • live operational data
  • event-driven backend systems

Application-specific semantics remain outside the library; it is responsible for the Lightstreamer transport, session and subscription lifecycle.

Documentation

API documentation is available on HexDocs:

https://hexdocs.pm/lightstreamer

The main entry point is:

Lightstreamer

Development

Clone the repository and install dependencies:

git clone https://github.com/ktec/lightstreamer.git
cd lightstreamer
mix deps.get

Run the test suite:

mix test

Run the formatter check:

mix format --check-formatted

License

Apache-2.0 — see the LICENSE file.

About

Elixir/OTP client for the Lightstreamer TLCP real-time streaming protocol over WebSockets

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages