Skip to content

v1 - Initial stable version

Choose a tag to compare

@bpacholek bpacholek released this 20 Mar 07:52
· 571 commits to main since this release

First stable release of idct/php-nats-jetstream-client — an async-first NATS and JetStream client for PHP 8.2+.

Highlights

  • Built on Amp 3.x — fully async, non-blocking I/O with no legacy blocking calls
  • Comprehensive JetStream support: streams, consumers (pull/push/ordered/ephemeral), KeyValue, ObjectStore
  • Microservices framework with discovery, schema validation, grouped endpoints, and observability hooks
  • Full authentication coverage: token, user/pass, TLS (mTLS), NKey (Ed25519), JWT + nonce signing, .creds file parsing
  • Resilient reconnect with exponential backoff, server rotation, and subscription replay

Core NATS

  • Publish / subscribe with callback and queue group support
  • Request / reply with timeout and cancellation
  • Polling subscribe API (SubscriptionQueue with fetch(), next(), fetchAll())
  • Graceful drain (unsubscribe all, deliver pending, close)
  • no_echo support
  • max_payload enforcement and no_responders negotiation
  • Subject validation against NATS naming rules
  • Configurable slow consumer policy (DropOldest, DropNewest, Error)

Connection & Resilience

  • Reconnect with exponential backoff, jitter, and max delay cap
  • Server rotation across configured endpoints
  • Subscription replay with validation on reconnect
  • Ping/pong heartbeat with maxPingsOut dead-connection detection
  • Async INFO updates during connection lifetime
  • Connect timeout (connectTimeoutMs) and request timeout (requestTimeoutMs)
  • tlsHandshakeFirst TLS option

JetStream

  • Stream CRUD: create, update, get, delete, purge (with subject filter), list
  • Consumer CRUD: durable + ephemeral, pull + push, list, pause/resume
  • Pull consumers: fetchNext, fetchBatch, ACK / NAK / delayed NAK / TERM / in-progress
  • Push consumers with heartbeat and flow-control handling
  • Ordered consumers with automatic sequence tracking and gap recovery
  • Pull consumer batching/iteration chain API (PullConsumerIterator)
  • JetStream publish ACK
  • Direct message get from stream
  • Scheduled publish (@at support via Schedule::at() / Schedule::atTimestamp())
  • Typed configuration enums: RetentionPolicy, StorageBackend, DiscardPolicy, DeliverPolicy, AckPolicy, ReplayPolicy
  • Stream mirroring and sourcing configuration helpers (StreamSource)
  • Republish and subject transform configuration helpers (Republish, SubjectTransform)

KeyValue

  • Bucket lifecycle with history, TTL, and storage options
  • put / get / update / delete / purge
  • watch with subject filter
  • getAll / getStatus

ObjectStore

  • Bucket lifecycle (create / delete)
  • put / get / delete / list / watch
  • Chunked uploads for large objects
  • SHA-256 digest verification
  • Streaming to callback (getToCallback)

Microservices

  • Service registration with PING / INFO / STATS / SCHEMA discovery
  • Grouped endpoint hierarchy
  • Enriched endpoint stats: request count, error count, last error, processing time
  • Stats reset API
  • Opt-in schema validation with built-in BasicJsonSchemaValidator
  • Handler adapters: callable, object (ServiceEndpointHandlerInterface), class-string
  • Request lifecycle observers with correlation ID extraction
  • Standardized error envelopes
  • run() helper for start + process loop + auto-stop

Authentication

  • Token auth
  • Username / password auth
  • TLS with CA, client cert/key, peer name override, verify toggle
  • JWT + nonce signing (NkeySeedSigner)
  • Standalone NKey authentication (Ed25519 challenge signing)
  • Credentials file parser (CredentialsParser::fromFile())

Protocol & Safety

  • Max frame size limit in protocol parser (DoS protection)
  • Wire input validation: length checks, negative values, framing boundaries
  • CR/LF injection prevention in wire headers
  • Strict typing throughout (declare(strict_types=1))

Requirements

  • PHP 8.2+
  • ext-sodium (for NKey/JWT authentication)
  • Amp 3.x, Amp Socket 2.x

Installation

composer require idct/php-nats-jetstream-client