Currently in testing: the GitHub code will be opened once complete.

Ticketing C# Library

GitHub NuGet

Repository

bash
powershell

Example

Basic Example

Create one broker at application startup and share it. wait=0 is one immediate attempt without a queue and the maximum wait is 255 seconds; lease is 1–250 seconds. The final minimum-work budget is required and may be zero. Clients round sub-second values up and reject out-of-range values or a budget greater than the normalized lease before sending; they never clamp.

csharp
using Ticketing;

var broker = TicketBroker.Connect("127.0.0.1:5225");
await broker.WaitReadyAsync(TimeSpan.FromSeconds(5));

await using var ticket = await broker.AcquireAsync(
    "key", TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(2));
var token = ticket.Token;
// In the same DB transaction: verify/update token high-water and perform the business write.

Automatic close/drop is a bounded best-effort release. Use the explicit release API when its result matters. The token must fence the protected database write in the same transaction.

Good to Know (Behavior)

  • Once any request byte may have been sent, losing the definitive response yields Indeterminate. The client never automatically resends A with the same owner, and the caller must not enter the critical section.
  • Cancellation before send is unsent; cancellation after possible send closes that session. If a grant token was parsed concurrently, the client attempts a bounded compensating exact-token release.
  • M, every E, and malformed/oversized/unknown responses are session-fatal. Unresolved possible-send acquires become Indeterminate.
  • B is a definitive capacity rejection and is returned immediately. There is no internal retry; the caller may later start a new acquire with a new owner and application-level backoff.
  • Explicit and compensating release retry the exact token only within an absolute 5-second deadline from call/enqueue. R is success, N means already gone or not current, and no final response is an error—not assumed success.
  • A Ticket is returned only with positive conservative time remaining and enough time for the required work budget. Work over 250 seconds is unsupported before send.
  • The token is mandatory database fencing: in the same DB transaction, reject token <= stored_high_water, update the high-water mark, and perform the business write before commit/rollback and release.

Security Options (Token · TLS)

Every option is optional. Token should match the server's client_tokens, and TLS has four modes: off / system trust store / a specified CA / skip verification (test only).

csharp
var broker = TicketBroker.CreateBuilder()
    .Addrs("10.0.0.1:5225", "10.0.0.2:5225", "10.0.0.3:5225")
    .Token("123")
    .Tls(TlsMode.SystemRoots)
    // .Tls(TlsMode.Ca("ca.crt"))
    // .Tls(TlsMode.InsecureSkipVerify)
    .Connect();

You can generate the server-side token, TLS, and cluster configuration on the Ticketing Server Deployment page.