Kafka Adapter Validation
Applies to
@connectum/events-kafka1.3.0.
Does this apply to you?
You need to act if KafkaAdapter() receives any of these, because it now throws when it is called instead of failing later:
- no options object (
KafkaAdapter(undefined)used to throwCannot use 'in' operatorfrom inside the adapter); brokersthat is not an array of non-empty strings, or is empty (brokers: []used to fail atconnect();brokers: 'localhost:9092'was accepted);- a
clientIdthat is an empty string; - a
consumerOptions.sessionTimeoutthat is not a finite number above 3000 ms (the client refused it at the firstsubscribe()); - a
retry.retriesthat is not a non-negative integer, or aretry.maxRetryTime,initialRetryTime,factorormultiplierthat is negative or not finite; - a
sasl.mechanismoutsideplain,scram-sha-256,scram-sha-512,oauthbearerandaws.
If none of these applies, nothing changes for you. Valid values behave as before.
Required changes
- Pass
brokersas an array:['kafka-1:9093', 'kafka-2:9093']. A function that resolves the list is not part of the adapter's types and is no longer accepted. - Remove an empty
clientId, or give it a name. Without it the adapter uses the service identifier of the event bus, orconnectum. - Raise
consumerOptions.sessionTimeoutabove 3000. Brokers also enforce their own minimum (group.min.session.timeout.ms, 6000 by default in Apache Kafka). - Use one of the five SASL mechanisms in the typed
sasloption. A mechanism that only the client library implements goes inclientOptions.sasl.
typescript
// Before: accepted, failed at connect()
KafkaAdapter({ brokers: [] });
// After: throws RangeError "KafkaAdapter: brokers must contain at least one broker address"
KafkaAdapter({ brokers: ['kafka-1:9092'] });Behavior that changed without an option
- With
consumerOptions.allowAutoTopicCreation: true,subscribe()waits up to ten seconds for the broker to create a missing topic. Without the option it rejects with an error that names the topic. See topics that do not exist yet. - Overlapping
connect()calls share one attempt, and error messages for an unreachablelocalhostand for an invalid topic name now carry the reason and the topic. See connection errors.
Verify the upgrade
Create the adapter in a startup test: an invalid option throws at that call, before any connection is made.