Download the PHP package thesis/nats without Composer
On this page you can find all versions of the php package thesis/nats. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package nats
Thesis Nats
Pure non-blocking (fiber based) strictly typed full-featured PHP driver for NATS.
Features
- NATS Core
- Publish-Subscribe
- Queues
- Request-Reply
- NATS JetStream
- Fetch Batch
- Fetch Bytes
- Fetch Immediate
- Push Consumer
- Pull Consumer
- Get message
- NATS KV
- Store key values
- Watch KV
- NATS ObjectStore
- Store objects
- Watch Object Store
- NATS CRDT
- Add Counter
- Get Counter
- Get Counters
- NATS Message Scheduler
- Single scheduled message
- NATS JetStream Batch Publishing
- Publish using
PublishBatch - Publish using
JetStream
- Publish using
- Nats Service Api
- Micro Service
- Endpoints
- Groups
Installation
Nats Core
The library implements the full functionality of NATS Core, including pub-sub, queues and request–reply.
Pub-Sub
Queues
Request-reply
Nats JetStream
JetStream is the built-in NATS persistence system. The library provides both JetStream entity management (streams, consumers) and message publishing/consumption capabilities.
Fetch Batch
You can request a specific number of messages at once using PullConsumer::fetch with FetchConfig::batch(number_of_messages). For example:
You can also configure the batch retrieval timeout and heartbeat settings using FetchConfig::maxWait and FetchConfig::heartbeat parameters.
Fetch Bytes
If you want to retrieve a batch of a specific size in bytes, you can use FetchConfig::bytes(byte_size):
And you can also configure the timeout and heartbeat settings.
Fetch Immediate
If you simply want to retrieve a batch of messages currently available in the stream, use FetchConfig::immediate():
Push Consumer
NATS offers two message delivery models: pull and push. Although the NATS documentation recommends the pull approach, for most PHP use cases push consumers are often preferable.
Similar to RabbitMQ, push consumers can be configured to avoid negative impacts on both the consumers and the messages themselves.
Key configuration parameters include maxAckPending, which limits the number of unacknowledged messages NATS will deliver before waiting (analogous to prefetch count in RabbitMQ),
and the ackPolicy. This setup allows you to scale message processing by increasing the number of consumers and distribute messages among them more evenly.
For example, if you want to process messages one by one with explicit acknowledgments, you would set maxAckPending=1 and ackPolicy=explicit.
Additionally, for push consumers, the deliverSubject parameter is mandatory, as it is this very parameter that distinguishes the push model from pull.
If you want to distribute messages from a single consumer across different subscriptions, you should use the deliverGroup parameter.
This enables you to scale processing across multiple consumer instances. This parameter functions identically to queueGroup in NATS Core.
Please refer to the push consumer configuration documentation to understand the purpose of each parameter.
Pull Consumer
Additionally, you can use PullConsumer::consume. This method handles message buffering, periodically requests the server and monitors timeouts to automatically request the next message batch.
Just like with push consumers, you can call pull directly on the Consumer object:
However, if you want to read messages with multiple consumers within the same process, you need to create a PullConsumer using Consumer::pulling(), and then create multiple consumer instances:
To stop all subscriptions, use Consumer::drain() or Consumer::stop().
You can control the number of requested messages per batch or the batch size using the PullConsumeConfig::maxMessages and PullConsumeConfig::maxBytes parameters respectively.
However, only one of these parameters can be set at a time.
Get message
NATS Key Value Store
JetStream, the persistence layer of NATS, not only allows for the higher qualities of service and features associated with 'streaming', but it also enables some functionalities not found in messaging systems like Key Value Store.
Store key values
Watch KV
NATS Object Store
JetStream, the persistence layer of NATS, not only allows for the higher qualities of service and features associated with 'streaming', but it also enables some functionalities not found in messaging systems like Object Store.
Store objects in the buckets
Watch Object Store
NATS CRDT
Distributed Counter CRDT. A Stream can opt in to supporting Counters which will allow any subject to be a counter. All subjects in the stream must be counters. See ADR-49 for details.
Add Counter
Get Counter
Get Counters
NATS Message Scheduler
Delayed Message Scheduling. The AllowMsgSchedules stream configuration option allows the scheduling of messages. Users can use this feature for delayed publishing/scheduling of messages.
See ADR-51 for details.
Single scheduled message
NATS JetStream Batch Publishing
The AllowAtomicPublish stream configuration option allows to atomically publish N messages into a stream. See ADR-50 for details.
Publish using PublishBatch
Publish batch using JetStream
Nats Service Api
This is implementation of ADR-32.
The core of the Micro component is the Service. A Service aggregates endpoints for handling application logic. Services are named and versioned. You create a Service using the Client::createService(), passing in the Service configuration.
Micro Service
Service endpoints
After a service is created, endpoints can be added. By default, an endpoint is available via its name.
If the subject for the endpoint is more complex (e.g., contains a * or >), the subject can be specified separately from the name.
Groups
Endpoints can also be aggregated using groups. A group represents a common subject prefix used by all endpoints associated with it.
License
The MIT License (MIT). Please see License File for more information.
All versions of nats with dependencies
ext-filter Version *
amphp/amp Version ^3.1.1
amphp/byte-stream Version ^2.1
amphp/parser Version ^1.1
amphp/pipeline Version ^1.2
amphp/socket Version ^2.3.1
cuyz/valinor Version ^1.15 || ^2.3
revolt/event-loop Version ^1.0.8
thesis/package-version Version ^0.1.2
thesis/time-span Version ^0.2.3