Are you an LLM? You can read better optimized documentation at /en/migration/events-amqp-options.md for this page in Markdown format
events-amqp Option Validation
Applies to
@connectum/events-amqp1.3.0.
Does this apply to you?
You need to act if your service passes any of the following to AmqpAdapter() or relies on the behavior below:
- a
topologyModethat is not exactly"assert","check"or"skip"("CHECK","Skip", a typo,null,""); - an
exchangeTypethat is not"topic","direct","fanout"or"headers"; consumerOptions.prefetchthat is not an integer from 0 to 65535;queueOptions.messageTtlorqueueOptions.maxLengththat is negative, fractional or not a number;- a finite
recovery.jitterorpublishRetry.jitteroutside 0 to 1 (NaNand the infinities keep using the default); - the same
exchangeTypeortopologyModevalues passed toFakeAmqpAdapterin tests, which now throws as well; recoveryorpublishRetrythat is neither a boolean nor an object, or a non-numericpublishRetry.maxRetries;- a
serialization.encodeorserialization.decodethat is not a function, or acontentTypethat is not a string; - a handler that reads
event.metadatavalues that came from an AMQP table or array; - code that expects
publish()to reject an unencodable routing key,messageIdortimestampwithAmqpConnectionError.
If none of these applies, nothing changes.
Required changes
AmqpAdapter() now throws a TypeError (wrong type or an unsupported value) or a RangeError (a number out of range) at the call, and the message names the option and the accepted values. Before, each of these was accepted:
- An unknown
topologyModeacted as"assert", so a service meant to leave the topology to the operator ("check","skip") declared the exchange and queues itself. Spell the mode exactly. - An unknown
exchangeTypemadeconnect()wait in the retry loop for the broker to accept it. Use one of the four types. - An out-of-range
prefetch,messageTtlormaxLengthfailed atsubscribe()with a raw error from amqplib or the broker. A finitejitterabove 1 was clamped to 1 without a word. Pass a value inside the documented range. - A missing
optionsargument failed withCannot read properties of undefined. Pass an object.
typescript
// Before: accepted, and acted as "assert"
AmqpAdapter({ url, topologyMode: 'CHECK' });
// After
AmqpAdapter({ url, topologyMode: 'check' });1
2
3
4
5
2
3
4
5
Values with a documented fallback are unchanged: publishTimeoutMs, recovery.initialConnectMaxRetries, and fractional or negative retry counts.
Behavior that changed without an option
- Table and array headers. For a message from an external publisher, a header that is an AMQP table reaches
ctx.metadataas JSON text ({"a":1}), not"[object Object]", and an array as[1,"a"], not1,a. Scalars are unchanged. If you parsed the old array form, parse JSON instead. - Invalid publish arguments. A routing key or
messageIdover 255 bytes, or atimestampthat is NaN, negative, fractional or infinite, rejectspublish()with amqplib'sTypeErrororRangeErrorinstead ofAmqpConnectionError, andpublishRetryno longer repeats it. If you branch onAmqpConnectionErrorto decide on a republish, such a call is now outside that branch: it can never succeed.
Verify the upgrade
Create the adapter in a startup test: an invalid option throws at that call.