@ohos-ports/confluentinc-kafka-javascript 1.10.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +457 -0
- package/LICENSE.kafkajs +31 -0
- package/LICENSE.node-rdkafka +25 -0
- package/LICENSE.txt +20 -0
- package/README.md +133 -0
- package/binding.gyp +184 -0
- package/build/Release/confluent-kafka-javascript.node +0 -0
- package/build/deps/librdkafka++.so.1 +0 -0
- package/build/deps/librdkafka.Makefile +6 -0
- package/build/deps/librdkafka.so.1 +0 -0
- package/build/deps/librdkafka.target.mk +55 -0
- package/deps/librdkafka/.clang-format +136 -0
- package/deps/librdkafka/.clang-format-cpp +103 -0
- package/deps/librdkafka/.dir-locals.el +10 -0
- package/deps/librdkafka/.formatignore +35 -0
- package/deps/librdkafka/.gdbmacros +19 -0
- package/deps/librdkafka/CHANGELOG.md +2477 -0
- package/deps/librdkafka/CMakeLists.txt +291 -0
- package/deps/librdkafka/CODE_OF_CONDUCT.md +46 -0
- package/deps/librdkafka/CONFIGURATION.md +212 -0
- package/deps/librdkafka/CONTRIBUTING.md +431 -0
- package/deps/librdkafka/Doxyfile +2375 -0
- package/deps/librdkafka/INTRODUCTION.md +2752 -0
- package/deps/librdkafka/LICENSE +26 -0
- package/deps/librdkafka/LICENSE.cjson +22 -0
- package/deps/librdkafka/LICENSE.crc32c +28 -0
- package/deps/librdkafka/LICENSE.fnv1a +18 -0
- package/deps/librdkafka/LICENSE.hdrhistogram +27 -0
- package/deps/librdkafka/LICENSE.lz4 +26 -0
- package/deps/librdkafka/LICENSE.murmur2 +25 -0
- package/deps/librdkafka/LICENSE.nanopb +22 -0
- package/deps/librdkafka/LICENSE.opentelemetry +203 -0
- package/deps/librdkafka/LICENSE.pycrc +23 -0
- package/deps/librdkafka/LICENSE.queue +31 -0
- package/deps/librdkafka/LICENSE.regexp +5 -0
- package/deps/librdkafka/LICENSE.snappy +36 -0
- package/deps/librdkafka/LICENSE.tinycthread +26 -0
- package/deps/librdkafka/LICENSE.wingetopt +49 -0
- package/deps/librdkafka/LICENSES.txt +625 -0
- package/deps/librdkafka/Makefile +125 -0
- package/deps/librdkafka/README.md +201 -0
- package/deps/librdkafka/README.win32 +26 -0
- package/deps/librdkafka/STATISTICS.md +624 -0
- package/deps/librdkafka/configure +214 -0
- package/deps/librdkafka/configure.self +341 -0
- package/deps/librdkafka/dev-conf.sh +123 -0
- package/deps/librdkafka/lds-gen.py +73 -0
- package/deps/librdkafka/mainpage.doxy +40 -0
- package/deps/librdkafka/mklove/Makefile.base +329 -0
- package/deps/librdkafka/mklove/modules/configure.atomics +144 -0
- package/deps/librdkafka/mklove/modules/configure.base +2484 -0
- package/deps/librdkafka/mklove/modules/configure.builtin +70 -0
- package/deps/librdkafka/mklove/modules/configure.cc +186 -0
- package/deps/librdkafka/mklove/modules/configure.cxx +8 -0
- package/deps/librdkafka/mklove/modules/configure.fileversion +65 -0
- package/deps/librdkafka/mklove/modules/configure.gitversion +29 -0
- package/deps/librdkafka/mklove/modules/configure.good_cflags +18 -0
- package/deps/librdkafka/mklove/modules/configure.host +132 -0
- package/deps/librdkafka/mklove/modules/configure.lib +49 -0
- package/deps/librdkafka/mklove/modules/configure.libcurl +99 -0
- package/deps/librdkafka/mklove/modules/configure.libsasl2 +36 -0
- package/deps/librdkafka/mklove/modules/configure.libssl +147 -0
- package/deps/librdkafka/mklove/modules/configure.libzstd +58 -0
- package/deps/librdkafka/mklove/modules/configure.parseversion +95 -0
- package/deps/librdkafka/mklove/modules/configure.pic +16 -0
- package/deps/librdkafka/mklove/modules/configure.socket +20 -0
- package/deps/librdkafka/mklove/modules/configure.zlib +61 -0
- package/deps/librdkafka/mklove/modules/patches/README.md +8 -0
- package/deps/librdkafka/mklove/modules/patches/libcurl.0000-no-runtime-linking-check.patch +11 -0
- package/deps/librdkafka/mklove/modules/patches/libssl.0000-osx-rand-include-fix-OpenSSL-PR16409.patch +56 -0
- package/deps/librdkafka/service.yml +182 -0
- package/deps/librdkafka/src/CMakeLists.txt +379 -0
- package/deps/librdkafka/src/Makefile +105 -0
- package/deps/librdkafka/src/README.lz4.md +30 -0
- package/deps/librdkafka/src/cJSON.c +3191 -0
- package/deps/librdkafka/src/cJSON.h +306 -0
- package/deps/librdkafka/src/crc32c.c +430 -0
- package/deps/librdkafka/src/crc32c.h +38 -0
- package/deps/librdkafka/src/generate_proto.sh +66 -0
- package/deps/librdkafka/src/librdkafka_cgrp_synch.png +0 -0
- package/deps/librdkafka/src/lz4.c +2727 -0
- package/deps/librdkafka/src/lz4.h +842 -0
- package/deps/librdkafka/src/lz4frame.c +2078 -0
- package/deps/librdkafka/src/lz4frame.h +692 -0
- package/deps/librdkafka/src/lz4frame_static.h +47 -0
- package/deps/librdkafka/src/lz4hc.c +1631 -0
- package/deps/librdkafka/src/lz4hc.h +413 -0
- package/deps/librdkafka/src/nanopb/pb.h +917 -0
- package/deps/librdkafka/src/nanopb/pb_common.c +388 -0
- package/deps/librdkafka/src/nanopb/pb_common.h +49 -0
- package/deps/librdkafka/src/nanopb/pb_decode.c +1727 -0
- package/deps/librdkafka/src/nanopb/pb_decode.h +193 -0
- package/deps/librdkafka/src/nanopb/pb_encode.c +1000 -0
- package/deps/librdkafka/src/nanopb/pb_encode.h +185 -0
- package/deps/librdkafka/src/opentelemetry/common.pb.c +32 -0
- package/deps/librdkafka/src/opentelemetry/common.pb.h +170 -0
- package/deps/librdkafka/src/opentelemetry/metrics.options +2 -0
- package/deps/librdkafka/src/opentelemetry/metrics.pb.c +67 -0
- package/deps/librdkafka/src/opentelemetry/metrics.pb.h +966 -0
- package/deps/librdkafka/src/opentelemetry/resource.pb.c +12 -0
- package/deps/librdkafka/src/opentelemetry/resource.pb.h +58 -0
- package/deps/librdkafka/src/queue.h +850 -0
- package/deps/librdkafka/src/rd.h +592 -0
- package/deps/librdkafka/src/rdaddr.c +255 -0
- package/deps/librdkafka/src/rdaddr.h +202 -0
- package/deps/librdkafka/src/rdatomic.h +262 -0
- package/deps/librdkafka/src/rdavg.h +260 -0
- package/deps/librdkafka/src/rdavl.c +210 -0
- package/deps/librdkafka/src/rdavl.h +250 -0
- package/deps/librdkafka/src/rdbase64.c +200 -0
- package/deps/librdkafka/src/rdbase64.h +43 -0
- package/deps/librdkafka/src/rdbuf.c +1884 -0
- package/deps/librdkafka/src/rdbuf.h +375 -0
- package/deps/librdkafka/src/rdcrc32.c +114 -0
- package/deps/librdkafka/src/rdcrc32.h +170 -0
- package/deps/librdkafka/src/rddl.c +179 -0
- package/deps/librdkafka/src/rddl.h +43 -0
- package/deps/librdkafka/src/rdendian.h +175 -0
- package/deps/librdkafka/src/rdfloat.h +67 -0
- package/deps/librdkafka/src/rdfnv1a.c +113 -0
- package/deps/librdkafka/src/rdfnv1a.h +35 -0
- package/deps/librdkafka/src/rdgz.c +120 -0
- package/deps/librdkafka/src/rdgz.h +46 -0
- package/deps/librdkafka/src/rdhdrhistogram.c +721 -0
- package/deps/librdkafka/src/rdhdrhistogram.h +87 -0
- package/deps/librdkafka/src/rdhttp.c +831 -0
- package/deps/librdkafka/src/rdhttp.h +101 -0
- package/deps/librdkafka/src/rdinterval.h +177 -0
- package/deps/librdkafka/src/rdkafka.c +7287 -0
- package/deps/librdkafka/src/rdkafka.h +11795 -0
- package/deps/librdkafka/src/rdkafka_admin.c +10165 -0
- package/deps/librdkafka/src/rdkafka_admin.h +658 -0
- package/deps/librdkafka/src/rdkafka_assignment.c +1282 -0
- package/deps/librdkafka/src/rdkafka_assignment.h +73 -0
- package/deps/librdkafka/src/rdkafka_assignor.c +1800 -0
- package/deps/librdkafka/src/rdkafka_assignor.h +402 -0
- package/deps/librdkafka/src/rdkafka_aux.c +409 -0
- package/deps/librdkafka/src/rdkafka_aux.h +174 -0
- package/deps/librdkafka/src/rdkafka_background.c +222 -0
- package/deps/librdkafka/src/rdkafka_broker.c +6736 -0
- package/deps/librdkafka/src/rdkafka_broker.h +851 -0
- package/deps/librdkafka/src/rdkafka_buf.c +543 -0
- package/deps/librdkafka/src/rdkafka_buf.h +1525 -0
- package/deps/librdkafka/src/rdkafka_cert.c +576 -0
- package/deps/librdkafka/src/rdkafka_cert.h +62 -0
- package/deps/librdkafka/src/rdkafka_cgrp.c +8310 -0
- package/deps/librdkafka/src/rdkafka_cgrp.h +589 -0
- package/deps/librdkafka/src/rdkafka_conf.c +5177 -0
- package/deps/librdkafka/src/rdkafka_conf.h +746 -0
- package/deps/librdkafka/src/rdkafka_confval.h +97 -0
- package/deps/librdkafka/src/rdkafka_coord.c +623 -0
- package/deps/librdkafka/src/rdkafka_coord.h +132 -0
- package/deps/librdkafka/src/rdkafka_error.c +228 -0
- package/deps/librdkafka/src/rdkafka_error.h +80 -0
- package/deps/librdkafka/src/rdkafka_event.c +502 -0
- package/deps/librdkafka/src/rdkafka_event.h +126 -0
- package/deps/librdkafka/src/rdkafka_feature.c +898 -0
- package/deps/librdkafka/src/rdkafka_feature.h +104 -0
- package/deps/librdkafka/src/rdkafka_fetcher.c +3820 -0
- package/deps/librdkafka/src/rdkafka_fetcher.h +62 -0
- package/deps/librdkafka/src/rdkafka_header.c +220 -0
- package/deps/librdkafka/src/rdkafka_header.h +76 -0
- package/deps/librdkafka/src/rdkafka_idempotence.c +807 -0
- package/deps/librdkafka/src/rdkafka_idempotence.h +144 -0
- package/deps/librdkafka/src/rdkafka_int.h +1505 -0
- package/deps/librdkafka/src/rdkafka_interceptor.c +842 -0
- package/deps/librdkafka/src/rdkafka_interceptor.h +104 -0
- package/deps/librdkafka/src/rdkafka_lz4.c +450 -0
- package/deps/librdkafka/src/rdkafka_lz4.h +49 -0
- package/deps/librdkafka/src/rdkafka_metadata.c +2347 -0
- package/deps/librdkafka/src/rdkafka_metadata.h +350 -0
- package/deps/librdkafka/src/rdkafka_metadata_cache.c +1183 -0
- package/deps/librdkafka/src/rdkafka_mock.c +4514 -0
- package/deps/librdkafka/src/rdkafka_mock.h +867 -0
- package/deps/librdkafka/src/rdkafka_mock_cgrp.c +1877 -0
- package/deps/librdkafka/src/rdkafka_mock_handlers.c +5255 -0
- package/deps/librdkafka/src/rdkafka_mock_int.h +1005 -0
- package/deps/librdkafka/src/rdkafka_mock_sharegrp.c +1207 -0
- package/deps/librdkafka/src/rdkafka_msg.c +2619 -0
- package/deps/librdkafka/src/rdkafka_msg.h +629 -0
- package/deps/librdkafka/src/rdkafka_msgbatch.h +62 -0
- package/deps/librdkafka/src/rdkafka_msgset.h +105 -0
- package/deps/librdkafka/src/rdkafka_msgset_reader.c +2099 -0
- package/deps/librdkafka/src/rdkafka_msgset_writer.c +1474 -0
- package/deps/librdkafka/src/rdkafka_offset.c +1565 -0
- package/deps/librdkafka/src/rdkafka_offset.h +150 -0
- package/deps/librdkafka/src/rdkafka_op.c +1219 -0
- package/deps/librdkafka/src/rdkafka_op.h +1065 -0
- package/deps/librdkafka/src/rdkafka_partition.c +5109 -0
- package/deps/librdkafka/src/rdkafka_partition.h +1215 -0
- package/deps/librdkafka/src/rdkafka_pattern.c +228 -0
- package/deps/librdkafka/src/rdkafka_pattern.h +70 -0
- package/deps/librdkafka/src/rdkafka_plugin.c +213 -0
- package/deps/librdkafka/src/rdkafka_plugin.h +41 -0
- package/deps/librdkafka/src/rdkafka_proto.h +739 -0
- package/deps/librdkafka/src/rdkafka_protocol.h +131 -0
- package/deps/librdkafka/src/rdkafka_queue.c +1351 -0
- package/deps/librdkafka/src/rdkafka_queue.h +1235 -0
- package/deps/librdkafka/src/rdkafka_range_assignor.c +1748 -0
- package/deps/librdkafka/src/rdkafka_request.c +7298 -0
- package/deps/librdkafka/src/rdkafka_request.h +761 -0
- package/deps/librdkafka/src/rdkafka_roundrobin_assignor.c +123 -0
- package/deps/librdkafka/src/rdkafka_sasl.c +589 -0
- package/deps/librdkafka/src/rdkafka_sasl.h +63 -0
- package/deps/librdkafka/src/rdkafka_sasl_cyrus.c +722 -0
- package/deps/librdkafka/src/rdkafka_sasl_int.h +89 -0
- package/deps/librdkafka/src/rdkafka_sasl_oauthbearer.c +1833 -0
- package/deps/librdkafka/src/rdkafka_sasl_oauthbearer.h +52 -0
- package/deps/librdkafka/src/rdkafka_sasl_oauthbearer_oidc.c +1827 -0
- package/deps/librdkafka/src/rdkafka_sasl_oauthbearer_oidc.h +52 -0
- package/deps/librdkafka/src/rdkafka_sasl_plain.c +142 -0
- package/deps/librdkafka/src/rdkafka_sasl_scram.c +858 -0
- package/deps/librdkafka/src/rdkafka_sasl_win32.c +550 -0
- package/deps/librdkafka/src/rdkafka_share_acknowledgement.c +1445 -0
- package/deps/librdkafka/src/rdkafka_share_acknowledgement.h +373 -0
- package/deps/librdkafka/src/rdkafka_ssl.c +2235 -0
- package/deps/librdkafka/src/rdkafka_ssl.h +86 -0
- package/deps/librdkafka/src/rdkafka_sticky_assignor.c +4785 -0
- package/deps/librdkafka/src/rdkafka_subscription.c +411 -0
- package/deps/librdkafka/src/rdkafka_telemetry.c +761 -0
- package/deps/librdkafka/src/rdkafka_telemetry.h +52 -0
- package/deps/librdkafka/src/rdkafka_telemetry_decode.c +1307 -0
- package/deps/librdkafka/src/rdkafka_telemetry_decode.h +59 -0
- package/deps/librdkafka/src/rdkafka_telemetry_encode.c +1309 -0
- package/deps/librdkafka/src/rdkafka_telemetry_encode.h +459 -0
- package/deps/librdkafka/src/rdkafka_timer.c +407 -0
- package/deps/librdkafka/src/rdkafka_timer.h +117 -0
- package/deps/librdkafka/src/rdkafka_topic.c +2382 -0
- package/deps/librdkafka/src/rdkafka_topic.h +369 -0
- package/deps/librdkafka/src/rdkafka_transport.c +1309 -0
- package/deps/librdkafka/src/rdkafka_transport.h +99 -0
- package/deps/librdkafka/src/rdkafka_transport_int.h +100 -0
- package/deps/librdkafka/src/rdkafka_txnmgr.c +3256 -0
- package/deps/librdkafka/src/rdkafka_txnmgr.h +171 -0
- package/deps/librdkafka/src/rdkafka_zstd.c +226 -0
- package/deps/librdkafka/src/rdkafka_zstd.h +57 -0
- package/deps/librdkafka/src/rdlist.c +593 -0
- package/deps/librdkafka/src/rdlist.h +444 -0
- package/deps/librdkafka/src/rdlog.c +89 -0
- package/deps/librdkafka/src/rdlog.h +41 -0
- package/deps/librdkafka/src/rdmap.c +508 -0
- package/deps/librdkafka/src/rdmap.h +492 -0
- package/deps/librdkafka/src/rdmurmur2.c +167 -0
- package/deps/librdkafka/src/rdmurmur2.h +35 -0
- package/deps/librdkafka/src/rdports.c +61 -0
- package/deps/librdkafka/src/rdports.h +38 -0
- package/deps/librdkafka/src/rdposix.h +250 -0
- package/deps/librdkafka/src/rdrand.c +151 -0
- package/deps/librdkafka/src/rdrand.h +72 -0
- package/deps/librdkafka/src/rdregex.c +156 -0
- package/deps/librdkafka/src/rdregex.h +43 -0
- package/deps/librdkafka/src/rdsignal.h +57 -0
- package/deps/librdkafka/src/rdstring.c +645 -0
- package/deps/librdkafka/src/rdstring.h +98 -0
- package/deps/librdkafka/src/rdsysqueue.h +404 -0
- package/deps/librdkafka/src/rdtime.h +356 -0
- package/deps/librdkafka/src/rdtypes.h +86 -0
- package/deps/librdkafka/src/rdunittest.c +564 -0
- package/deps/librdkafka/src/rdunittest.h +232 -0
- package/deps/librdkafka/src/rdunittest_acknowledge.c +1177 -0
- package/deps/librdkafka/src/rdunittest_fetcher.c +1211 -0
- package/deps/librdkafka/src/rdunittest_msgset_errors.c +1521 -0
- package/deps/librdkafka/src/rdvarint.c +134 -0
- package/deps/librdkafka/src/rdvarint.h +165 -0
- package/deps/librdkafka/src/rdwin32.h +382 -0
- package/deps/librdkafka/src/rdxxhash.c +1030 -0
- package/deps/librdkafka/src/rdxxhash.h +328 -0
- package/deps/librdkafka/src/regexp.c +1352 -0
- package/deps/librdkafka/src/regexp.h +41 -0
- package/deps/librdkafka/src/snappy.c +1866 -0
- package/deps/librdkafka/src/snappy.h +62 -0
- package/deps/librdkafka/src/snappy_compat.h +138 -0
- package/deps/librdkafka/src/statistics_schema.json +444 -0
- package/deps/librdkafka/src/tinycthread.c +932 -0
- package/deps/librdkafka/src/tinycthread.h +503 -0
- package/deps/librdkafka/src/tinycthread_extra.c +210 -0
- package/deps/librdkafka/src/tinycthread_extra.h +218 -0
- package/deps/librdkafka/src/win32_config.h +58 -0
- package/deps/librdkafka/src-cpp/CMakeLists.txt +90 -0
- package/deps/librdkafka/src-cpp/ConfImpl.cpp +84 -0
- package/deps/librdkafka/src-cpp/ConsumerImpl.cpp +244 -0
- package/deps/librdkafka/src-cpp/HandleImpl.cpp +436 -0
- package/deps/librdkafka/src-cpp/HeadersImpl.cpp +48 -0
- package/deps/librdkafka/src-cpp/KafkaConsumerImpl.cpp +296 -0
- package/deps/librdkafka/src-cpp/Makefile +55 -0
- package/deps/librdkafka/src-cpp/MessageImpl.cpp +38 -0
- package/deps/librdkafka/src-cpp/MetadataImpl.cpp +170 -0
- package/deps/librdkafka/src-cpp/ProducerImpl.cpp +197 -0
- package/deps/librdkafka/src-cpp/QueueImpl.cpp +70 -0
- package/deps/librdkafka/src-cpp/README.md +16 -0
- package/deps/librdkafka/src-cpp/RdKafka.cpp +59 -0
- package/deps/librdkafka/src-cpp/TopicImpl.cpp +124 -0
- package/deps/librdkafka/src-cpp/TopicPartitionImpl.cpp +57 -0
- package/deps/librdkafka/src-cpp/rdkafkacpp.h +3797 -0
- package/deps/librdkafka/src-cpp/rdkafkacpp_int.h +1641 -0
- package/deps/librdkafka/tests/0000-unittests.c +72 -0
- package/deps/librdkafka/tests/0001-multiobj.c +102 -0
- package/deps/librdkafka/tests/0002-unkpart.c +244 -0
- package/deps/librdkafka/tests/0003-msgmaxsize.c +173 -0
- package/deps/librdkafka/tests/0004-conf.c +934 -0
- package/deps/librdkafka/tests/0005-order.c +133 -0
- package/deps/librdkafka/tests/0006-symbols.c +163 -0
- package/deps/librdkafka/tests/0007-autotopic.c +136 -0
- package/deps/librdkafka/tests/0008-reqacks.c +179 -0
- package/deps/librdkafka/tests/0009-mock_cluster.c +272 -0
- package/deps/librdkafka/tests/0011-produce_batch.c +753 -0
- package/deps/librdkafka/tests/0012-produce_consume.c +537 -0
- package/deps/librdkafka/tests/0013-null-msgs.c +473 -0
- package/deps/librdkafka/tests/0014-reconsume-191.c +512 -0
- package/deps/librdkafka/tests/0015-offset_seeks.c +172 -0
- package/deps/librdkafka/tests/0016-client_swname.c +181 -0
- package/deps/librdkafka/tests/0017-compression.c +140 -0
- package/deps/librdkafka/tests/0018-cgrp_term.c +444 -0
- package/deps/librdkafka/tests/0019-list_groups.c +289 -0
- package/deps/librdkafka/tests/0020-destroy_hang.c +162 -0
- package/deps/librdkafka/tests/0021-rkt_destroy.c +72 -0
- package/deps/librdkafka/tests/0022-consume_batch.c +331 -0
- package/deps/librdkafka/tests/0025-timers.c +147 -0
- package/deps/librdkafka/tests/0026-consume_pause.c +547 -0
- package/deps/librdkafka/tests/0028-long_topicnames.c +79 -0
- package/deps/librdkafka/tests/0029-assign_offset.c +202 -0
- package/deps/librdkafka/tests/0030-offset_commit.c +589 -0
- package/deps/librdkafka/tests/0031-get_offsets.c +235 -0
- package/deps/librdkafka/tests/0033-regex_subscribe.c +536 -0
- package/deps/librdkafka/tests/0034-offset_reset.c +398 -0
- package/deps/librdkafka/tests/0035-api_version.c +73 -0
- package/deps/librdkafka/tests/0036-partial_fetch.c +87 -0
- package/deps/librdkafka/tests/0037-destroy_hang_local.c +85 -0
- package/deps/librdkafka/tests/0038-performance.c +121 -0
- package/deps/librdkafka/tests/0039-event.c +284 -0
- package/deps/librdkafka/tests/0040-io_event.c +257 -0
- package/deps/librdkafka/tests/0041-fetch_max_bytes.c +97 -0
- package/deps/librdkafka/tests/0042-many_topics.c +252 -0
- package/deps/librdkafka/tests/0043-no_connection.c +77 -0
- package/deps/librdkafka/tests/0044-partition_cnt.c +94 -0
- package/deps/librdkafka/tests/0045-subscribe_update.c +1010 -0
- package/deps/librdkafka/tests/0046-rkt_cache.c +65 -0
- package/deps/librdkafka/tests/0047-partial_buf_tmout.c +98 -0
- package/deps/librdkafka/tests/0048-partitioner.c +283 -0
- package/deps/librdkafka/tests/0049-consume_conn_close.c +162 -0
- package/deps/librdkafka/tests/0050-subscribe_adds.c +145 -0
- package/deps/librdkafka/tests/0051-assign_adds.c +126 -0
- package/deps/librdkafka/tests/0052-msg_timestamps.c +238 -0
- package/deps/librdkafka/tests/0053-stats_cb.cpp +527 -0
- package/deps/librdkafka/tests/0054-offset_time.cpp +236 -0
- package/deps/librdkafka/tests/0055-producer_latency.c +539 -0
- package/deps/librdkafka/tests/0056-balanced_group_mt.c +315 -0
- package/deps/librdkafka/tests/0057-invalid_topic.cpp +112 -0
- package/deps/librdkafka/tests/0058-log.cpp +123 -0
- package/deps/librdkafka/tests/0059-bsearch.cpp +241 -0
- package/deps/librdkafka/tests/0060-op_prio.cpp +163 -0
- package/deps/librdkafka/tests/0061-consumer_lag.cpp +295 -0
- package/deps/librdkafka/tests/0062-stats_event.c +126 -0
- package/deps/librdkafka/tests/0063-clusterid.cpp +180 -0
- package/deps/librdkafka/tests/0064-interceptors.c +529 -0
- package/deps/librdkafka/tests/0065-yield.cpp +140 -0
- package/deps/librdkafka/tests/0066-plugins.cpp +143 -0
- package/deps/librdkafka/tests/0067-empty_topic.cpp +151 -0
- package/deps/librdkafka/tests/0068-produce_timeout.c +136 -0
- package/deps/librdkafka/tests/0069-consumer_add_parts.c +119 -0
- package/deps/librdkafka/tests/0070-null_empty.cpp +197 -0
- package/deps/librdkafka/tests/0072-headers_ut.c +448 -0
- package/deps/librdkafka/tests/0073-headers.c +381 -0
- package/deps/librdkafka/tests/0074-producev.c +87 -0
- package/deps/librdkafka/tests/0075-retry.c +290 -0
- package/deps/librdkafka/tests/0076-produce_retry.c +452 -0
- package/deps/librdkafka/tests/0077-compaction.c +366 -0
- package/deps/librdkafka/tests/0078-c_from_cpp.cpp +96 -0
- package/deps/librdkafka/tests/0079-fork.c +93 -0
- package/deps/librdkafka/tests/0080-admin_ut.c +3095 -0
- package/deps/librdkafka/tests/0081-admin.c +5633 -0
- package/deps/librdkafka/tests/0082-fetch_max_bytes.cpp +137 -0
- package/deps/librdkafka/tests/0083-cb_event.c +233 -0
- package/deps/librdkafka/tests/0084-destroy_flags.c +208 -0
- package/deps/librdkafka/tests/0085-headers.cpp +392 -0
- package/deps/librdkafka/tests/0086-purge.c +368 -0
- package/deps/librdkafka/tests/0088-produce_metadata_timeout.c +162 -0
- package/deps/librdkafka/tests/0089-max_poll_interval.c +511 -0
- package/deps/librdkafka/tests/0090-idempotence.c +171 -0
- package/deps/librdkafka/tests/0091-max_poll_interval_timeout.c +295 -0
- package/deps/librdkafka/tests/0092-mixed_msgver.c +103 -0
- package/deps/librdkafka/tests/0093-holb.c +200 -0
- package/deps/librdkafka/tests/0094-idempotence_msg_timeout.c +231 -0
- package/deps/librdkafka/tests/0095-all_brokers_down.cpp +122 -0
- package/deps/librdkafka/tests/0097-ssl_verify.cpp +674 -0
- package/deps/librdkafka/tests/0098-consumer-txn.cpp +1218 -0
- package/deps/librdkafka/tests/0099-commit_metadata.c +194 -0
- package/deps/librdkafka/tests/0100-thread_interceptors.cpp +195 -0
- package/deps/librdkafka/tests/0101-fetch-from-follower.cpp +446 -0
- package/deps/librdkafka/tests/0102-static_group_rebalance.c +836 -0
- package/deps/librdkafka/tests/0103-transactions.c +1383 -0
- package/deps/librdkafka/tests/0104-fetch_from_follower_mock.c +625 -0
- package/deps/librdkafka/tests/0105-transactions_mock.c +3930 -0
- package/deps/librdkafka/tests/0106-cgrp_sess_timeout.c +318 -0
- package/deps/librdkafka/tests/0107-topic_recreate.c +259 -0
- package/deps/librdkafka/tests/0109-auto_create_topics.cpp +278 -0
- package/deps/librdkafka/tests/0110-batch_size.cpp +182 -0
- package/deps/librdkafka/tests/0111-delay_create_topics.cpp +127 -0
- package/deps/librdkafka/tests/0112-assign_unknown_part.c +87 -0
- package/deps/librdkafka/tests/0113-cooperative_rebalance.cpp +3473 -0
- package/deps/librdkafka/tests/0114-sticky_partitioning.cpp +176 -0
- package/deps/librdkafka/tests/0115-producer_auth.cpp +182 -0
- package/deps/librdkafka/tests/0116-kafkaconsumer_close.cpp +216 -0
- package/deps/librdkafka/tests/0117-mock_errors.c +331 -0
- package/deps/librdkafka/tests/0118-commit_rebalance.c +154 -0
- package/deps/librdkafka/tests/0119-consumer_auth.cpp +167 -0
- package/deps/librdkafka/tests/0120-asymmetric_subscription.c +185 -0
- package/deps/librdkafka/tests/0121-clusterid.c +115 -0
- package/deps/librdkafka/tests/0122-buffer_cleaning_after_rebalance.c +227 -0
- package/deps/librdkafka/tests/0123-connections_max_idle.c +98 -0
- package/deps/librdkafka/tests/0124-openssl_invalid_engine.c +69 -0
- package/deps/librdkafka/tests/0125-immediate_flush.c +144 -0
- package/deps/librdkafka/tests/0126-oauthbearer_oidc.c +1164 -0
- package/deps/librdkafka/tests/0127-fetch_queue_backoff.cpp +165 -0
- package/deps/librdkafka/tests/0128-sasl_callback_queue.cpp +217 -0
- package/deps/librdkafka/tests/0129-fetch_aborted_msgs.c +79 -0
- package/deps/librdkafka/tests/0130-store_offsets.c +178 -0
- package/deps/librdkafka/tests/0131-connect_timeout.c +81 -0
- package/deps/librdkafka/tests/0132-strategy_ordering.c +179 -0
- package/deps/librdkafka/tests/0133-ssl_keys.c +150 -0
- package/deps/librdkafka/tests/0134-ssl_provider.c +92 -0
- package/deps/librdkafka/tests/0135-sasl_credentials.cpp +279 -0
- package/deps/librdkafka/tests/0136-resolve_cb.c +181 -0
- package/deps/librdkafka/tests/0137-barrier_batch_consume.c +752 -0
- package/deps/librdkafka/tests/0138-admin_mock.c +281 -0
- package/deps/librdkafka/tests/0139-offset_validation_mock.c +950 -0
- package/deps/librdkafka/tests/0140-commit_metadata.cpp +108 -0
- package/deps/librdkafka/tests/0142-reauthentication.c +931 -0
- package/deps/librdkafka/tests/0143-exponential_backoff_mock.c +552 -0
- package/deps/librdkafka/tests/0144-idempotence_mock.c +373 -0
- package/deps/librdkafka/tests/0145-pause_resume_mock.c +119 -0
- package/deps/librdkafka/tests/0146-metadata_mock.c +505 -0
- package/deps/librdkafka/tests/0147-consumer_group_consumer_mock.c +1210 -0
- package/deps/librdkafka/tests/0148-offset_fetch_commit_error_mock.c +569 -0
- package/deps/librdkafka/tests/0149-broker-same-host-port.c +140 -0
- package/deps/librdkafka/tests/0150-telemetry_mock.c +651 -0
- package/deps/librdkafka/tests/0151-purge-brokers.c +566 -0
- package/deps/librdkafka/tests/0152-rebootstrap.c +59 -0
- package/deps/librdkafka/tests/0153-memberid.c +128 -0
- package/deps/librdkafka/tests/0155-share_group_heartbeat_mock.c +2695 -0
- package/deps/librdkafka/tests/0156-share_consumer_fetch_mock.c +1551 -0
- package/deps/librdkafka/tests/0157-share_consumer_ack_mock.c +1788 -0
- package/deps/librdkafka/tests/0158-share_consumer_transactions_mock.c +467 -0
- package/deps/librdkafka/tests/0170-share_consumer_subscription.c +2192 -0
- package/deps/librdkafka/tests/0171-share_consumer_consume.c +2150 -0
- package/deps/librdkafka/tests/0172-share_consumer_acknowledge.c +1919 -0
- package/deps/librdkafka/tests/0173-share_consumer_commit_async.c +2735 -0
- package/deps/librdkafka/tests/0174-share_consumer_concurrency.c +1434 -0
- package/deps/librdkafka/tests/0175-share_consumer_groups.c +574 -0
- package/deps/librdkafka/tests/0176-share_consumer_commit_sync.c +2986 -0
- package/deps/librdkafka/tests/0177-share_consumer_transactions.c +1815 -0
- package/deps/librdkafka/tests/0178-share_consumer_close.c +2102 -0
- package/deps/librdkafka/tests/0179-share_consumer_destroy.c +2482 -0
- package/deps/librdkafka/tests/0180-share_consumer_config.c +1677 -0
- package/deps/librdkafka/tests/0181-share_consumer_topic_delete.c +354 -0
- package/deps/librdkafka/tests/0182-share_consumer_error_handling_mock.c +3358 -0
- package/deps/librdkafka/tests/0183-share_consumer_leader_change_mock.c +1234 -0
- package/deps/librdkafka/tests/0184-share_consumer_topic_recreate.c +1356 -0
- package/deps/librdkafka/tests/0185-share_consumer_max_poll_interval.c +557 -0
- package/deps/librdkafka/tests/0186-share_consumer_fatal_error.c +360 -0
- package/deps/librdkafka/tests/0190-share_consumer_telemetry.c +387 -0
- package/deps/librdkafka/tests/1000-unktopic.c +164 -0
- package/deps/librdkafka/tests/8000-idle.cpp +60 -0
- package/deps/librdkafka/tests/8001-fetch_from_follower_mock_manual.c +113 -0
- package/deps/librdkafka/tests/CMakeLists.txt +193 -0
- package/deps/librdkafka/tests/LibrdkafkaTestApp.py +291 -0
- package/deps/librdkafka/tests/Makefile +182 -0
- package/deps/librdkafka/tests/README.md +514 -0
- package/deps/librdkafka/tests/autotest.sh +33 -0
- package/deps/librdkafka/tests/backtrace.gdb +30 -0
- package/deps/librdkafka/tests/broker_version_tests.py +315 -0
- package/deps/librdkafka/tests/buildbox.sh +17 -0
- package/deps/librdkafka/tests/cleanup-checker-tests.sh +20 -0
- package/deps/librdkafka/tests/cluster_testing.py +203 -0
- package/deps/librdkafka/tests/delete-test-topics.sh +56 -0
- package/deps/librdkafka/tests/fixtures/oauthbearer/jwt_assertion_template.json +10 -0
- package/deps/librdkafka/tests/fixtures/ssl/Makefile +8 -0
- package/deps/librdkafka/tests/fixtures/ssl/README.md +13 -0
- package/deps/librdkafka/tests/fixtures/ssl/client.keystore.intermediate.p12 +0 -0
- package/deps/librdkafka/tests/fixtures/ssl/client.keystore.p12 +0 -0
- package/deps/librdkafka/tests/fixtures/ssl/client2.certificate.intermediate.pem +72 -0
- package/deps/librdkafka/tests/fixtures/ssl/client2.certificate.pem +50 -0
- package/deps/librdkafka/tests/fixtures/ssl/client2.intermediate.key +46 -0
- package/deps/librdkafka/tests/fixtures/ssl/client2.key +46 -0
- package/deps/librdkafka/tests/fixtures/ssl/create_keys.sh +168 -0
- package/deps/librdkafka/tests/fuzzers/Makefile +12 -0
- package/deps/librdkafka/tests/fuzzers/README.md +31 -0
- package/deps/librdkafka/tests/fuzzers/fuzz_regex.c +74 -0
- package/deps/librdkafka/tests/fuzzers/helpers.h +90 -0
- package/deps/librdkafka/tests/gen-ssl-certs.sh +165 -0
- package/deps/librdkafka/tests/interactive_broker_version.py +170 -0
- package/deps/librdkafka/tests/interceptor_test/CMakeLists.txt +16 -0
- package/deps/librdkafka/tests/interceptor_test/Makefile +22 -0
- package/deps/librdkafka/tests/interceptor_test/interceptor_test.c +314 -0
- package/deps/librdkafka/tests/interceptor_test/interceptor_test.h +54 -0
- package/deps/librdkafka/tests/java/IncrementalRebalanceCli.java +97 -0
- package/deps/librdkafka/tests/java/Makefile +13 -0
- package/deps/librdkafka/tests/java/Murmur2Cli.java +46 -0
- package/deps/librdkafka/tests/java/README.md +14 -0
- package/deps/librdkafka/tests/java/TransactionProducerCli.java +162 -0
- package/deps/librdkafka/tests/java/run-class.sh +11 -0
- package/deps/librdkafka/tests/librdkafka.suppressions +483 -0
- package/deps/librdkafka/tests/lz4_manual_test.sh +59 -0
- package/deps/librdkafka/tests/multi-broker-version-test.sh +50 -0
- package/deps/librdkafka/tests/parse-refcnt.sh +43 -0
- package/deps/librdkafka/tests/performance_plot.py +115 -0
- package/deps/librdkafka/tests/plugin_test/Makefile +19 -0
- package/deps/librdkafka/tests/plugin_test/plugin_test.c +58 -0
- package/deps/librdkafka/tests/requirements.txt +2 -0
- package/deps/librdkafka/tests/run-all-tests.sh +81 -0
- package/deps/librdkafka/tests/run-consumer-tests.sh +16 -0
- package/deps/librdkafka/tests/run-producer-tests.sh +16 -0
- package/deps/librdkafka/tests/run-test-batches.py +157 -0
- package/deps/librdkafka/tests/run-test.sh +141 -0
- package/deps/librdkafka/tests/rusage.c +249 -0
- package/deps/librdkafka/tests/sasl_test.py +289 -0
- package/deps/librdkafka/tests/scenarios/README.md +6 -0
- package/deps/librdkafka/tests/scenarios/ak23.json +6 -0
- package/deps/librdkafka/tests/scenarios/default.json +5 -0
- package/deps/librdkafka/tests/scenarios/noautocreate.json +5 -0
- package/deps/librdkafka/tests/share_telemetry_verify/share-otel-collector-config.yaml +28 -0
- package/deps/librdkafka/tests/sockem.c +801 -0
- package/deps/librdkafka/tests/sockem.h +85 -0
- package/deps/librdkafka/tests/sockem_ctrl.c +145 -0
- package/deps/librdkafka/tests/sockem_ctrl.h +61 -0
- package/deps/librdkafka/tests/test.c +8376 -0
- package/deps/librdkafka/tests/test.conf.example +27 -0
- package/deps/librdkafka/tests/test.h +1150 -0
- package/deps/librdkafka/tests/testcpp.cpp +131 -0
- package/deps/librdkafka/tests/testcpp.h +388 -0
- package/deps/librdkafka/tests/testshared.h +416 -0
- package/deps/librdkafka/tests/tools/README.md +4 -0
- package/deps/librdkafka/tests/tools/stats/README.md +21 -0
- package/deps/librdkafka/tests/tools/stats/filter.jq +42 -0
- package/deps/librdkafka/tests/tools/stats/graph.py +150 -0
- package/deps/librdkafka/tests/tools/stats/requirements.txt +3 -0
- package/deps/librdkafka/tests/tools/stats/to_csv.py +124 -0
- package/deps/librdkafka/tests/trivup/trivup-0.15.0.tar.gz +0 -0
- package/deps/librdkafka/tests/until-fail.sh +87 -0
- package/deps/librdkafka/tests/xxxx-assign_partition.c +122 -0
- package/deps/librdkafka/tests/xxxx-metadata.cpp +159 -0
- package/deps/librdkafka/vcpkg.json +23 -0
- package/deps/librdkafka/win32/README.md +5 -0
- package/deps/librdkafka/win32/build-package.bat +3 -0
- package/deps/librdkafka/win32/build.bat +19 -0
- package/deps/librdkafka/win32/common.vcxproj +84 -0
- package/deps/librdkafka/win32/interceptor_test/interceptor_test.vcxproj +87 -0
- package/deps/librdkafka/win32/librdkafka.autopkg.template +54 -0
- package/deps/librdkafka/win32/librdkafka.master.testing.targets +13 -0
- package/deps/librdkafka/win32/librdkafka.sln +226 -0
- package/deps/librdkafka/win32/librdkafka.vcxproj +282 -0
- package/deps/librdkafka/win32/librdkafkacpp/librdkafkacpp.vcxproj +104 -0
- package/deps/librdkafka/win32/msbuild.ps1 +58 -0
- package/deps/librdkafka/win32/openssl_engine_example/openssl_engine_example.vcxproj +132 -0
- package/deps/librdkafka/win32/package-zip.ps1 +46 -0
- package/deps/librdkafka/win32/packages/repositories.config +4 -0
- package/deps/librdkafka/win32/push-package.bat +4 -0
- package/deps/librdkafka/win32/rdkafka_complex_consumer_example_cpp/rdkafka_complex_consumer_example_cpp.vcxproj +67 -0
- package/deps/librdkafka/win32/rdkafka_example/rdkafka_example.vcxproj +97 -0
- package/deps/librdkafka/win32/rdkafka_performance/rdkafka_performance.vcxproj +97 -0
- package/deps/librdkafka/win32/setup-msys2.ps1 +47 -0
- package/deps/librdkafka/win32/setup-vcpkg.ps1 +34 -0
- package/deps/librdkafka/win32/tests/test.conf.example +25 -0
- package/deps/librdkafka/win32/tests/tests.vcxproj +278 -0
- package/deps/librdkafka/win32/win_ssl_cert_store/win_ssl_cert_store.vcxproj +132 -0
- package/deps/librdkafka/win32/wingetopt.c +564 -0
- package/deps/librdkafka/win32/wingetopt.h +101 -0
- package/deps/librdkafka/win32/wintime.h +33 -0
- package/deps/librdkafka.gyp +83 -0
- package/deps/windows-install.py +80 -0
- package/index.d.ts +3 -0
- package/lib/admin.js +732 -0
- package/lib/client.js +679 -0
- package/lib/error.js +501 -0
- package/lib/index.js +8 -0
- package/lib/kafka-consumer-stream.js +399 -0
- package/lib/kafka-consumer.js +798 -0
- package/lib/kafkajs/_admin.js +1052 -0
- package/lib/kafkajs/_common.js +887 -0
- package/lib/kafkajs/_consumer.js +2156 -0
- package/lib/kafkajs/_consumer_cache.js +310 -0
- package/lib/kafkajs/_error.js +298 -0
- package/lib/kafkajs/_kafka.js +125 -0
- package/lib/kafkajs/_linked-list.js +220 -0
- package/lib/kafkajs/_producer.js +863 -0
- package/lib/kafkajs/index.js +5 -0
- package/lib/producer/high-level-producer.js +400 -0
- package/lib/producer-stream.js +337 -0
- package/lib/producer.js +405 -0
- package/lib/rdkafka.js +44 -0
- package/lib/tools/ref-counter.js +53 -0
- package/lib/topic-partition.js +91 -0
- package/lib/topic.js +43 -0
- package/lib/util.js +55 -0
- package/librdkafka.js +12 -0
- package/package.json +85 -0
- package/shim/source_location +54 -0
- package/src/admin.cc +1597 -0
- package/src/admin.h +112 -0
- package/src/binding.cc +76 -0
- package/src/binding.h +25 -0
- package/src/callbacks.cc +676 -0
- package/src/callbacks.h +302 -0
- package/src/common.cc +1628 -0
- package/src/common.h +192 -0
- package/src/config.cc +219 -0
- package/src/config.h +61 -0
- package/src/connection.cc +703 -0
- package/src/connection.h +117 -0
- package/src/errors.cc +119 -0
- package/src/errors.h +60 -0
- package/src/kafka-consumer.cc +1539 -0
- package/src/kafka-consumer.h +147 -0
- package/src/producer.cc +917 -0
- package/src/producer.h +124 -0
- package/src/topic.cc +173 -0
- package/src/topic.h +54 -0
- package/src/workers.cc +1714 -0
- package/src/workers.h +690 -0
- package/types/config.d.ts +1269 -0
- package/types/errors.d.ts +373 -0
- package/types/kafkajs.d.ts +568 -0
- package/types/rdkafka.d.ts +571 -0
- package/util/configure.js +32 -0
- package/util/generate-docs.sh +18 -0
- package/util/get-env.js +6 -0
- package/util/test-compile.js +11 -0
- package/util/test-producer-delivery.js +100 -0
|
@@ -0,0 +1,863 @@
|
|
|
1
|
+
const RdKafka = require('../rdkafka');
|
|
2
|
+
const { Admin } = require('./_admin');
|
|
3
|
+
const { kafkaJSToRdKafkaConfig,
|
|
4
|
+
topicPartitionOffsetToRdKafka,
|
|
5
|
+
createKafkaJsErrorFromLibRdKafkaError,
|
|
6
|
+
convertToRdKafkaHeaders,
|
|
7
|
+
createBindingMessageMetadata,
|
|
8
|
+
DefaultLogger,
|
|
9
|
+
loggerTrampoline,
|
|
10
|
+
severityToLogLevel,
|
|
11
|
+
checkAllowedKeys,
|
|
12
|
+
CompatibilityErrorMessages,
|
|
13
|
+
logLevel,
|
|
14
|
+
} = require('./_common');
|
|
15
|
+
const error = require('./_error');
|
|
16
|
+
const { Buffer } = require('buffer');
|
|
17
|
+
|
|
18
|
+
const ProducerState = Object.freeze({
|
|
19
|
+
INIT: 0,
|
|
20
|
+
CONNECTING: 1,
|
|
21
|
+
INITIALIZING_TRANSACTIONS: 2,
|
|
22
|
+
INITIALIZED_TRANSACTIONS: 3,
|
|
23
|
+
CONNECTED: 4,
|
|
24
|
+
DISCONNECTING: 5,
|
|
25
|
+
DISCONNECTED: 6,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A list of supported compression types.
|
|
30
|
+
* @enum {string}
|
|
31
|
+
* @readonly
|
|
32
|
+
* @memberof KafkaJS
|
|
33
|
+
*/
|
|
34
|
+
const CompressionTypes = {
|
|
35
|
+
None: 'none',
|
|
36
|
+
GZIP: 'gzip',
|
|
37
|
+
SNAPPY: 'snappy',
|
|
38
|
+
LZ4: 'lz4',
|
|
39
|
+
ZSTD: 'zstd',
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Producer for sending messages to Kafka (promise-based, async API).
|
|
44
|
+
*
|
|
45
|
+
* The producer allows sending messages to the Kafka cluster, and provides
|
|
46
|
+
* methods to configure and control various aspects of that. This class should
|
|
47
|
+
* not be instantiated directly, and rather, an instance of
|
|
48
|
+
* [Kafka]{@link KafkaJS.Kafka} should be used.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* const { Kafka } = require('@confluentinc/kafka-javascript');
|
|
52
|
+
* const kafka = new Kafka({ 'bootstrap.servers': 'localhost:9092' });
|
|
53
|
+
* const producer = kafka.producer();
|
|
54
|
+
* await producer.connect();
|
|
55
|
+
* await producer.send({
|
|
56
|
+
* // send options
|
|
57
|
+
* });
|
|
58
|
+
* @memberof KafkaJS
|
|
59
|
+
* @see [Producer example]{@link https://github.com/confluentinc/confluent-kafka-javascript/blob/master/examples/producer.js}
|
|
60
|
+
*/
|
|
61
|
+
class Producer {
|
|
62
|
+
/**
|
|
63
|
+
* The config supplied by the user.
|
|
64
|
+
* @type {import("../../types/kafkajs").ProducerConstructorConfig|null}
|
|
65
|
+
*/
|
|
66
|
+
#userConfig = null;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The config realized after processing any compatibility options.
|
|
70
|
+
* @type {import("../../types/config").ProducerGlobalConfig|null}
|
|
71
|
+
*/
|
|
72
|
+
#internalConfig = null;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* internalClient is the node-rdkafka client used by the API.
|
|
76
|
+
* @type {import("../rdkafka").Producer|null}
|
|
77
|
+
*/
|
|
78
|
+
#internalClient = null;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* connectPromiseFunc is the set of promise functions used to resolve/reject the connect() promise.
|
|
82
|
+
* @type {{resolve: Function, reject: Function}|{}}
|
|
83
|
+
*/
|
|
84
|
+
#connectPromiseFunc = {};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Stores the first error encountered while connecting (if any). This is what we
|
|
88
|
+
* want to reject with.
|
|
89
|
+
* @type {Error|null}
|
|
90
|
+
*/
|
|
91
|
+
#connectionError = null;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* state is the current state of the producer.
|
|
95
|
+
* @type {ProducerState}
|
|
96
|
+
*/
|
|
97
|
+
#state = ProducerState.INIT;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* ongoingTransaction is true if there is an ongoing transaction.
|
|
101
|
+
* @type {boolean}
|
|
102
|
+
*/
|
|
103
|
+
#ongoingTransaction = false;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* A logger for the producer.
|
|
107
|
+
* @type {import("../../types/kafkajs").Logger}
|
|
108
|
+
*/
|
|
109
|
+
#logger = new DefaultLogger();
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* This method should not be used directly. See {@link KafkaJS.Producer}.
|
|
113
|
+
* @constructor
|
|
114
|
+
* @param {import("../../types/kafkajs").ProducerConfig} kJSConfig
|
|
115
|
+
*/
|
|
116
|
+
constructor(kJSConfig) {
|
|
117
|
+
this.#userConfig = kJSConfig;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @returns {import("../rdkafka").Producer | null} the internal node-rdkafka client.
|
|
122
|
+
* @note only for internal use and subject to API changes.
|
|
123
|
+
* @private
|
|
124
|
+
*/
|
|
125
|
+
_getInternalClient() {
|
|
126
|
+
return this.#internalClient;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Create a new admin client using the underlying connections of the producer.
|
|
131
|
+
*
|
|
132
|
+
* The producer must be connected before connecting the resulting admin client.
|
|
133
|
+
* The usage of the admin client is limited to the lifetime of the producer.
|
|
134
|
+
* The producer's logger is shared with the admin client.
|
|
135
|
+
* @returns {KafkaJS.Admin}
|
|
136
|
+
*/
|
|
137
|
+
dependentAdmin() {
|
|
138
|
+
return new Admin(null, this);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* The client name used by the producer for logging - determined by librdkafka
|
|
143
|
+
* using a combination of clientId and an integer.
|
|
144
|
+
* @type {string|undefined}
|
|
145
|
+
*/
|
|
146
|
+
#clientName = undefined;
|
|
147
|
+
|
|
148
|
+
// Convenience function to create the metadata object needed for logging.
|
|
149
|
+
#createProducerBindingMessageMetadata() {
|
|
150
|
+
return createBindingMessageMetadata(this.#clientName);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
#config() {
|
|
154
|
+
if (!this.#internalConfig)
|
|
155
|
+
this.#internalConfig = this.#finalizedConfig();
|
|
156
|
+
return this.#internalConfig;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
#kafkaJSToProducerConfig(kjsConfig) {
|
|
160
|
+
if (!kjsConfig || Object.keys(kjsConfig).length === 0) {
|
|
161
|
+
return {};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const disallowedKey = checkAllowedKeys('producer', kjsConfig);
|
|
165
|
+
if (disallowedKey) {
|
|
166
|
+
throw new error.KafkaJSError(CompatibilityErrorMessages.unsupportedKey(disallowedKey), { code: error.ErrorCodes.ERR__INVALID_ARG });
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const rdKafkaConfig = kafkaJSToRdKafkaConfig(kjsConfig);
|
|
170
|
+
|
|
171
|
+
/* Producer specific configuration. */
|
|
172
|
+
if (Object.hasOwn(kjsConfig, 'createPartitioner')) {
|
|
173
|
+
throw new error.KafkaJSError(CompatibilityErrorMessages.createPartitioner(), { code: error.ErrorCodes.ERR__NOT_IMPLEMENTED });
|
|
174
|
+
}
|
|
175
|
+
rdKafkaConfig['partitioner'] = 'murmur2_random';
|
|
176
|
+
|
|
177
|
+
if (Object.hasOwn(kjsConfig, 'metadataMaxAge')) {
|
|
178
|
+
rdKafkaConfig['topic.metadata.refresh.interval.ms'] = kjsConfig.metadataMaxAge;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (Object.hasOwn(kjsConfig, 'allowAutoTopicCreation')) {
|
|
182
|
+
rdKafkaConfig['allow.auto.create.topics'] = kjsConfig.allowAutoTopicCreation;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (Object.hasOwn(kjsConfig, 'transactionTimeout')) {
|
|
186
|
+
rdKafkaConfig['transaction.timeout.ms'] = kjsConfig.transactionTimeout;
|
|
187
|
+
} else {
|
|
188
|
+
rdKafkaConfig['transaction.timeout.ms'] = 60000;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// `socket.timeout.ms` must be set <= `transaction.timeout.ms` + 100
|
|
192
|
+
if (rdKafkaConfig['socket.timeout.ms'] > rdKafkaConfig['transaction.timeout.ms'] + 100) {
|
|
193
|
+
rdKafkaConfig['socket.timeout.ms'] = rdKafkaConfig['transaction.timeout.ms'] + 100;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (Object.hasOwn(kjsConfig, 'idempotent')) {
|
|
197
|
+
rdKafkaConfig['enable.idempotence'] = kjsConfig.idempotent;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (Object.hasOwn(kjsConfig, 'maxInFlightRequests')) {
|
|
201
|
+
rdKafkaConfig['max.in.flight'] = kjsConfig.maxInFlightRequests;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (Object.hasOwn(kjsConfig, 'transactionalId')) {
|
|
205
|
+
rdKafkaConfig['transactional.id'] = kjsConfig.transactionalId;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (Object.hasOwn(kjsConfig, 'compression')) {
|
|
209
|
+
rdKafkaConfig['compression.codec'] = kjsConfig.compression;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (Object.hasOwn(kjsConfig, 'acks')) {
|
|
213
|
+
rdKafkaConfig['acks'] = kjsConfig.acks;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (Object.hasOwn(kjsConfig, 'timeout')) {
|
|
217
|
+
rdKafkaConfig['request.timeout.ms'] = kjsConfig.timeout;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const retry = kjsConfig.retry ?? {};
|
|
221
|
+
const { retries } = retry;
|
|
222
|
+
rdKafkaConfig["retries"] = retries ?? 5;
|
|
223
|
+
|
|
224
|
+
/* Set the logger */
|
|
225
|
+
if (Object.hasOwn(kjsConfig, 'logger')) {
|
|
226
|
+
this.#logger = kjsConfig.logger;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/* Set the log level - INFO for compatibility with kafkaJS, or DEBUG if that is turned
|
|
230
|
+
* on using the logLevel property. rdKafkaConfig.log_level is guaranteed to be set if we're
|
|
231
|
+
* here, and containing the correct value. */
|
|
232
|
+
this.#logger.setLogLevel(severityToLogLevel[rdKafkaConfig.log_level]);
|
|
233
|
+
|
|
234
|
+
return rdKafkaConfig;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
#finalizedConfig() {
|
|
238
|
+
/* Creates an rdkafka config based off the kafkaJS block. Switches to compatibility mode if the block exists. */
|
|
239
|
+
let compatibleConfig = this.#kafkaJSToProducerConfig(this.#userConfig.kafkaJS);
|
|
240
|
+
|
|
241
|
+
/* There can be multiple different and conflicting config directives for setting the log level:
|
|
242
|
+
* 1. If there's a kafkaJS block:
|
|
243
|
+
* a. If there's a logLevel directive in the kafkaJS block, set the logger level accordingly.
|
|
244
|
+
* b. If there's no logLevel directive, set the logger level to INFO.
|
|
245
|
+
* (both these are already handled in the conversion method above).
|
|
246
|
+
* 2. If there is a log_level or debug directive in the main config, set the logger level accordingly.
|
|
247
|
+
* !This overrides any different value provided in the kafkaJS block!
|
|
248
|
+
* a. If there's a log_level directive, set the logger level accordingly.
|
|
249
|
+
* b. If there's a debug directive, set the logger level to DEBUG regardless of anything else. This is because
|
|
250
|
+
* librdkafka ignores log_level if debug is set, and our behaviour should be identical.
|
|
251
|
+
* 3. There's nothing at all. Take no action in this case, let the logger use its default log level.
|
|
252
|
+
*/
|
|
253
|
+
if (Object.hasOwn(this.#userConfig, 'log_level')) {
|
|
254
|
+
this.#logger.setLogLevel(severityToLogLevel[this.#userConfig.log_level]);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (Object.hasOwn(this.#userConfig, 'debug')) {
|
|
258
|
+
this.#logger.setLogLevel(logLevel.DEBUG);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
let rdKafkaConfig = Object.assign(compatibleConfig, this.#userConfig);
|
|
262
|
+
|
|
263
|
+
/* Delete properties which are already processed, or cannot be passed to node-rdkafka */
|
|
264
|
+
delete rdKafkaConfig.kafkaJS;
|
|
265
|
+
|
|
266
|
+
/* Certain properties that the user has set are overridden. There is
|
|
267
|
+
* no longer a delivery report, rather, results are made available on
|
|
268
|
+
* awaiting. */
|
|
269
|
+
/* TODO: Add a warning if dr_cb is set? Or else, create a trampoline for it. */
|
|
270
|
+
rdKafkaConfig.dr_cb = true;
|
|
271
|
+
|
|
272
|
+
if (Object.hasOwn(rdKafkaConfig, 'stats_cb')) {
|
|
273
|
+
if (typeof rdKafkaConfig['stats_cb'] === 'function')
|
|
274
|
+
this.#statsCb = rdKafkaConfig['stats_cb'];
|
|
275
|
+
delete rdKafkaConfig['stats_cb'];
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return rdKafkaConfig;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Flattens a list of topics with partitions into a list of topic, partition, offset.
|
|
283
|
+
* @param {import("../../types/kafkajs").TopicOffsets[]} topics
|
|
284
|
+
* @returns {import("../../types/kafkajs").TopicPartitionOffset}
|
|
285
|
+
* @private
|
|
286
|
+
*/
|
|
287
|
+
#flattenTopicPartitionOffsets(topics) {
|
|
288
|
+
return topics.flatMap(topic => {
|
|
289
|
+
return topic.partitions.map(partition => {
|
|
290
|
+
return { partition: Number(partition.partition), offset: String(partition.offset), topic: String(topic.topic) };
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
#readyTransactions(err) {
|
|
296
|
+
if (err) {
|
|
297
|
+
this.#connectPromiseFunc["reject"](err);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (this.#state !== ProducerState.INITIALIZING_TRANSACTIONS) {
|
|
302
|
+
// FSM impossible state. We should add error handling for
|
|
303
|
+
// this later.
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
this.#state = ProducerState.INITIALIZED_TRANSACTIONS;
|
|
308
|
+
this.#readyCb();
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Processes a delivery report, converting it to the type that the promisified API uses.
|
|
313
|
+
* @param {import('../..').LibrdKafkaError} err
|
|
314
|
+
* @param {import('../..').DeliveryReport} report
|
|
315
|
+
* @private
|
|
316
|
+
*/
|
|
317
|
+
#deliveryCallback(err, report) {
|
|
318
|
+
const opaque = report.opaque;
|
|
319
|
+
if (!opaque || (typeof opaque.resolve !== 'function' && typeof opaque.reject !== 'function')) {
|
|
320
|
+
// not sure how to handle this.
|
|
321
|
+
throw new error.KafkaJSError("Internal error: deliveryCallback called without opaque set properly", { code: error.ErrorCodes.ERR__STATE });
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
if (err) {
|
|
325
|
+
opaque.reject(createKafkaJsErrorFromLibRdKafkaError(err));
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
delete report['opaque'];
|
|
330
|
+
|
|
331
|
+
const recordMetadata = {
|
|
332
|
+
topicName: report.topic,
|
|
333
|
+
partition: report.partition,
|
|
334
|
+
errorCode: 0,
|
|
335
|
+
baseOffset: report.offset,
|
|
336
|
+
logAppendTime: '-1',
|
|
337
|
+
logStartOffset: '0',
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
opaque.resolve(recordMetadata);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
async #readyCb() {
|
|
344
|
+
if (this.#state !== ProducerState.CONNECTING && this.#state !== ProducerState.INITIALIZED_TRANSACTIONS) {
|
|
345
|
+
/* The connectPromiseFunc might not be set, so we throw such an error. It's a state error that we can't recover from. Probably a bug. */
|
|
346
|
+
throw new error.KafkaJSError(`Ready callback called in invalid state ${this.#state}`, { code: error.ErrorCodes.ERR__STATE });
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const rdKafkaConfig = this.#config();
|
|
350
|
+
this.#clientName = this.#internalClient.name;
|
|
351
|
+
|
|
352
|
+
if (Object.hasOwn(rdKafkaConfig, 'transactional.id') && this.#state !== ProducerState.INITIALIZED_TRANSACTIONS) {
|
|
353
|
+
this.#state = ProducerState.INITIALIZING_TRANSACTIONS;
|
|
354
|
+
this.#logger.debug("Attempting to initialize transactions", this.#createProducerBindingMessageMetadata());
|
|
355
|
+
this.#internalClient.initTransactions(5000 /* default: 5s */, this.#readyTransactions.bind(this));
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
this.#state = ProducerState.CONNECTED;
|
|
360
|
+
this.#internalClient.setPollInBackground(true);
|
|
361
|
+
this.#internalClient.on('delivery-report', this.#deliveryCallback.bind(this));
|
|
362
|
+
this.#logger.info("Producer connected", this.#createProducerBindingMessageMetadata());
|
|
363
|
+
|
|
364
|
+
// Resolve the promise.
|
|
365
|
+
this.#connectPromiseFunc["resolve"]();
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Callback for the event.error event, fails the initial connect() and logs the error.
|
|
370
|
+
* @param {Error} err
|
|
371
|
+
* @private
|
|
372
|
+
*/
|
|
373
|
+
#errorCb(err) {
|
|
374
|
+
/* If we get an error in the middle of connecting, reject the promise later with this error. */
|
|
375
|
+
if (this.#state < ProducerState.CONNECTED) {
|
|
376
|
+
if (!this.#connectionError)
|
|
377
|
+
this.#connectionError = err;
|
|
378
|
+
}
|
|
379
|
+
this.#logger.error(`Error: ${err.message}`, this.#createProducerBindingMessageMetadata());
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Callback for the event.stats event, if defined.
|
|
384
|
+
* @private
|
|
385
|
+
*/
|
|
386
|
+
#statsCb = null;
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Set up the client and connect to the bootstrap brokers.
|
|
390
|
+
*
|
|
391
|
+
* This method can be called only once for a producer instance, and must be
|
|
392
|
+
* called before doing any other operations.
|
|
393
|
+
* @returns {Promise<void>} Resolves when connection is complete, rejects on error.
|
|
394
|
+
*/
|
|
395
|
+
async connect() {
|
|
396
|
+
if (this.#state !== ProducerState.INIT) {
|
|
397
|
+
throw new error.KafkaJSError("Connect has already been called elsewhere.", { code: error.ErrorCodes.ERR__STATE });
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
this.#state = ProducerState.CONNECTING;
|
|
401
|
+
|
|
402
|
+
const rdKafkaConfig = this.#config();
|
|
403
|
+
|
|
404
|
+
this.#internalClient = new RdKafka.Producer(rdKafkaConfig);
|
|
405
|
+
this.#internalClient.on('ready', this.#readyCb.bind(this));
|
|
406
|
+
this.#internalClient.on('event.error', this.#errorCb.bind(this));
|
|
407
|
+
this.#internalClient.on('error', this.#errorCb.bind(this));
|
|
408
|
+
this.#internalClient.on('event.log', (msg) => loggerTrampoline(msg, this.#logger));
|
|
409
|
+
if (this.#statsCb) {
|
|
410
|
+
this.#internalClient.on('event.stats', this.#statsCb.bind(this));
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
return new Promise((resolve, reject) => {
|
|
414
|
+
this.#connectPromiseFunc = { resolve, reject };
|
|
415
|
+
this.#internalClient.connect(null, (err) => {
|
|
416
|
+
if (err) {
|
|
417
|
+
this.#state = ProducerState.DISCONNECTED;
|
|
418
|
+
const rejectionError = this.#connectionError ? this.#connectionError : err;
|
|
419
|
+
reject(createKafkaJsErrorFromLibRdKafkaError(rejectionError));
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Disconnect from the brokers, clean-up and tear down the client.
|
|
427
|
+
* @returns {Promise<void>} Resolves when disconnect is complete, rejects on error.
|
|
428
|
+
*/
|
|
429
|
+
async disconnect() {
|
|
430
|
+
/* Not yet connected - no error. */
|
|
431
|
+
if (this.#state === ProducerState.INIT) {
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/* TODO: We should handle a case where we are connecting, we should
|
|
436
|
+
* await the connection and then schedule a disconnect. */
|
|
437
|
+
|
|
438
|
+
/* Already disconnecting, or disconnected. */
|
|
439
|
+
if (this.#state >= ProducerState.DISCONNECTING) {
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
this.#state = ProducerState.DISCONNECTING;
|
|
444
|
+
await new Promise((resolve, reject) => {
|
|
445
|
+
const cb = (err) => {
|
|
446
|
+
if (err) {
|
|
447
|
+
reject(createKafkaJsErrorFromLibRdKafkaError(err));
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
this.#state = ProducerState.DISCONNECTED;
|
|
451
|
+
this.#logger.info("Producer disconnected", this.#createProducerBindingMessageMetadata());
|
|
452
|
+
resolve();
|
|
453
|
+
};
|
|
454
|
+
this.#internalClient.disconnect(5000 /* default timeout, 5000ms */, cb);
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Starts a new transaction.
|
|
460
|
+
*
|
|
461
|
+
* This can only be used with a transactional producer, where the transactional
|
|
462
|
+
* ID is set within the config.
|
|
463
|
+
*
|
|
464
|
+
* No more than one transaction may be ongoing at a time.
|
|
465
|
+
* @sa {@link KafkaJS.Producer#commit}
|
|
466
|
+
* @sa {@link KafkaJS.Producer#abort}
|
|
467
|
+
* @returns {Promise<KafkaJS.Producer>} Resolves with the producer when the transaction is started.
|
|
468
|
+
*/
|
|
469
|
+
async transaction() {
|
|
470
|
+
if (this.#state !== ProducerState.CONNECTED) {
|
|
471
|
+
throw new error.KafkaJSError("Cannot start transaction without awaiting connect()", { code: error.ErrorCodes.ERR__STATE });
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
if (this.#ongoingTransaction) {
|
|
475
|
+
throw new error.KafkaJSError("Can only start one transaction at a time.", { code: error.ErrorCodes.ERR__STATE });
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
this.#logger.debug("Attempting to begin transaction", this.#createProducerBindingMessageMetadata());
|
|
479
|
+
return new Promise((resolve, reject) => {
|
|
480
|
+
this.#internalClient.beginTransaction((err) => {
|
|
481
|
+
if (err) {
|
|
482
|
+
reject(createKafkaJsErrorFromLibRdKafkaError(err));
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
this.#ongoingTransaction = true;
|
|
486
|
+
|
|
487
|
+
// Resolve with 'this' because we don't need any specific transaction object.
|
|
488
|
+
// Just using the producer works since we can only have one transaction
|
|
489
|
+
// ongoing for one producer.
|
|
490
|
+
resolve(this);
|
|
491
|
+
});
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Commit the current transaction.
|
|
497
|
+
*
|
|
498
|
+
* Can only be called if there is an ongoing transaction.
|
|
499
|
+
* @returns {Promise<void>} Resolves when the transaction is committed.
|
|
500
|
+
*/
|
|
501
|
+
async commit() {
|
|
502
|
+
if (this.#state !== ProducerState.CONNECTED) {
|
|
503
|
+
throw new error.KafkaJSError("Cannot commit without awaiting connect()", { code: error.ErrorCodes.ERR__STATE });
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
if (!this.#ongoingTransaction) {
|
|
507
|
+
throw new error.KafkaJSError("Cannot commit, no transaction ongoing.", { code: error.ErrorCodes.ERR__STATE });
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
this.#logger.debug("Attempting to commit transaction", this.#createProducerBindingMessageMetadata());
|
|
511
|
+
return new Promise((resolve, reject) => {
|
|
512
|
+
this.#internalClient.commitTransaction(5000 /* default: 5000ms */, err => {
|
|
513
|
+
if (err) {
|
|
514
|
+
// TODO: Do we reset ongoingTransaction here?
|
|
515
|
+
reject(createKafkaJsErrorFromLibRdKafkaError(err));
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
this.#ongoingTransaction = false;
|
|
519
|
+
resolve();
|
|
520
|
+
});
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Abort the current transaction.
|
|
526
|
+
*
|
|
527
|
+
* Can only be called if there is an ongoing transaction.
|
|
528
|
+
* @returns {Promise<void>} Resolves when the transaction is aborted.
|
|
529
|
+
*/
|
|
530
|
+
async abort() {
|
|
531
|
+
if (this.#state !== ProducerState.CONNECTED) {
|
|
532
|
+
throw new error.KafkaJSError("Cannot abort without awaiting connect()", { code: error.ErrorCodes.ERR__STATE });
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
if (!this.#ongoingTransaction) {
|
|
536
|
+
throw new error.KafkaJSError("Cannot abort, no transaction ongoing.", { code: error.ErrorCodes.ERR__STATE });
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
this.#logger.debug("Attempting to abort transaction", this.#createProducerBindingMessageMetadata());
|
|
540
|
+
return new Promise((resolve, reject) => {
|
|
541
|
+
this.#internalClient.abortTransaction(5000 /* default: 5000ms */, err => {
|
|
542
|
+
if (err) {
|
|
543
|
+
// TODO: Do we reset ongoingTransaction here?
|
|
544
|
+
reject(createKafkaJsErrorFromLibRdKafkaError(err));
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
this.#ongoingTransaction = false;
|
|
548
|
+
resolve();
|
|
549
|
+
});
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* Send offsets for the transaction.
|
|
555
|
+
*
|
|
556
|
+
* Can only be called if there is an ongoing transaction.
|
|
557
|
+
* @param {object} arg - The arguments to sendOffsets
|
|
558
|
+
* @param {KafkaJS.Consumer} arg.consumer - The consumer to send offsets for.
|
|
559
|
+
* @param {Array<{topic: string, partitions: Array<{partition: number, offset: string}>}>} arg.topics - The topics, partitions and the offsets to send.
|
|
560
|
+
*
|
|
561
|
+
* @returns {Promise<void>} Resolves when the offsets are sent.
|
|
562
|
+
*/
|
|
563
|
+
async sendOffsets(arg) {
|
|
564
|
+
let { consumerGroupId, topics, consumer } = arg;
|
|
565
|
+
|
|
566
|
+
/* If the user has not supplied a consumer, or supplied a consumerGroupId, throw immediately. */
|
|
567
|
+
if (consumerGroupId || !consumer) {
|
|
568
|
+
throw new error.KafkaJSError(CompatibilityErrorMessages.sendOffsetsMustProvideConsumer(), { code: error.ErrorCodes.ERR__INVALID_ARG });
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
if (!Array.isArray(topics) || topics.length === 0) {
|
|
572
|
+
throw new error.KafkaJSError("sendOffsets arguments are invalid", { code: error.ErrorCodes.ERR__INVALID_ARG });
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
if (this.#state !== ProducerState.CONNECTED) {
|
|
576
|
+
throw new error.KafkaJSError("Cannot sendOffsets without awaiting connect()", { code: error.ErrorCodes.ERR__STATE });
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
if (!this.#ongoingTransaction) {
|
|
580
|
+
throw new error.KafkaJSError("Cannot sendOffsets, no transaction ongoing.", { code: error.ErrorCodes.ERR__STATE });
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
return new Promise((resolve, reject) => {
|
|
584
|
+
this.#internalClient.sendOffsetsToTransaction(
|
|
585
|
+
this.#flattenTopicPartitionOffsets(topics).map(topicPartitionOffsetToRdKafka),
|
|
586
|
+
consumer._getInternalClient(),
|
|
587
|
+
async err => {
|
|
588
|
+
if (err)
|
|
589
|
+
reject(createKafkaJsErrorFromLibRdKafkaError(err));
|
|
590
|
+
else
|
|
591
|
+
resolve();
|
|
592
|
+
});
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Check if there is an ongoing transaction.
|
|
598
|
+
*
|
|
599
|
+
* Since a producer itself represents a transaction, and there is no distinct
|
|
600
|
+
* type for a transaction, this method exists on the producer.
|
|
601
|
+
* @returns {boolean} true if there is an ongoing transaction, false otherwise.
|
|
602
|
+
*/
|
|
603
|
+
isActive() {
|
|
604
|
+
return this.#ongoingTransaction;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* Sends a record of messages to a specific topic.
|
|
609
|
+
*
|
|
610
|
+
* @example
|
|
611
|
+
* const deliveryReport = await producer.send({
|
|
612
|
+
* topic: 'test-topic',
|
|
613
|
+
* messages: [{ value: 'v1', partition: 0, key: 'x' }]
|
|
614
|
+
* });
|
|
615
|
+
* @param {Object} sendOptions - The record to send. The keys `acks`, `timeout`, and `compression` are not used, and should not be set, rather, they should be set in the global config.
|
|
616
|
+
* @returns {Promise<Array<Object>>} Resolves with the record metadata for the messages.
|
|
617
|
+
*/
|
|
618
|
+
async send(sendOptions) {
|
|
619
|
+
if (this.#state !== ProducerState.CONNECTED) {
|
|
620
|
+
throw new error.KafkaJSError("Cannot send without awaiting connect()", { code: error.ErrorCodes.ERR__STATE });
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
if (sendOptions === null || !(sendOptions instanceof Object)) {
|
|
624
|
+
throw new error.KafkaJSError(CompatibilityErrorMessages.sendOptionsMandatoryMissing(), { code: error.ErrorCodes.ERR__INVALID_ARG });
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
if (Object.hasOwn(sendOptions, 'acks')) {
|
|
628
|
+
throw new error.KafkaJSError(CompatibilityErrorMessages.sendOptionsAcks('send'), { code: error.ErrorCodes.ERR__INVALID_ARG });
|
|
629
|
+
}
|
|
630
|
+
if (Object.hasOwn(sendOptions, 'timeout')) {
|
|
631
|
+
throw new error.KafkaJSError(CompatibilityErrorMessages.sendOptionsTimeout('send'), { code: error.ErrorCodes.ERR__INVALID_ARG });
|
|
632
|
+
}
|
|
633
|
+
if (Object.hasOwn(sendOptions, 'compression')) {
|
|
634
|
+
throw new error.KafkaJSError(CompatibilityErrorMessages.sendOptionsCompression('send'), { code: error.ErrorCodes.ERR__INVALID_ARG });
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
const msgPromises = [];
|
|
638
|
+
for (let i = 0; i < sendOptions.messages.length; i++) {
|
|
639
|
+
const msg = sendOptions.messages[i];
|
|
640
|
+
|
|
641
|
+
if (!Object.hasOwn(msg, "partition") || msg.partition === null) {
|
|
642
|
+
msg.partition = -1;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
if (typeof msg.value === 'string') {
|
|
646
|
+
msg.value = Buffer.from(msg.value);
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
if (Object.hasOwn(msg, "timestamp") && msg.timestamp) {
|
|
650
|
+
msg.timestamp = Number(msg.timestamp);
|
|
651
|
+
} else {
|
|
652
|
+
msg.timestamp = 0;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
msg.headers = convertToRdKafkaHeaders(msg.headers);
|
|
656
|
+
|
|
657
|
+
msgPromises.push(new Promise((resolve, reject) => {
|
|
658
|
+
const opaque = { resolve, reject };
|
|
659
|
+
try {
|
|
660
|
+
this.#internalClient.produce(sendOptions.topic, msg.partition, msg.value, msg.key, msg.timestamp, opaque, msg.headers);
|
|
661
|
+
} catch (err) {
|
|
662
|
+
reject(err);
|
|
663
|
+
}
|
|
664
|
+
}));
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
/* The delivery report will be handled by the delivery-report event handler, and we can simply wait for it here. */
|
|
668
|
+
|
|
669
|
+
const recordMetadataArr = await Promise.all(msgPromises);
|
|
670
|
+
|
|
671
|
+
const topicPartitionRecordMetadata = new Map();
|
|
672
|
+
for (const recordMetadata of recordMetadataArr) {
|
|
673
|
+
const key = `${recordMetadata.topicName},${recordMetadata.partition}`;
|
|
674
|
+
if (recordMetadata.baseOffset === null || !topicPartitionRecordMetadata.has(key)) {
|
|
675
|
+
topicPartitionRecordMetadata.set(key, recordMetadata);
|
|
676
|
+
continue;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
const currentRecordMetadata = topicPartitionRecordMetadata.get(key);
|
|
680
|
+
|
|
681
|
+
// Don't overwrite a null baseOffset
|
|
682
|
+
if (currentRecordMetadata.baseOffset === null) {
|
|
683
|
+
continue;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
if (currentRecordMetadata.baseOffset > recordMetadata.baseOffset) {
|
|
687
|
+
topicPartitionRecordMetadata.set(key, recordMetadata);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
const ret = [];
|
|
692
|
+
for (const value of topicPartitionRecordMetadata.values()) {
|
|
693
|
+
value.baseOffset = value.baseOffset?.toString();
|
|
694
|
+
ret.push(value);
|
|
695
|
+
}
|
|
696
|
+
return ret;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* Sends a record of messages to various topics.
|
|
701
|
+
*
|
|
702
|
+
* This method is identical to calling send() repeatedly and waiting on all the return values together.
|
|
703
|
+
*
|
|
704
|
+
* @example
|
|
705
|
+
* const deliveryReports = await producer.sendBatch({
|
|
706
|
+
* topicMessages: [
|
|
707
|
+
* { topic: 'test-topic1', messages: [{ key: 'hello', value: 'hello' }] },
|
|
708
|
+
* { topic: 'test-topic2', messages: [{ key: 'world', value: 'world' }] }
|
|
709
|
+
* ]
|
|
710
|
+
* });
|
|
711
|
+
* @param {Object} sendOptions - The record to send. The keys `acks`, `timeout`, and `compression` are not used, and should not be set, rather, they should be set in the global config.
|
|
712
|
+
* @returns {Promise<Array<Object>>} Resolves with the record metadata for the messages.
|
|
713
|
+
*/
|
|
714
|
+
async sendBatch(sendOptions) {
|
|
715
|
+
if (this.#state !== ProducerState.CONNECTED) {
|
|
716
|
+
throw new error.KafkaJSError("Cannot sendBatch without awaiting connect()", { code: error.ErrorCodes.ERR__STATE });
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
if (sendOptions === null || !(sendOptions instanceof Object)) {
|
|
720
|
+
throw new error.KafkaJSError(CompatibilityErrorMessages.sendBatchMandatoryMissing(), { code: error.ErrorCodes.ERR__INVALID_ARG });
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
if (Object.hasOwn(sendOptions, 'acks')) {
|
|
724
|
+
throw new error.KafkaJSError(CompatibilityErrorMessages.sendOptionsAcks('sendBatch'), { code: error.ErrorCodes.ERR__INVALID_ARG });
|
|
725
|
+
}
|
|
726
|
+
if (Object.hasOwn(sendOptions, 'timeout')) {
|
|
727
|
+
throw new error.KafkaJSError(CompatibilityErrorMessages.sendOptionsTimeout('timeout'), { code: error.ErrorCodes.ERR__INVALID_ARG });
|
|
728
|
+
}
|
|
729
|
+
if (Object.hasOwn(sendOptions, 'compression')) {
|
|
730
|
+
throw new error.KafkaJSError(CompatibilityErrorMessages.sendOptionsCompression('compression'), { code: error.ErrorCodes.ERR__INVALID_ARG });
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
if (sendOptions.topicMessages !== null && !Array.isArray(sendOptions.topicMessages)) {
|
|
734
|
+
throw new error.KafkaJSError(CompatibilityErrorMessages.sendBatchMandatoryMissing(), { code: error.ErrorCodes.ERR__INVALID_ARG });
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
if (!sendOptions.topicMessages || sendOptions.topicMessages.length === 0) {
|
|
738
|
+
return Promise.resolve([]);
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
// Internally, we just use send() because the batching is handled by librdkafka.
|
|
742
|
+
const sentPromises = [];
|
|
743
|
+
|
|
744
|
+
for (const topicMessage of sendOptions.topicMessages) {
|
|
745
|
+
sentPromises.push(this.send(topicMessage));
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
const records = await Promise.all(sentPromises);
|
|
749
|
+
return records.flat();
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
/**
|
|
753
|
+
* Get the logger associated to this producer instance.
|
|
754
|
+
*
|
|
755
|
+
* @example
|
|
756
|
+
* const logger = producer.logger();
|
|
757
|
+
* logger.info('Hello world');
|
|
758
|
+
* logger.setLogLevel(logLevel.ERROR);
|
|
759
|
+
* @see {@link KafkaJS.logLevel} for available log levels
|
|
760
|
+
* @returns {Object} The logger instance.
|
|
761
|
+
*/
|
|
762
|
+
logger() {
|
|
763
|
+
return this.#logger;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* Change SASL credentials to be sent on the next authentication attempt.
|
|
768
|
+
*
|
|
769
|
+
* Only applicable if SASL authentication is being used.
|
|
770
|
+
* @param {object} args The SASL credentials to set.
|
|
771
|
+
* @param {string} args.username SASL username.
|
|
772
|
+
* @param {string} args.password SASL password.
|
|
773
|
+
*/
|
|
774
|
+
setSaslCredentials(args = {}) {
|
|
775
|
+
if (!Object.hasOwn(args, 'username')) {
|
|
776
|
+
throw new error.KafkaJSError("username must be set for setSaslCredentials", { code: error.ErrorCodes.ERR__INVALID_ARG });
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
if (!Object.hasOwn(args, 'password')) {
|
|
780
|
+
throw new error.KafkaJSError("password must be set for setSaslCredentials", { code: error.ErrorCodes.ERR__INVALID_ARG });
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
/**
|
|
784
|
+
* In case we've not started connecting yet, just modify the configuration for
|
|
785
|
+
* the first connection attempt.
|
|
786
|
+
*/
|
|
787
|
+
if (this.#state < ProducerState.CONNECTING) {
|
|
788
|
+
this.#userConfig['sasl.username'] = args.username;
|
|
789
|
+
this.#userConfig['sasl.password'] = args.password;
|
|
790
|
+
if (Object.hasOwn(this.#userConfig, 'kafkaJS') && Object.hasOwn(this.#userConfig.kafkaJS, 'sasl')) {
|
|
791
|
+
this.#userConfig.kafkaJS.sasl.username = args.username;
|
|
792
|
+
this.#userConfig.kafkaJS.sasl.password = args.password;
|
|
793
|
+
}
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
this.#logger.info("Setting SASL credentials", this.#createProducerBindingMessageMetadata());
|
|
798
|
+
this.#internalClient.setSaslCredentials(args.username, args.password);
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
/**
|
|
802
|
+
* Flushes any pending messages.
|
|
803
|
+
*
|
|
804
|
+
* Messages are batched internally by librdkafka for performance reasons.
|
|
805
|
+
* Continously sent messages are batched upto a timeout, or upto a maximum
|
|
806
|
+
* size. Calling flush sends any pending messages immediately without
|
|
807
|
+
* waiting for this size or timeout.
|
|
808
|
+
*
|
|
809
|
+
* This is only useful when using asynchronous sends.
|
|
810
|
+
* For example, the following code does not get any benefit from flushing,
|
|
811
|
+
* since `await`ing the send waits for the delivery report, and the message
|
|
812
|
+
* has already been sent by the time we start flushing:
|
|
813
|
+
*
|
|
814
|
+
* ```js
|
|
815
|
+
* for (let i = 0; i < 100; i++) await send(...);
|
|
816
|
+
* await flush(...) // Not useful.
|
|
817
|
+
* ```
|
|
818
|
+
*
|
|
819
|
+
* However, using the following code may put these 5 messages into a batch
|
|
820
|
+
* and then the subsequent `flush` will send the batch altogether (as long as
|
|
821
|
+
* batch size, etc. are conducive to batching):
|
|
822
|
+
* ```js
|
|
823
|
+
* for (let i = 0; i < 5; i++) send(...);
|
|
824
|
+
* await flush({timeout: 5000});
|
|
825
|
+
* ```
|
|
826
|
+
* @param {object} args
|
|
827
|
+
* @param {number} args.timeout Time to try flushing for in milliseconds, 500ms by default.
|
|
828
|
+
* @returns {Promise<void>} Resolves on successful flush.
|
|
829
|
+
* @throws {KafkaJSTimeout} if the flush times out.
|
|
830
|
+
*/
|
|
831
|
+
async flush(args = { timeout: 500 }) {
|
|
832
|
+
if (this.#state !== ProducerState.CONNECTED) {
|
|
833
|
+
throw new error.KafkaJSError("Cannot flush without awaiting connect()", { code: error.ErrorCodes.ERR__STATE });
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
if (!Object.hasOwn(args, 'timeout')) {
|
|
837
|
+
throw new error.KafkaJSError("timeout must be set for flushing", { code: error.ErrorCodes.ERR__INVALID_ARG });
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
this.#logger.debug(`Attempting to flush messages for ${args.timeout}ms`, this.#createProducerBindingMessageMetadata());
|
|
841
|
+
return new Promise((resolve, reject) => {
|
|
842
|
+
this.#internalClient.flush(args.timeout, (err) => {
|
|
843
|
+
if (err) {
|
|
844
|
+
const kjsErr = createKafkaJsErrorFromLibRdKafkaError(err);
|
|
845
|
+
if (err.code === error.ErrorCodes.ERR__TIMED_OUT) {
|
|
846
|
+
/* See reason below for yield. Same here - but for partially processed delivery reports. */
|
|
847
|
+
setTimeout(() => reject(kjsErr), 0);
|
|
848
|
+
} else {
|
|
849
|
+
reject(kjsErr);
|
|
850
|
+
}
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
/* Yielding here allows any 'then's and 'awaits' on associated sends to be scheduled
|
|
854
|
+
* before flush completes, which means that the user doesn't have to yield themselves.
|
|
855
|
+
* It's not necessary that all the 'then's and 'awaits' will be able to run, but
|
|
856
|
+
* it's better than nothing. */
|
|
857
|
+
setTimeout(resolve, 0);
|
|
858
|
+
});
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
module.exports = { Producer, CompressionTypes: Object.freeze(CompressionTypes) };
|