
It is a Symfony Messenger transport for NATS JetStream. Point a DSN at a stream and a subject, route your messages to it in messenger.yaml, and run bin/console messenger:consume the way you would with AMQP or Redis.
This release is about configuration. Fifteen JetStream settings the client already supported are now transport options, and a group of fixes stops setup() from fighting a stream that is already running.
New options:
Stream policy: stream_retention, stream_discard, stream_duplicate_window, stream_compression, stream_description.
Access policy: stream_deny_delete, stream_deny_purge, stream_allow_direct, stream_allow_rollup_headers.
Stream limits: stream_max_message_size, stream_max_consumers.
Consumer: max_ack_pending, inactive_threshold, replay_policy.
Values are checked when the transport is built, so a typo in an enum fails at boot with a readable message instead of an odd server rejection later.
auto_setup:
Named after the option of the same name on the AMQP transport. With auto_setup=true the transport creates the stream and the consumer on the first send or get, so you do not have to run messenger:setup-transports. It is off by default, so nothing changes unless you ask for it. If NATS later reports the consumer as gone, for example after inactive_threshold removed an idle one, the transport rebuilds it and retries the pull.
Read the warning in the README before you turn it on. A durable consumer holds the acknowledgement state, so a replacement starts from the beginning and redelivers everything the stream still keeps, acknowledged messages included. Handlers need to be idempotent.
Fixes that matter if you already run this:
setup() no longer writes max_consumers and max_msg_size unless you set them. It used to send -1, which reset a message size cap with nothing in the output to say so, and made setup fail permanently on NATS 2.11 and older when the stream had a consumer limit.
replay_policy no longer breaks setup on an existing consumer. NATS refuses to change it in either direction, so the transport now writes the consumer's current policy back and applies your value only to a new one.
stream_deny_delete and stream_deny_purge are never cancelled. NATS can turn a deny on but never off, so the server's value is kept instead of failing every setup.
Lowering stream_max_age below the stream's de-duplication window used to fail. The window is now clamped, the same way the server does it when a stream is created.
379 unit tests, 99.7% statement coverage, and Behat scenarios against plain, TLS and mTLS NATS, now on both the oldest and the newest supported server.
No breaking changes, so 5.0.0 users can upgrade straight across. Requires PHP 8.2+, Symfony 7.2 or 8, NATS 2.9+ (2.12 for scheduled messages). MIT licensed.
composer require idct/symfony-nats-messenger
https://github.com/ideaconnect/symfony-nats-messenger
#php #symfony
