rdkafka.h 137 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211
  1. /*
  2. * librdkafka - Apache Kafka C library
  3. *
  4. * Copyright (c) 2012-2013 Magnus Edenhill
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright notice,
  13. * this list of conditions and the following disclaimer in the documentation
  14. * and/or other materials provided with the distribution.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  20. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  21. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  22. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  23. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  24. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  26. * POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. /**
  29. * @file rdkafka.h
  30. * @brief Apache Kafka C/C++ consumer and producer client library.
  31. *
  32. * rdkafka.h contains the public API for librdkafka.
  33. * The API is documented in this file as comments prefixing the function, type,
  34. * enum, define, etc.
  35. *
  36. * @sa For the C++ interface see rdkafkacpp.h
  37. *
  38. * @tableofcontents
  39. */
  40. /* @cond NO_DOC */
  41. #ifndef _RDKAFKA_H_
  42. #define _RDKAFKA_H_
  43. #include <stdio.h>
  44. #include <inttypes.h>
  45. #include <sys/types.h>
  46. #ifdef __cplusplus
  47. extern "C" {
  48. #if 0
  49. } /* Restore indent */
  50. #endif
  51. #endif
  52. #ifdef _MSC_VER
  53. #include <basetsd.h>
  54. #ifndef WIN32_MEAN_AND_LEAN
  55. #define WIN32_MEAN_AND_LEAN
  56. #endif
  57. #include <Winsock2.h> /* for sockaddr, .. */
  58. typedef SSIZE_T ssize_t;
  59. #define RD_UNUSED
  60. #define RD_INLINE __inline
  61. #define RD_DEPRECATED __declspec(deprecated)
  62. #undef RD_EXPORT
  63. #ifdef LIBRDKAFKA_STATICLIB
  64. #define RD_EXPORT
  65. #else
  66. #ifdef LIBRDKAFKA_EXPORTS
  67. #define RD_EXPORT __declspec(dllexport)
  68. #else
  69. #define RD_EXPORT __declspec(dllimport)
  70. #endif
  71. #ifndef LIBRDKAFKA_TYPECHECKS
  72. #define LIBRDKAFKA_TYPECHECKS 0
  73. #endif
  74. #endif
  75. #else
  76. #include <sys/socket.h> /* for sockaddr, .. */
  77. #define RD_UNUSED __attribute__((unused))
  78. #define RD_INLINE inline
  79. #define RD_EXPORT
  80. #define RD_DEPRECATED __attribute__((deprecated))
  81. #ifndef LIBRDKAFKA_TYPECHECKS
  82. #define LIBRDKAFKA_TYPECHECKS 1
  83. #endif
  84. #endif
  85. /**
  86. * @brief Type-checking macros
  87. * Compile-time checking that \p ARG is of type \p TYPE.
  88. * @returns \p RET
  89. */
  90. #if LIBRDKAFKA_TYPECHECKS
  91. #define _LRK_TYPECHECK(RET,TYPE,ARG) \
  92. ({ if (0) { TYPE __t RD_UNUSED = (ARG); } RET; })
  93. #define _LRK_TYPECHECK2(RET,TYPE,ARG,TYPE2,ARG2) \
  94. ({ \
  95. if (0) { \
  96. TYPE __t RD_UNUSED = (ARG); \
  97. TYPE2 __t2 RD_UNUSED = (ARG2); \
  98. } \
  99. RET; })
  100. #define _LRK_TYPECHECK3(RET,TYPE,ARG,TYPE2,ARG2,TYPE3,ARG3) \
  101. ({ \
  102. if (0) { \
  103. TYPE __t RD_UNUSED = (ARG); \
  104. TYPE2 __t2 RD_UNUSED = (ARG2); \
  105. TYPE3 __t3 RD_UNUSED = (ARG3); \
  106. } \
  107. RET; })
  108. #else
  109. #define _LRK_TYPECHECK(RET,TYPE,ARG) (RET)
  110. #define _LRK_TYPECHECK2(RET,TYPE,ARG,TYPE2,ARG2) (RET)
  111. #define _LRK_TYPECHECK3(RET,TYPE,ARG,TYPE2,ARG2,TYPE3,ARG3) (RET)
  112. #endif
  113. /* @endcond */
  114. /**
  115. * @name librdkafka version
  116. * @{
  117. *
  118. *
  119. */
  120. /**
  121. * @brief librdkafka version
  122. *
  123. * Interpreted as hex \c MM.mm.rr.xx:
  124. * - MM = Major
  125. * - mm = minor
  126. * - rr = revision
  127. * - xx = pre-release id (0xff is the final release)
  128. *
  129. * E.g.: \c 0x000801ff = 0.8.1
  130. *
  131. * @remark This value should only be used during compile time,
  132. * for runtime checks of version use rd_kafka_version()
  133. */
  134. #define RD_KAFKA_VERSION 0x000b04ff
  135. /**
  136. * @brief Returns the librdkafka version as integer.
  137. *
  138. * @returns Version integer.
  139. *
  140. * @sa See RD_KAFKA_VERSION for how to parse the integer format.
  141. * @sa Use rd_kafka_version_str() to retreive the version as a string.
  142. */
  143. RD_EXPORT
  144. int rd_kafka_version(void);
  145. /**
  146. * @brief Returns the librdkafka version as string.
  147. *
  148. * @returns Version string
  149. */
  150. RD_EXPORT
  151. const char *rd_kafka_version_str (void);
  152. /**@}*/
  153. /**
  154. * @name Constants, errors, types
  155. * @{
  156. *
  157. *
  158. */
  159. /**
  160. * @enum rd_kafka_type_t
  161. *
  162. * @brief rd_kafka_t handle type.
  163. *
  164. * @sa rd_kafka_new()
  165. */
  166. typedef enum rd_kafka_type_t {
  167. RD_KAFKA_PRODUCER, /**< Producer client */
  168. RD_KAFKA_CONSUMER /**< Consumer client */
  169. } rd_kafka_type_t;
  170. /**
  171. * @enum Timestamp types
  172. *
  173. * @sa rd_kafka_message_timestamp()
  174. */
  175. typedef enum rd_kafka_timestamp_type_t {
  176. RD_KAFKA_TIMESTAMP_NOT_AVAILABLE, /**< Timestamp not available */
  177. RD_KAFKA_TIMESTAMP_CREATE_TIME, /**< Message creation time */
  178. RD_KAFKA_TIMESTAMP_LOG_APPEND_TIME /**< Log append time */
  179. } rd_kafka_timestamp_type_t;
  180. /**
  181. * @brief Retrieve supported debug contexts for use with the \c \"debug\"
  182. * configuration property. (runtime)
  183. *
  184. * @returns Comma-separated list of available debugging contexts.
  185. */
  186. RD_EXPORT
  187. const char *rd_kafka_get_debug_contexts(void);
  188. /**
  189. * @brief Supported debug contexts. (compile time)
  190. *
  191. * @deprecated This compile time value may be outdated at runtime due to
  192. * linking another version of the library.
  193. * Use rd_kafka_get_debug_contexts() instead.
  194. */
  195. #define RD_KAFKA_DEBUG_CONTEXTS \
  196. "all,generic,broker,topic,metadata,feature,queue,msg,protocol,cgrp,security,fetch,interceptor,plugin,consumer"
  197. /* @cond NO_DOC */
  198. /* Private types to provide ABI compatibility */
  199. typedef struct rd_kafka_s rd_kafka_t;
  200. typedef struct rd_kafka_topic_s rd_kafka_topic_t;
  201. typedef struct rd_kafka_conf_s rd_kafka_conf_t;
  202. typedef struct rd_kafka_topic_conf_s rd_kafka_topic_conf_t;
  203. typedef struct rd_kafka_queue_s rd_kafka_queue_t;
  204. /* @endcond */
  205. /**
  206. * @enum rd_kafka_resp_err_t
  207. * @brief Error codes.
  208. *
  209. * The negative error codes delimited by two underscores
  210. * (\c RD_KAFKA_RESP_ERR__..) denotes errors internal to librdkafka and are
  211. * displayed as \c \"Local: \<error string..\>\", while the error codes
  212. * delimited by a single underscore (\c RD_KAFKA_RESP_ERR_..) denote broker
  213. * errors and are displayed as \c \"Broker: \<error string..\>\".
  214. *
  215. * @sa Use rd_kafka_err2str() to translate an error code a human readable string
  216. */
  217. typedef enum {
  218. /* Internal errors to rdkafka: */
  219. /** Begin internal error codes */
  220. RD_KAFKA_RESP_ERR__BEGIN = -200,
  221. /** Received message is incorrect */
  222. RD_KAFKA_RESP_ERR__BAD_MSG = -199,
  223. /** Bad/unknown compression */
  224. RD_KAFKA_RESP_ERR__BAD_COMPRESSION = -198,
  225. /** Broker is going away */
  226. RD_KAFKA_RESP_ERR__DESTROY = -197,
  227. /** Generic failure */
  228. RD_KAFKA_RESP_ERR__FAIL = -196,
  229. /** Broker transport failure */
  230. RD_KAFKA_RESP_ERR__TRANSPORT = -195,
  231. /** Critical system resource */
  232. RD_KAFKA_RESP_ERR__CRIT_SYS_RESOURCE = -194,
  233. /** Failed to resolve broker */
  234. RD_KAFKA_RESP_ERR__RESOLVE = -193,
  235. /** Produced message timed out*/
  236. RD_KAFKA_RESP_ERR__MSG_TIMED_OUT = -192,
  237. /** Reached the end of the topic+partition queue on
  238. * the broker. Not really an error. */
  239. RD_KAFKA_RESP_ERR__PARTITION_EOF = -191,
  240. /** Permanent: Partition does not exist in cluster. */
  241. RD_KAFKA_RESP_ERR__UNKNOWN_PARTITION = -190,
  242. /** File or filesystem error */
  243. RD_KAFKA_RESP_ERR__FS = -189,
  244. /** Permanent: Topic does not exist in cluster. */
  245. RD_KAFKA_RESP_ERR__UNKNOWN_TOPIC = -188,
  246. /** All broker connections are down. */
  247. RD_KAFKA_RESP_ERR__ALL_BROKERS_DOWN = -187,
  248. /** Invalid argument, or invalid configuration */
  249. RD_KAFKA_RESP_ERR__INVALID_ARG = -186,
  250. /** Operation timed out */
  251. RD_KAFKA_RESP_ERR__TIMED_OUT = -185,
  252. /** Queue is full */
  253. RD_KAFKA_RESP_ERR__QUEUE_FULL = -184,
  254. /** ISR count < required.acks */
  255. RD_KAFKA_RESP_ERR__ISR_INSUFF = -183,
  256. /** Broker node update */
  257. RD_KAFKA_RESP_ERR__NODE_UPDATE = -182,
  258. /** SSL error */
  259. RD_KAFKA_RESP_ERR__SSL = -181,
  260. /** Waiting for coordinator to become available. */
  261. RD_KAFKA_RESP_ERR__WAIT_COORD = -180,
  262. /** Unknown client group */
  263. RD_KAFKA_RESP_ERR__UNKNOWN_GROUP = -179,
  264. /** Operation in progress */
  265. RD_KAFKA_RESP_ERR__IN_PROGRESS = -178,
  266. /** Previous operation in progress, wait for it to finish. */
  267. RD_KAFKA_RESP_ERR__PREV_IN_PROGRESS = -177,
  268. /** This operation would interfere with an existing subscription */
  269. RD_KAFKA_RESP_ERR__EXISTING_SUBSCRIPTION = -176,
  270. /** Assigned partitions (rebalance_cb) */
  271. RD_KAFKA_RESP_ERR__ASSIGN_PARTITIONS = -175,
  272. /** Revoked partitions (rebalance_cb) */
  273. RD_KAFKA_RESP_ERR__REVOKE_PARTITIONS = -174,
  274. /** Conflicting use */
  275. RD_KAFKA_RESP_ERR__CONFLICT = -173,
  276. /** Wrong state */
  277. RD_KAFKA_RESP_ERR__STATE = -172,
  278. /** Unknown protocol */
  279. RD_KAFKA_RESP_ERR__UNKNOWN_PROTOCOL = -171,
  280. /** Not implemented */
  281. RD_KAFKA_RESP_ERR__NOT_IMPLEMENTED = -170,
  282. /** Authentication failure*/
  283. RD_KAFKA_RESP_ERR__AUTHENTICATION = -169,
  284. /** No stored offset */
  285. RD_KAFKA_RESP_ERR__NO_OFFSET = -168,
  286. /** Outdated */
  287. RD_KAFKA_RESP_ERR__OUTDATED = -167,
  288. /** Timed out in queue */
  289. RD_KAFKA_RESP_ERR__TIMED_OUT_QUEUE = -166,
  290. /** Feature not supported by broker */
  291. RD_KAFKA_RESP_ERR__UNSUPPORTED_FEATURE = -165,
  292. /** Awaiting cache update */
  293. RD_KAFKA_RESP_ERR__WAIT_CACHE = -164,
  294. /** Operation interrupted (e.g., due to yield)) */
  295. RD_KAFKA_RESP_ERR__INTR = -163,
  296. /** Key serialization error */
  297. RD_KAFKA_RESP_ERR__KEY_SERIALIZATION = -162,
  298. /** Value serialization error */
  299. RD_KAFKA_RESP_ERR__VALUE_SERIALIZATION = -161,
  300. /** Key deserialization error */
  301. RD_KAFKA_RESP_ERR__KEY_DESERIALIZATION = -160,
  302. /** Value deserialization error */
  303. RD_KAFKA_RESP_ERR__VALUE_DESERIALIZATION = -159,
  304. /** Partial response */
  305. RD_KAFKA_RESP_ERR__PARTIAL = -158,
  306. /** Modification attempted on read-only object */
  307. RD_KAFKA_RESP_ERR__READ_ONLY = -157,
  308. /** No such entry / item not found */
  309. RD_KAFKA_RESP_ERR__NOENT = -156,
  310. /** Read underflow */
  311. RD_KAFKA_RESP_ERR__UNDERFLOW = -155,
  312. /** End internal error codes */
  313. RD_KAFKA_RESP_ERR__END = -100,
  314. /* Kafka broker errors: */
  315. /** Unknown broker error */
  316. RD_KAFKA_RESP_ERR_UNKNOWN = -1,
  317. /** Success */
  318. RD_KAFKA_RESP_ERR_NO_ERROR = 0,
  319. /** Offset out of range */
  320. RD_KAFKA_RESP_ERR_OFFSET_OUT_OF_RANGE = 1,
  321. /** Invalid message */
  322. RD_KAFKA_RESP_ERR_INVALID_MSG = 2,
  323. /** Unknown topic or partition */
  324. RD_KAFKA_RESP_ERR_UNKNOWN_TOPIC_OR_PART = 3,
  325. /** Invalid message size */
  326. RD_KAFKA_RESP_ERR_INVALID_MSG_SIZE = 4,
  327. /** Leader not available */
  328. RD_KAFKA_RESP_ERR_LEADER_NOT_AVAILABLE = 5,
  329. /** Not leader for partition */
  330. RD_KAFKA_RESP_ERR_NOT_LEADER_FOR_PARTITION = 6,
  331. /** Request timed out */
  332. RD_KAFKA_RESP_ERR_REQUEST_TIMED_OUT = 7,
  333. /** Broker not available */
  334. RD_KAFKA_RESP_ERR_BROKER_NOT_AVAILABLE = 8,
  335. /** Replica not available */
  336. RD_KAFKA_RESP_ERR_REPLICA_NOT_AVAILABLE = 9,
  337. /** Message size too large */
  338. RD_KAFKA_RESP_ERR_MSG_SIZE_TOO_LARGE = 10,
  339. /** StaleControllerEpochCode */
  340. RD_KAFKA_RESP_ERR_STALE_CTRL_EPOCH = 11,
  341. /** Offset metadata string too large */
  342. RD_KAFKA_RESP_ERR_OFFSET_METADATA_TOO_LARGE = 12,
  343. /** Broker disconnected before response received */
  344. RD_KAFKA_RESP_ERR_NETWORK_EXCEPTION = 13,
  345. /** Group coordinator load in progress */
  346. RD_KAFKA_RESP_ERR_GROUP_LOAD_IN_PROGRESS = 14,
  347. /** Group coordinator not available */
  348. RD_KAFKA_RESP_ERR_GROUP_COORDINATOR_NOT_AVAILABLE = 15,
  349. /** Not coordinator for group */
  350. RD_KAFKA_RESP_ERR_NOT_COORDINATOR_FOR_GROUP = 16,
  351. /** Invalid topic */
  352. RD_KAFKA_RESP_ERR_TOPIC_EXCEPTION = 17,
  353. /** Message batch larger than configured server segment size */
  354. RD_KAFKA_RESP_ERR_RECORD_LIST_TOO_LARGE = 18,
  355. /** Not enough in-sync replicas */
  356. RD_KAFKA_RESP_ERR_NOT_ENOUGH_REPLICAS = 19,
  357. /** Message(s) written to insufficient number of in-sync replicas */
  358. RD_KAFKA_RESP_ERR_NOT_ENOUGH_REPLICAS_AFTER_APPEND = 20,
  359. /** Invalid required acks value */
  360. RD_KAFKA_RESP_ERR_INVALID_REQUIRED_ACKS = 21,
  361. /** Specified group generation id is not valid */
  362. RD_KAFKA_RESP_ERR_ILLEGAL_GENERATION = 22,
  363. /** Inconsistent group protocol */
  364. RD_KAFKA_RESP_ERR_INCONSISTENT_GROUP_PROTOCOL = 23,
  365. /** Invalid group.id */
  366. RD_KAFKA_RESP_ERR_INVALID_GROUP_ID = 24,
  367. /** Unknown member */
  368. RD_KAFKA_RESP_ERR_UNKNOWN_MEMBER_ID = 25,
  369. /** Invalid session timeout */
  370. RD_KAFKA_RESP_ERR_INVALID_SESSION_TIMEOUT = 26,
  371. /** Group rebalance in progress */
  372. RD_KAFKA_RESP_ERR_REBALANCE_IN_PROGRESS = 27,
  373. /** Commit offset data size is not valid */
  374. RD_KAFKA_RESP_ERR_INVALID_COMMIT_OFFSET_SIZE = 28,
  375. /** Topic authorization failed */
  376. RD_KAFKA_RESP_ERR_TOPIC_AUTHORIZATION_FAILED = 29,
  377. /** Group authorization failed */
  378. RD_KAFKA_RESP_ERR_GROUP_AUTHORIZATION_FAILED = 30,
  379. /** Cluster authorization failed */
  380. RD_KAFKA_RESP_ERR_CLUSTER_AUTHORIZATION_FAILED = 31,
  381. /** Invalid timestamp */
  382. RD_KAFKA_RESP_ERR_INVALID_TIMESTAMP = 32,
  383. /** Unsupported SASL mechanism */
  384. RD_KAFKA_RESP_ERR_UNSUPPORTED_SASL_MECHANISM = 33,
  385. /** Illegal SASL state */
  386. RD_KAFKA_RESP_ERR_ILLEGAL_SASL_STATE = 34,
  387. /** Unuspported version */
  388. RD_KAFKA_RESP_ERR_UNSUPPORTED_VERSION = 35,
  389. /** Topic already exists */
  390. RD_KAFKA_RESP_ERR_TOPIC_ALREADY_EXISTS = 36,
  391. /** Invalid number of partitions */
  392. RD_KAFKA_RESP_ERR_INVALID_PARTITIONS = 37,
  393. /** Invalid replication factor */
  394. RD_KAFKA_RESP_ERR_INVALID_REPLICATION_FACTOR = 38,
  395. /** Invalid replica assignment */
  396. RD_KAFKA_RESP_ERR_INVALID_REPLICA_ASSIGNMENT = 39,
  397. /** Invalid config */
  398. RD_KAFKA_RESP_ERR_INVALID_CONFIG = 40,
  399. /** Not controller for cluster */
  400. RD_KAFKA_RESP_ERR_NOT_CONTROLLER = 41,
  401. /** Invalid request */
  402. RD_KAFKA_RESP_ERR_INVALID_REQUEST = 42,
  403. /** Message format on broker does not support request */
  404. RD_KAFKA_RESP_ERR_UNSUPPORTED_FOR_MESSAGE_FORMAT = 43,
  405. /** Isolation policy volation */
  406. RD_KAFKA_RESP_ERR_POLICY_VIOLATION = 44,
  407. /** Broker received an out of order sequence number */
  408. RD_KAFKA_RESP_ERR_OUT_OF_ORDER_SEQUENCE_NUMBER = 45,
  409. /** Broker received a duplicate sequence number */
  410. RD_KAFKA_RESP_ERR_DUPLICATE_SEQUENCE_NUMBER = 46,
  411. /** Producer attempted an operation with an old epoch */
  412. RD_KAFKA_RESP_ERR_INVALID_PRODUCER_EPOCH = 47,
  413. /** Producer attempted a transactional operation in an invalid state */
  414. RD_KAFKA_RESP_ERR_INVALID_TXN_STATE = 48,
  415. /** Producer attempted to use a producer id which is not
  416. * currently assigned to its transactional id */
  417. RD_KAFKA_RESP_ERR_INVALID_PRODUCER_ID_MAPPING = 49,
  418. /** Transaction timeout is larger than the maximum
  419. * value allowed by the broker's max.transaction.timeout.ms */
  420. RD_KAFKA_RESP_ERR_INVALID_TRANSACTION_TIMEOUT = 50,
  421. /** Producer attempted to update a transaction while another
  422. * concurrent operation on the same transaction was ongoing */
  423. RD_KAFKA_RESP_ERR_CONCURRENT_TRANSACTIONS = 51,
  424. /** Indicates that the transaction coordinator sending a
  425. * WriteTxnMarker is no longer the current coordinator for a
  426. * given producer */
  427. RD_KAFKA_RESP_ERR_TRANSACTION_COORDINATOR_FENCED = 52,
  428. /** Transactional Id authorization failed */
  429. RD_KAFKA_RESP_ERR_TRANSACTIONAL_ID_AUTHORIZATION_FAILED = 53,
  430. /** Security features are disabled */
  431. RD_KAFKA_RESP_ERR_SECURITY_DISABLED = 54,
  432. /** Operation not attempted */
  433. RD_KAFKA_RESP_ERR_OPERATION_NOT_ATTEMPTED = 55,
  434. RD_KAFKA_RESP_ERR_END_ALL,
  435. } rd_kafka_resp_err_t;
  436. /**
  437. * @brief Error code value, name and description.
  438. * Typically for use with language bindings to automatically expose
  439. * the full set of librdkafka error codes.
  440. */
  441. struct rd_kafka_err_desc {
  442. rd_kafka_resp_err_t code;/**< Error code */
  443. const char *name; /**< Error name, same as code enum sans prefix */
  444. const char *desc; /**< Human readable error description. */
  445. };
  446. /**
  447. * @brief Returns the full list of error codes.
  448. */
  449. RD_EXPORT
  450. void rd_kafka_get_err_descs (const struct rd_kafka_err_desc **errdescs,
  451. size_t *cntp);
  452. /**
  453. * @brief Returns a human readable representation of a kafka error.
  454. *
  455. * @param err Error code to translate
  456. */
  457. RD_EXPORT
  458. const char *rd_kafka_err2str (rd_kafka_resp_err_t err);
  459. /**
  460. * @brief Returns the error code name (enum name).
  461. *
  462. * @param err Error code to translate
  463. */
  464. RD_EXPORT
  465. const char *rd_kafka_err2name (rd_kafka_resp_err_t err);
  466. /**
  467. * @brief Returns the last error code generated by a legacy API call
  468. * in the current thread.
  469. *
  470. * The legacy APIs are the ones using errno to propagate error value, namely:
  471. * - rd_kafka_topic_new()
  472. * - rd_kafka_consume_start()
  473. * - rd_kafka_consume_stop()
  474. * - rd_kafka_consume()
  475. * - rd_kafka_consume_batch()
  476. * - rd_kafka_consume_callback()
  477. * - rd_kafka_consume_queue()
  478. * - rd_kafka_produce()
  479. *
  480. * The main use for this function is to avoid converting system \p errno
  481. * values to rd_kafka_resp_err_t codes for legacy APIs.
  482. *
  483. * @remark The last error is stored per-thread, if multiple rd_kafka_t handles
  484. * are used in the same application thread the developer needs to
  485. * make sure rd_kafka_last_error() is called immediately after
  486. * a failed API call.
  487. *
  488. * @remark errno propagation from librdkafka is not safe on Windows
  489. * and should not be used, use rd_kafka_last_error() instead.
  490. */
  491. RD_EXPORT
  492. rd_kafka_resp_err_t rd_kafka_last_error (void);
  493. /**
  494. * @brief Converts the system errno value \p errnox to a rd_kafka_resp_err_t
  495. * error code upon failure from the following functions:
  496. * - rd_kafka_topic_new()
  497. * - rd_kafka_consume_start()
  498. * - rd_kafka_consume_stop()
  499. * - rd_kafka_consume()
  500. * - rd_kafka_consume_batch()
  501. * - rd_kafka_consume_callback()
  502. * - rd_kafka_consume_queue()
  503. * - rd_kafka_produce()
  504. *
  505. * @param errnox System errno value to convert
  506. *
  507. * @returns Appropriate error code for \p errnox
  508. *
  509. * @remark A better alternative is to call rd_kafka_last_error() immediately
  510. * after any of the above functions return -1 or NULL.
  511. *
  512. * @deprecated Use rd_kafka_last_error() to retrieve the last error code
  513. * set by the legacy librdkafka APIs.
  514. *
  515. * @sa rd_kafka_last_error()
  516. */
  517. RD_EXPORT RD_DEPRECATED
  518. rd_kafka_resp_err_t rd_kafka_errno2err(int errnox);
  519. /**
  520. * @brief Returns the thread-local system errno
  521. *
  522. * On most platforms this is the same as \p errno but in case of different
  523. * runtimes between library and application (e.g., Windows static DLLs)
  524. * this provides a means for exposing the errno librdkafka uses.
  525. *
  526. * @remark The value is local to the current calling thread.
  527. *
  528. * @deprecated Use rd_kafka_last_error() to retrieve the last error code
  529. * set by the legacy librdkafka APIs.
  530. */
  531. RD_EXPORT RD_DEPRECATED
  532. int rd_kafka_errno (void);
  533. /**
  534. * @brief Topic+Partition place holder
  535. *
  536. * Generic place holder for a Topic+Partition and its related information
  537. * used for multiple purposes:
  538. * - consumer offset (see rd_kafka_commit(), et.al.)
  539. * - group rebalancing callback (rd_kafka_conf_set_rebalance_cb())
  540. * - offset commit result callback (rd_kafka_conf_set_offset_commit_cb())
  541. */
  542. /**
  543. * @brief Generic place holder for a specific Topic+Partition.
  544. *
  545. * @sa rd_kafka_topic_partition_list_new()
  546. */
  547. typedef struct rd_kafka_topic_partition_s {
  548. char *topic; /**< Topic name */
  549. int32_t partition; /**< Partition */
  550. int64_t offset; /**< Offset */
  551. void *metadata; /**< Metadata */
  552. size_t metadata_size; /**< Metadata size */
  553. void *opaque; /**< Application opaque */
  554. rd_kafka_resp_err_t err; /**< Error code, depending on use. */
  555. void *_private; /**< INTERNAL USE ONLY,
  556. * INITIALIZE TO ZERO, DO NOT TOUCH */
  557. } rd_kafka_topic_partition_t;
  558. /**
  559. * @brief Destroy a rd_kafka_topic_partition_t.
  560. * @remark This must not be called for elements in a topic partition list.
  561. */
  562. RD_EXPORT
  563. void rd_kafka_topic_partition_destroy (rd_kafka_topic_partition_t *rktpar);
  564. /**
  565. * @brief A growable list of Topic+Partitions.
  566. *
  567. */
  568. typedef struct rd_kafka_topic_partition_list_s {
  569. int cnt; /**< Current number of elements */
  570. int size; /**< Current allocated size */
  571. rd_kafka_topic_partition_t *elems; /**< Element array[] */
  572. } rd_kafka_topic_partition_list_t;
  573. /**
  574. * @brief Create a new list/vector Topic+Partition container.
  575. *
  576. * @param size Initial allocated size used when the expected number of
  577. * elements is known or can be estimated.
  578. * Avoids reallocation and possibly relocation of the
  579. * elems array.
  580. *
  581. * @returns A newly allocated Topic+Partition list.
  582. *
  583. * @remark Use rd_kafka_topic_partition_list_destroy() to free all resources
  584. * in use by a list and the list itself.
  585. * @sa rd_kafka_topic_partition_list_add()
  586. */
  587. RD_EXPORT
  588. rd_kafka_topic_partition_list_t *rd_kafka_topic_partition_list_new (int size);
  589. /**
  590. * @brief Free all resources used by the list and the list itself.
  591. */
  592. RD_EXPORT
  593. void
  594. rd_kafka_topic_partition_list_destroy (rd_kafka_topic_partition_list_t *rkparlist);
  595. /**
  596. * @brief Add topic+partition to list
  597. *
  598. * @param rktparlist List to extend
  599. * @param topic Topic name (copied)
  600. * @param partition Partition id
  601. *
  602. * @returns The object which can be used to fill in additionals fields.
  603. */
  604. RD_EXPORT
  605. rd_kafka_topic_partition_t *
  606. rd_kafka_topic_partition_list_add (rd_kafka_topic_partition_list_t *rktparlist,
  607. const char *topic, int32_t partition);
  608. /**
  609. * @brief Add range of partitions from \p start to \p stop inclusive.
  610. *
  611. * @param rktparlist List to extend
  612. * @param topic Topic name (copied)
  613. * @param start Start partition of range
  614. * @param stop Last partition of range (inclusive)
  615. */
  616. RD_EXPORT
  617. void
  618. rd_kafka_topic_partition_list_add_range (rd_kafka_topic_partition_list_t
  619. *rktparlist,
  620. const char *topic,
  621. int32_t start, int32_t stop);
  622. /**
  623. * @brief Delete partition from list.
  624. *
  625. * @param rktparlist List to modify
  626. * @param topic Topic name to match
  627. * @param partition Partition to match
  628. *
  629. * @returns 1 if partition was found (and removed), else 0.
  630. *
  631. * @remark Any held indices to elems[] are unusable after this call returns 1.
  632. */
  633. RD_EXPORT
  634. int
  635. rd_kafka_topic_partition_list_del (rd_kafka_topic_partition_list_t *rktparlist,
  636. const char *topic, int32_t partition);
  637. /**
  638. * @brief Delete partition from list by elems[] index.
  639. *
  640. * @returns 1 if partition was found (and removed), else 0.
  641. *
  642. * @sa rd_kafka_topic_partition_list_del()
  643. */
  644. RD_EXPORT
  645. int
  646. rd_kafka_topic_partition_list_del_by_idx (
  647. rd_kafka_topic_partition_list_t *rktparlist,
  648. int idx);
  649. /**
  650. * @brief Make a copy of an existing list.
  651. *
  652. * @param src The existing list to copy.
  653. *
  654. * @returns A new list fully populated to be identical to \p src
  655. */
  656. RD_EXPORT
  657. rd_kafka_topic_partition_list_t *
  658. rd_kafka_topic_partition_list_copy (const rd_kafka_topic_partition_list_t *src);
  659. /**
  660. * @brief Set offset to \p offset for \p topic and \p partition
  661. *
  662. * @returns RD_KAFKA_RESP_ERR_NO_ERROR on success or
  663. * RD_KAFKA_RESP_ERR__UNKNOWN_PARTITION if \p partition was not found
  664. * in the list.
  665. */
  666. RD_EXPORT
  667. rd_kafka_resp_err_t rd_kafka_topic_partition_list_set_offset (
  668. rd_kafka_topic_partition_list_t *rktparlist,
  669. const char *topic, int32_t partition, int64_t offset);
  670. /**
  671. * @brief Find element by \p topic and \p partition.
  672. *
  673. * @returns a pointer to the first matching element, or NULL if not found.
  674. */
  675. RD_EXPORT
  676. rd_kafka_topic_partition_t *
  677. rd_kafka_topic_partition_list_find (rd_kafka_topic_partition_list_t *rktparlist,
  678. const char *topic, int32_t partition);
  679. /**
  680. * @brief Sort list using comparator \p cmp.
  681. *
  682. * If \p cmp is NULL the default comparator will be used that
  683. * sorts by ascending topic name and partition.
  684. *
  685. */
  686. RD_EXPORT void
  687. rd_kafka_topic_partition_list_sort (rd_kafka_topic_partition_list_t *rktparlist,
  688. int (*cmp) (const void *a, const void *b,
  689. void *opaque),
  690. void *opaque);
  691. /**@}*/
  692. /**
  693. * @name Var-arg tag types
  694. * @{
  695. *
  696. */
  697. /**
  698. * @enum rd_kafka_vtype_t
  699. *
  700. * @brief Var-arg tag types
  701. *
  702. * @sa rd_kafka_producev()
  703. */
  704. typedef enum rd_kafka_vtype_t {
  705. RD_KAFKA_VTYPE_END, /**< va-arg sentinel */
  706. RD_KAFKA_VTYPE_TOPIC, /**< (const char *) Topic name */
  707. RD_KAFKA_VTYPE_RKT, /**< (rd_kafka_topic_t *) Topic handle */
  708. RD_KAFKA_VTYPE_PARTITION, /**< (int32_t) Partition */
  709. RD_KAFKA_VTYPE_VALUE, /**< (void *, size_t) Message value (payload)*/
  710. RD_KAFKA_VTYPE_KEY, /**< (void *, size_t) Message key */
  711. RD_KAFKA_VTYPE_OPAQUE, /**< (void *) Application opaque */
  712. RD_KAFKA_VTYPE_MSGFLAGS, /**< (int) RD_KAFKA_MSG_F_.. flags */
  713. RD_KAFKA_VTYPE_TIMESTAMP, /**< (int64_t) Milliseconds since epoch UTC */
  714. RD_KAFKA_VTYPE_HEADER, /**< (const char *, const void *, ssize_t)
  715. * Message Header */
  716. RD_KAFKA_VTYPE_HEADERS, /**< (rd_kafka_headers_t *) Headers list */
  717. } rd_kafka_vtype_t;
  718. /**
  719. * @brief Convenience macros for rd_kafka_vtype_t that takes the
  720. * correct arguments for each vtype.
  721. */
  722. /*!
  723. * va-arg end sentinel used to terminate the variable argument list
  724. */
  725. #define RD_KAFKA_V_END RD_KAFKA_VTYPE_END
  726. /*!
  727. * Topic name (const char *)
  728. */
  729. #define RD_KAFKA_V_TOPIC(topic) \
  730. _LRK_TYPECHECK(RD_KAFKA_VTYPE_TOPIC, const char *, topic), \
  731. (const char *)topic
  732. /*!
  733. * Topic object (rd_kafka_topic_t *)
  734. */
  735. #define RD_KAFKA_V_RKT(rkt) \
  736. _LRK_TYPECHECK(RD_KAFKA_VTYPE_RKT, rd_kafka_topic_t *, rkt), \
  737. (rd_kafka_topic_t *)rkt
  738. /*!
  739. * Partition (int32_t)
  740. */
  741. #define RD_KAFKA_V_PARTITION(partition) \
  742. _LRK_TYPECHECK(RD_KAFKA_VTYPE_PARTITION, int32_t, partition), \
  743. (int32_t)partition
  744. /*!
  745. * Message value/payload pointer and length (void *, size_t)
  746. */
  747. #define RD_KAFKA_V_VALUE(VALUE,LEN) \
  748. _LRK_TYPECHECK2(RD_KAFKA_VTYPE_VALUE, void *, VALUE, size_t, LEN), \
  749. (void *)VALUE, (size_t)LEN
  750. /*!
  751. * Message key pointer and length (const void *, size_t)
  752. */
  753. #define RD_KAFKA_V_KEY(KEY,LEN) \
  754. _LRK_TYPECHECK2(RD_KAFKA_VTYPE_KEY, const void *, KEY, size_t, LEN), \
  755. (void *)KEY, (size_t)LEN
  756. /*!
  757. * Message opaque pointer (void *)
  758. * Same as \c produce(.., msg_opaque), and \c rkmessage->_private .
  759. */
  760. #define RD_KAFKA_V_OPAQUE(opaque) \
  761. _LRK_TYPECHECK(RD_KAFKA_VTYPE_OPAQUE, void *, opaque), \
  762. (void *)opaque
  763. /*!
  764. * Message flags (int)
  765. * @sa RD_KAFKA_MSG_F_COPY, et.al.
  766. */
  767. #define RD_KAFKA_V_MSGFLAGS(msgflags) \
  768. _LRK_TYPECHECK(RD_KAFKA_VTYPE_MSGFLAGS, int, msgflags), \
  769. (int)msgflags
  770. /*!
  771. * Timestamp (int64_t)
  772. */
  773. #define RD_KAFKA_V_TIMESTAMP(timestamp) \
  774. _LRK_TYPECHECK(RD_KAFKA_VTYPE_TIMESTAMP, int64_t, timestamp), \
  775. (int64_t)timestamp
  776. /*!
  777. * Add Message Header (const char *NAME, const void *VALUE, ssize_t LEN).
  778. * @sa rd_kafka_header_add()
  779. * @remark RD_KAFKA_V_HEADER() and RD_KAFKA_V_HEADERS() MUST NOT be mixed
  780. * in the same call to producev().
  781. */
  782. #define RD_KAFKA_V_HEADER(NAME,VALUE,LEN) \
  783. _LRK_TYPECHECK3(RD_KAFKA_VTYPE_HEADER, const char *, NAME, \
  784. const void *, VALUE, ssize_t, LEN), \
  785. (const char *)NAME, (const void *)VALUE, (ssize_t)LEN
  786. /*!
  787. * Message Headers list (rd_kafka_headers_t *).
  788. * The message object will assume ownership of the headers (unless producev()
  789. * fails).
  790. * Any existing headers will be replaced.
  791. * @sa rd_kafka_message_set_headers()
  792. * @remark RD_KAFKA_V_HEADER() and RD_KAFKA_V_HEADERS() MUST NOT be mixed
  793. * in the same call to producev().
  794. */
  795. #define RD_KAFKA_V_HEADERS(HDRS) \
  796. _LRK_TYPECHECK(RD_KAFKA_VTYPE_HEADERS, rd_kafka_headers_t *, HDRS), \
  797. (rd_kafka_headers_t *)HDRS
  798. /**@}*/
  799. /**
  800. * @name Message headers
  801. * @{
  802. *
  803. * @brief Message headers consist of a list of (string key, binary value) pairs.
  804. * Duplicate keys are supported and the order in which keys were
  805. * added are retained.
  806. *
  807. * Header values are considered binary and may have three types of
  808. * value:
  809. * - proper value with size > 0 and a valid pointer
  810. * - empty value with size = 0 and any non-NULL pointer
  811. * - null value with size = 0 and a NULL pointer
  812. *
  813. * Headers require Apache Kafka broker version v0.11.0.0 or later.
  814. *
  815. * Header operations are O(n).
  816. */
  817. typedef struct rd_kafka_headers_s rd_kafka_headers_t;
  818. /**
  819. * @brief Create a new headers list.
  820. *
  821. * @param initial_count Preallocate space for this number of headers.
  822. * Any number of headers may be added, updated and
  823. * removed regardless of the initial count.
  824. */
  825. RD_EXPORT rd_kafka_headers_t *rd_kafka_headers_new (size_t initial_count);
  826. /**
  827. * @brief Destroy the headers list. The object and any returned value pointers
  828. * are not usable after this call.
  829. */
  830. RD_EXPORT void rd_kafka_headers_destroy (rd_kafka_headers_t *hdrs);
  831. /**
  832. * @brief Make a copy of headers list \p src.
  833. */
  834. RD_EXPORT rd_kafka_headers_t *
  835. rd_kafka_headers_copy (const rd_kafka_headers_t *src);
  836. /**
  837. * @brief Add header with name \p name and value \p val (copied) of size
  838. * \p size (not including null-terminator).
  839. *
  840. * @param name Header name.
  841. * @param name_size Header name size (not including the null-terminator).
  842. * If -1 the \p name length is automatically acquired using
  843. * strlen().
  844. * @param value Pointer to header value, or NULL (set size to 0 or -1).
  845. * @param value_size Size of header value. If -1 the \p value is assumed to be a
  846. * null-terminated string and the length is automatically
  847. * acquired using strlen().
  848. *
  849. * @returns RD_KAFKA_RESP_ERR__READ_ONLY if the headers are read-only,
  850. * else RD_KAFKA_RESP_ERR_NO_ERROR.
  851. */
  852. RD_EXPORT rd_kafka_resp_err_t
  853. rd_kafka_header_add (rd_kafka_headers_t *hdrs,
  854. const char *name, ssize_t name_size,
  855. const void *value, ssize_t value_size);
  856. /**
  857. * @brief Remove all headers for the given key (if any).
  858. *
  859. * @returns RD_KAFKA_RESP_ERR__READ_ONLY if the headers are read-only,
  860. * RD_KAFKA_RESP_ERR__NOENT if no matching headers were found,
  861. * else RD_KAFKA_RESP_ERR_NO_ERROR if headers were removed.
  862. */
  863. RD_EXPORT rd_kafka_resp_err_t
  864. rd_kafka_header_remove (rd_kafka_headers_t *hdrs, const char *name);
  865. /**
  866. * @brief Find last header in list \p hdrs matching \p name.
  867. *
  868. * @param name Header to find (last match).
  869. * @param valuep (out) Set to a (null-terminated) const pointer to the value
  870. * (may be NULL).
  871. * @param sizep (out) Set to the value's size (not including null-terminator).
  872. *
  873. * @returns RD_KAFKA_RESP_ERR_NO_ERROR if an entry was found, else
  874. * RD_KAFKA_RESP_ERR__NOENT.
  875. *
  876. * @remark The returned pointer in \p valuep includes a trailing null-terminator
  877. * that is not accounted for in \p sizep.
  878. * @remark The returned pointer is only valid as long as the headers list and
  879. * the header item is valid.
  880. */
  881. RD_EXPORT rd_kafka_resp_err_t
  882. rd_kafka_header_get_last (const rd_kafka_headers_t *hdrs,
  883. const char *name, const void **valuep, size_t *sizep);
  884. /**
  885. * @brief Iterator for headers matching \p name.
  886. *
  887. * Same semantics as rd_kafka_header_get_last()
  888. *
  889. * @param hdrs Headers to iterate.
  890. * @param idx Iterator index, start at 0 and increment by one for each call
  891. * as long as RD_KAFKA_RESP_ERR_NO_ERROR is returned.
  892. * @param name Header name to match.
  893. * @param valuep (out) Set to a (null-terminated) const pointer to the value
  894. * (may be NULL).
  895. * @param sizep (out) Set to the value's size (not including null-terminator).
  896. */
  897. RD_EXPORT rd_kafka_resp_err_t
  898. rd_kafka_header_get (const rd_kafka_headers_t *hdrs, size_t idx,
  899. const char *name, const void **valuep, size_t *sizep);
  900. /**
  901. * @brief Iterator for all headers.
  902. *
  903. * Same semantics as rd_kafka_header_get()
  904. *
  905. * @sa rd_kafka_header_get()
  906. */
  907. RD_EXPORT rd_kafka_resp_err_t
  908. rd_kafka_header_get_all (const rd_kafka_headers_t *hdrs, size_t idx,
  909. const char **namep,
  910. const void **valuep, size_t *sizep);
  911. /**@}*/
  912. /**
  913. * @name Kafka messages
  914. * @{
  915. *
  916. */
  917. // FIXME: This doesn't show up in docs for some reason
  918. // "Compound rd_kafka_message_t is not documented."
  919. /**
  920. * @brief A Kafka message as returned by the \c rd_kafka_consume*() family
  921. * of functions as well as provided to the Producer \c dr_msg_cb().
  922. *
  923. * For the consumer this object has two purposes:
  924. * - provide the application with a consumed message. (\c err == 0)
  925. * - report per-topic+partition consumer errors (\c err != 0)
  926. *
  927. * The application must check \c err to decide what action to take.
  928. *
  929. * When the application is finished with a message it must call
  930. * rd_kafka_message_destroy() unless otherwise noted.
  931. */
  932. typedef struct rd_kafka_message_s {
  933. rd_kafka_resp_err_t err; /**< Non-zero for error signaling. */
  934. rd_kafka_topic_t *rkt; /**< Topic */
  935. int32_t partition; /**< Partition */
  936. void *payload; /**< Producer: original message payload.
  937. * Consumer: Depends on the value of \c err :
  938. * - \c err==0: Message payload.
  939. * - \c err!=0: Error string */
  940. size_t len; /**< Depends on the value of \c err :
  941. * - \c err==0: Message payload length
  942. * - \c err!=0: Error string length */
  943. void *key; /**< Depends on the value of \c err :
  944. * - \c err==0: Optional message key */
  945. size_t key_len; /**< Depends on the value of \c err :
  946. * - \c err==0: Optional message key length*/
  947. int64_t offset; /**< Consume:
  948. * - Message offset (or offset for error
  949. * if \c err!=0 if applicable).
  950. * - dr_msg_cb:
  951. * Message offset assigned by broker.
  952. * If \c produce.offset.report is set then
  953. * each message will have this field set,
  954. * otherwise only the last message in
  955. * each produced internal batch will
  956. * have this field set, otherwise 0. */
  957. void *_private; /**< Consume:
  958. * - rdkafka private pointer: DO NOT MODIFY
  959. * - dr_msg_cb:
  960. * msg_opaque from produce() call */
  961. } rd_kafka_message_t;
  962. /**
  963. * @brief Frees resources for \p rkmessage and hands ownership back to rdkafka.
  964. */
  965. RD_EXPORT
  966. void rd_kafka_message_destroy(rd_kafka_message_t *rkmessage);
  967. /**
  968. * @brief Returns the error string for an errored rd_kafka_message_t or NULL if
  969. * there was no error.
  970. *
  971. * @remark This function MUST NOT be used with the producer.
  972. */
  973. static RD_INLINE const char *
  974. RD_UNUSED
  975. rd_kafka_message_errstr(const rd_kafka_message_t *rkmessage) {
  976. if (!rkmessage->err)
  977. return NULL;
  978. if (rkmessage->payload)
  979. return (const char *)rkmessage->payload;
  980. return rd_kafka_err2str(rkmessage->err);
  981. }
  982. /**
  983. * @brief Returns the message timestamp for a consumed message.
  984. *
  985. * The timestamp is the number of milliseconds since the epoch (UTC).
  986. *
  987. * \p tstype (if not NULL) is updated to indicate the type of timestamp.
  988. *
  989. * @returns message timestamp, or -1 if not available.
  990. *
  991. * @remark Message timestamps require broker version 0.10.0 or later.
  992. */
  993. RD_EXPORT
  994. int64_t rd_kafka_message_timestamp (const rd_kafka_message_t *rkmessage,
  995. rd_kafka_timestamp_type_t *tstype);
  996. /**
  997. * @brief Returns the latency for a produced message measured from
  998. * the produce() call.
  999. *
  1000. * @returns the latency in microseconds, or -1 if not available.
  1001. */
  1002. RD_EXPORT
  1003. int64_t rd_kafka_message_latency (const rd_kafka_message_t *rkmessage);
  1004. /**
  1005. * @brief Get the message header list.
  1006. *
  1007. * The returned pointer in \p *hdrsp is associated with the \p rkmessage and
  1008. * must not be used after destruction of the message object or the header
  1009. * list is replaced with rd_kafka_message_set_headers().
  1010. *
  1011. * @returns RD_KAFKA_RESP_ERR_NO_ERROR if headers were returned,
  1012. * RD_KAFKA_RESP_ERR__NOENT if the message has no headers,
  1013. * or another error code if the headers could not be parsed.
  1014. *
  1015. * @remark Headers require broker version 0.11.0.0 or later.
  1016. *
  1017. * @remark As an optimization the raw protocol headers are parsed on
  1018. * the first call to this function.
  1019. */
  1020. RD_EXPORT rd_kafka_resp_err_t
  1021. rd_kafka_message_headers (const rd_kafka_message_t *rkmessage,
  1022. rd_kafka_headers_t **hdrsp);
  1023. /**
  1024. * @brief Get the message header list and detach the list from the message
  1025. * making the application the owner of the headers.
  1026. * The application must eventually destroy the headers using
  1027. * rd_kafka_headers_destroy().
  1028. * The message's headers will be set to NULL.
  1029. *
  1030. * Otherwise same semantics as rd_kafka_message_headers()
  1031. *
  1032. * @sa rd_kafka_message_headers
  1033. */
  1034. RD_EXPORT rd_kafka_resp_err_t
  1035. rd_kafka_message_detach_headers (rd_kafka_message_t *rkmessage,
  1036. rd_kafka_headers_t **hdrsp);
  1037. /**
  1038. * @brief Replace the message's current headers with a new list.
  1039. *
  1040. * @param hdrs New header list. The message object assumes ownership of
  1041. * the list, the list will be destroyed automatically with
  1042. * the message object.
  1043. * The new headers list may be updated until the message object
  1044. * is passed or returned to librdkafka.
  1045. *
  1046. * @remark The existing headers object, if any, will be destroyed.
  1047. */
  1048. RD_EXPORT
  1049. void rd_kafka_message_set_headers (rd_kafka_message_t *rkmessage,
  1050. rd_kafka_headers_t *hdrs);
  1051. /**
  1052. * @brief Returns the number of header key/value pairs
  1053. *
  1054. * @param hdrs Headers to count
  1055. */
  1056. RD_EXPORT size_t rd_kafka_header_cnt (const rd_kafka_headers_t *hdrs);
  1057. /**@}*/
  1058. /**
  1059. * @name Configuration interface
  1060. * @{
  1061. *
  1062. * @brief Main/global configuration property interface
  1063. *
  1064. */
  1065. /**
  1066. * @enum rd_kafka_conf_res_t
  1067. * @brief Configuration result type
  1068. */
  1069. typedef enum {
  1070. RD_KAFKA_CONF_UNKNOWN = -2, /**< Unknown configuration name. */
  1071. RD_KAFKA_CONF_INVALID = -1, /**< Invalid configuration value. */
  1072. RD_KAFKA_CONF_OK = 0 /**< Configuration okay */
  1073. } rd_kafka_conf_res_t;
  1074. /**
  1075. * @brief Create configuration object.
  1076. *
  1077. * When providing your own configuration to the \c rd_kafka_*_new_*() calls
  1078. * the rd_kafka_conf_t objects needs to be created with this function
  1079. * which will set up the defaults.
  1080. * I.e.:
  1081. * @code
  1082. * rd_kafka_conf_t *myconf;
  1083. * rd_kafka_conf_res_t res;
  1084. *
  1085. * myconf = rd_kafka_conf_new();
  1086. * res = rd_kafka_conf_set(myconf, "socket.timeout.ms", "600",
  1087. * errstr, sizeof(errstr));
  1088. * if (res != RD_KAFKA_CONF_OK)
  1089. * die("%s\n", errstr);
  1090. *
  1091. * rk = rd_kafka_new(..., myconf);
  1092. * @endcode
  1093. *
  1094. * Please see CONFIGURATION.md for the default settings or use
  1095. * rd_kafka_conf_properties_show() to provide the information at runtime.
  1096. *
  1097. * The properties are identical to the Apache Kafka configuration properties
  1098. * whenever possible.
  1099. *
  1100. * @returns A new rd_kafka_conf_t object with defaults set.
  1101. *
  1102. * @sa rd_kafka_conf_set(), rd_kafka_conf_destroy()
  1103. */
  1104. RD_EXPORT
  1105. rd_kafka_conf_t *rd_kafka_conf_new(void);
  1106. /**
  1107. * @brief Destroys a conf object.
  1108. */
  1109. RD_EXPORT
  1110. void rd_kafka_conf_destroy(rd_kafka_conf_t *conf);
  1111. /**
  1112. * @brief Creates a copy/duplicate of configuration object \p conf
  1113. *
  1114. * @remark Interceptors are NOT copied to the new configuration object.
  1115. * @sa rd_kafka_interceptor_f_on_conf_dup
  1116. */
  1117. RD_EXPORT
  1118. rd_kafka_conf_t *rd_kafka_conf_dup(const rd_kafka_conf_t *conf);
  1119. /**
  1120. * @brief Same as rd_kafka_conf_dup() but with an array of property name
  1121. * prefixes to filter out (ignore) when copying.
  1122. */
  1123. RD_EXPORT
  1124. rd_kafka_conf_t *rd_kafka_conf_dup_filter (const rd_kafka_conf_t *conf,
  1125. size_t filter_cnt,
  1126. const char **filter);
  1127. /**
  1128. * @brief Sets a configuration property.
  1129. *
  1130. * \p conf must have been previously created with rd_kafka_conf_new().
  1131. *
  1132. * Fallthrough:
  1133. * Topic-level configuration properties may be set using this interface
  1134. * in which case they are applied on the \c default_topic_conf.
  1135. * If no \c default_topic_conf has been set one will be created.
  1136. * Any sub-sequent rd_kafka_conf_set_default_topic_conf() calls will
  1137. * replace the current default topic configuration.
  1138. *
  1139. * @returns \c rd_kafka_conf_res_t to indicate success or failure.
  1140. * In case of failure \p errstr is updated to contain a human readable
  1141. * error string.
  1142. */
  1143. RD_EXPORT
  1144. rd_kafka_conf_res_t rd_kafka_conf_set(rd_kafka_conf_t *conf,
  1145. const char *name,
  1146. const char *value,
  1147. char *errstr, size_t errstr_size);
  1148. /**
  1149. * @brief Enable event sourcing.
  1150. * \p events is a bitmask of \c RD_KAFKA_EVENT_* of events to enable
  1151. * for consumption by `rd_kafka_queue_poll()`.
  1152. */
  1153. RD_EXPORT
  1154. void rd_kafka_conf_set_events(rd_kafka_conf_t *conf, int events);
  1155. /**
  1156. @deprecated See rd_kafka_conf_set_dr_msg_cb()
  1157. */
  1158. RD_EXPORT
  1159. void rd_kafka_conf_set_dr_cb(rd_kafka_conf_t *conf,
  1160. void (*dr_cb) (rd_kafka_t *rk,
  1161. void *payload, size_t len,
  1162. rd_kafka_resp_err_t err,
  1163. void *opaque, void *msg_opaque));
  1164. /**
  1165. * @brief \b Producer: Set delivery report callback in provided \p conf object.
  1166. *
  1167. * The delivery report callback will be called once for each message
  1168. * accepted by rd_kafka_produce() (et.al) with \p err set to indicate
  1169. * the result of the produce request.
  1170. *
  1171. * The callback is called when a message is succesfully produced or
  1172. * if librdkafka encountered a permanent failure, or the retry counter for
  1173. * temporary errors has been exhausted.
  1174. *
  1175. * An application must call rd_kafka_poll() at regular intervals to
  1176. * serve queued delivery report callbacks.
  1177. */
  1178. RD_EXPORT
  1179. void rd_kafka_conf_set_dr_msg_cb(rd_kafka_conf_t *conf,
  1180. void (*dr_msg_cb) (rd_kafka_t *rk,
  1181. const rd_kafka_message_t *
  1182. rkmessage,
  1183. void *opaque));
  1184. /**
  1185. * @brief \b Consumer: Set consume callback for use with rd_kafka_consumer_poll()
  1186. *
  1187. */
  1188. RD_EXPORT
  1189. void rd_kafka_conf_set_consume_cb (rd_kafka_conf_t *conf,
  1190. void (*consume_cb) (rd_kafka_message_t *
  1191. rkmessage,
  1192. void *opaque));
  1193. /**
  1194. * @brief \b Consumer: Set rebalance callback for use with
  1195. * coordinated consumer group balancing.
  1196. *
  1197. * The \p err field is set to either RD_KAFKA_RESP_ERR__ASSIGN_PARTITIONS
  1198. * or RD_KAFKA_RESP_ERR__REVOKE_PARTITIONS and 'partitions'
  1199. * contains the full partition set that was either assigned or revoked.
  1200. *
  1201. * Registering a \p rebalance_cb turns off librdkafka's automatic
  1202. * partition assignment/revocation and instead delegates that responsibility
  1203. * to the application's \p rebalance_cb.
  1204. *
  1205. * The rebalance callback is responsible for updating librdkafka's
  1206. * assignment set based on the two events: RD_KAFKA_RESP_ERR__ASSIGN_PARTITIONS
  1207. * and RD_KAFKA_RESP_ERR__REVOKE_PARTITIONS but should also be able to handle
  1208. * arbitrary rebalancing failures where \p err is neither of those.
  1209. * @remark In this latter case (arbitrary error), the application must
  1210. * call rd_kafka_assign(rk, NULL) to synchronize state.
  1211. *
  1212. * Without a rebalance callback this is done automatically by librdkafka
  1213. * but registering a rebalance callback gives the application flexibility
  1214. * in performing other operations along with the assinging/revocation,
  1215. * such as fetching offsets from an alternate location (on assign)
  1216. * or manually committing offsets (on revoke).
  1217. *
  1218. * @remark The \p partitions list is destroyed by librdkafka on return
  1219. * return from the rebalance_cb and must not be freed or
  1220. * saved by the application.
  1221. *
  1222. * The following example shows the application's responsibilities:
  1223. * @code
  1224. * static void rebalance_cb (rd_kafka_t *rk, rd_kafka_resp_err_t err,
  1225. * rd_kafka_topic_partition_list_t *partitions,
  1226. * void *opaque) {
  1227. *
  1228. * switch (err)
  1229. * {
  1230. * case RD_KAFKA_RESP_ERR__ASSIGN_PARTITIONS:
  1231. * // application may load offets from arbitrary external
  1232. * // storage here and update \p partitions
  1233. *
  1234. * rd_kafka_assign(rk, partitions);
  1235. * break;
  1236. *
  1237. * case RD_KAFKA_RESP_ERR__REVOKE_PARTITIONS:
  1238. * if (manual_commits) // Optional explicit manual commit
  1239. * rd_kafka_commit(rk, partitions, 0); // sync commit
  1240. *
  1241. * rd_kafka_assign(rk, NULL);
  1242. * break;
  1243. *
  1244. * default:
  1245. * handle_unlikely_error(err);
  1246. * rd_kafka_assign(rk, NULL); // sync state
  1247. * break;
  1248. * }
  1249. * }
  1250. * @endcode
  1251. */
  1252. RD_EXPORT
  1253. void rd_kafka_conf_set_rebalance_cb (
  1254. rd_kafka_conf_t *conf,
  1255. void (*rebalance_cb) (rd_kafka_t *rk,
  1256. rd_kafka_resp_err_t err,
  1257. rd_kafka_topic_partition_list_t *partitions,
  1258. void *opaque));
  1259. /**
  1260. * @brief \b Consumer: Set offset commit callback for use with consumer groups.
  1261. *
  1262. * The results of automatic or manual offset commits will be scheduled
  1263. * for this callback and is served by rd_kafka_consumer_poll().
  1264. *
  1265. * If no partitions had valid offsets to commit this callback will be called
  1266. * with \p err == RD_KAFKA_RESP_ERR__NO_OFFSET which is not to be considered
  1267. * an error.
  1268. *
  1269. * The \p offsets list contains per-partition information:
  1270. * - \c offset: committed offset (attempted)
  1271. * - \c err: commit error
  1272. */
  1273. RD_EXPORT
  1274. void rd_kafka_conf_set_offset_commit_cb (
  1275. rd_kafka_conf_t *conf,
  1276. void (*offset_commit_cb) (rd_kafka_t *rk,
  1277. rd_kafka_resp_err_t err,
  1278. rd_kafka_topic_partition_list_t *offsets,
  1279. void *opaque));
  1280. /**
  1281. * @brief Set error callback in provided conf object.
  1282. *
  1283. * The error callback is used by librdkafka to signal critical errors
  1284. * back to the application.
  1285. *
  1286. * If no \p error_cb is registered then the errors will be logged instead.
  1287. */
  1288. RD_EXPORT
  1289. void rd_kafka_conf_set_error_cb(rd_kafka_conf_t *conf,
  1290. void (*error_cb) (rd_kafka_t *rk, int err,
  1291. const char *reason,
  1292. void *opaque));
  1293. /**
  1294. * @brief Set throttle callback.
  1295. *
  1296. * The throttle callback is used to forward broker throttle times to the
  1297. * application for Produce and Fetch (consume) requests.
  1298. *
  1299. * Callbacks are triggered whenever a non-zero throttle time is returned by
  1300. * the broker, or when the throttle time drops back to zero.
  1301. *
  1302. * An application must call rd_kafka_poll() or rd_kafka_consumer_poll() at
  1303. * regular intervals to serve queued callbacks.
  1304. *
  1305. * @remark Requires broker version 0.9.0 or later.
  1306. */
  1307. RD_EXPORT
  1308. void rd_kafka_conf_set_throttle_cb (rd_kafka_conf_t *conf,
  1309. void (*throttle_cb) (
  1310. rd_kafka_t *rk,
  1311. const char *broker_name,
  1312. int32_t broker_id,
  1313. int throttle_time_ms,
  1314. void *opaque));
  1315. /**
  1316. * @brief Set logger callback.
  1317. *
  1318. * The default is to print to stderr, but a syslog logger is also available,
  1319. * see rd_kafka_log_print and rd_kafka_log_syslog for the builtin alternatives.
  1320. * Alternatively the application may provide its own logger callback.
  1321. * Or pass \p func as NULL to disable logging.
  1322. *
  1323. * This is the configuration alternative to the deprecated rd_kafka_set_logger()
  1324. *
  1325. * @remark The log_cb will be called spontaneously from librdkafka's internal
  1326. * threads unless logs have been forwarded to a poll queue through
  1327. * \c rd_kafka_set_log_queue().
  1328. * An application MUST NOT call any librdkafka APIs or do any prolonged
  1329. * work in a non-forwarded \c log_cb.
  1330. */
  1331. RD_EXPORT
  1332. void rd_kafka_conf_set_log_cb(rd_kafka_conf_t *conf,
  1333. void (*log_cb) (const rd_kafka_t *rk, int level,
  1334. const char *fac, const char *buf));
  1335. /**
  1336. * @brief Set statistics callback in provided conf object.
  1337. *
  1338. * The statistics callback is triggered from rd_kafka_poll() every
  1339. * \c statistics.interval.ms (needs to be configured separately).
  1340. * Function arguments:
  1341. * - \p rk - Kafka handle
  1342. * - \p json - String containing the statistics data in JSON format
  1343. * - \p json_len - Length of \p json string.
  1344. * - \p opaque - Application-provided opaque.
  1345. *
  1346. * If the application wishes to hold on to the \p json pointer and free
  1347. * it at a later time it must return 1 from the \p stats_cb.
  1348. * If the application returns 0 from the \p stats_cb then librdkafka
  1349. * will immediately free the \p json pointer.
  1350. */
  1351. RD_EXPORT
  1352. void rd_kafka_conf_set_stats_cb(rd_kafka_conf_t *conf,
  1353. int (*stats_cb) (rd_kafka_t *rk,
  1354. char *json,
  1355. size_t json_len,
  1356. void *opaque));
  1357. /**
  1358. * @brief Set socket callback.
  1359. *
  1360. * The socket callback is responsible for opening a socket
  1361. * according to the supplied \p domain, \p type and \p protocol.
  1362. * The socket shall be created with \c CLOEXEC set in a racefree fashion, if
  1363. * possible.
  1364. *
  1365. * Default:
  1366. * - on linux: racefree CLOEXEC
  1367. * - others : non-racefree CLOEXEC
  1368. *
  1369. * @remark The callback will be called from an internal librdkafka thread.
  1370. */
  1371. RD_EXPORT
  1372. void rd_kafka_conf_set_socket_cb(rd_kafka_conf_t *conf,
  1373. int (*socket_cb) (int domain, int type,
  1374. int protocol,
  1375. void *opaque));
  1376. /**
  1377. * @brief Set connect callback.
  1378. *
  1379. * The connect callback is responsible for connecting socket \p sockfd
  1380. * to peer address \p addr.
  1381. * The \p id field contains the broker identifier.
  1382. *
  1383. * \p connect_cb shall return 0 on success (socket connected) or an error
  1384. * number (errno) on error.
  1385. *
  1386. * @remark The callback will be called from an internal librdkafka thread.
  1387. */
  1388. RD_EXPORT void
  1389. rd_kafka_conf_set_connect_cb (rd_kafka_conf_t *conf,
  1390. int (*connect_cb) (int sockfd,
  1391. const struct sockaddr *addr,
  1392. int addrlen,
  1393. const char *id,
  1394. void *opaque));
  1395. /**
  1396. * @brief Set close socket callback.
  1397. *
  1398. * Close a socket (optionally opened with socket_cb()).
  1399. *
  1400. * @remark The callback will be called from an internal librdkafka thread.
  1401. */
  1402. RD_EXPORT void
  1403. rd_kafka_conf_set_closesocket_cb (rd_kafka_conf_t *conf,
  1404. int (*closesocket_cb) (int sockfd,
  1405. void *opaque));
  1406. #ifndef _MSC_VER
  1407. /**
  1408. * @brief Set open callback.
  1409. *
  1410. * The open callback is responsible for opening the file specified by
  1411. * pathname, flags and mode.
  1412. * The file shall be opened with \c CLOEXEC set in a racefree fashion, if
  1413. * possible.
  1414. *
  1415. * Default:
  1416. * - on linux: racefree CLOEXEC
  1417. * - others : non-racefree CLOEXEC
  1418. *
  1419. * @remark The callback will be called from an internal librdkafka thread.
  1420. */
  1421. RD_EXPORT
  1422. void rd_kafka_conf_set_open_cb (rd_kafka_conf_t *conf,
  1423. int (*open_cb) (const char *pathname,
  1424. int flags, mode_t mode,
  1425. void *opaque));
  1426. #endif
  1427. /**
  1428. * @brief Sets the application's opaque pointer that will be passed to callbacks
  1429. */
  1430. RD_EXPORT
  1431. void rd_kafka_conf_set_opaque(rd_kafka_conf_t *conf, void *opaque);
  1432. /**
  1433. * @brief Retrieves the opaque pointer previously set with rd_kafka_conf_set_opaque()
  1434. */
  1435. RD_EXPORT
  1436. void *rd_kafka_opaque(const rd_kafka_t *rk);
  1437. /**
  1438. * Sets the default topic configuration to use for automatically
  1439. * subscribed topics (e.g., through pattern-matched topics).
  1440. * The topic config object is not usable after this call.
  1441. */
  1442. RD_EXPORT
  1443. void rd_kafka_conf_set_default_topic_conf (rd_kafka_conf_t *conf,
  1444. rd_kafka_topic_conf_t *tconf);
  1445. /**
  1446. * @brief Retrieve configuration value for property \p name.
  1447. *
  1448. * If \p dest is non-NULL the value will be written to \p dest with at
  1449. * most \p dest_size.
  1450. *
  1451. * \p *dest_size is updated to the full length of the value, thus if
  1452. * \p *dest_size initially is smaller than the full length the application
  1453. * may reallocate \p dest to fit the returned \p *dest_size and try again.
  1454. *
  1455. * If \p dest is NULL only the full length of the value is returned.
  1456. *
  1457. * Fallthrough:
  1458. * Topic-level configuration properties from the \c default_topic_conf
  1459. * may be retrieved using this interface.
  1460. *
  1461. * @returns \p RD_KAFKA_CONF_OK if the property name matched, else
  1462. * \p RD_KAFKA_CONF_UNKNOWN.
  1463. */
  1464. RD_EXPORT
  1465. rd_kafka_conf_res_t rd_kafka_conf_get (const rd_kafka_conf_t *conf,
  1466. const char *name,
  1467. char *dest, size_t *dest_size);
  1468. /**
  1469. * @brief Retrieve topic configuration value for property \p name.
  1470. *
  1471. * @sa rd_kafka_conf_get()
  1472. */
  1473. RD_EXPORT
  1474. rd_kafka_conf_res_t rd_kafka_topic_conf_get (const rd_kafka_topic_conf_t *conf,
  1475. const char *name,
  1476. char *dest, size_t *dest_size);
  1477. /**
  1478. * @brief Dump the configuration properties and values of \p conf to an array
  1479. * with \"key\", \"value\" pairs.
  1480. *
  1481. * The number of entries in the array is returned in \p *cntp.
  1482. *
  1483. * The dump must be freed with `rd_kafka_conf_dump_free()`.
  1484. */
  1485. RD_EXPORT
  1486. const char **rd_kafka_conf_dump(rd_kafka_conf_t *conf, size_t *cntp);
  1487. /**
  1488. * @brief Dump the topic configuration properties and values of \p conf
  1489. * to an array with \"key\", \"value\" pairs.
  1490. *
  1491. * The number of entries in the array is returned in \p *cntp.
  1492. *
  1493. * The dump must be freed with `rd_kafka_conf_dump_free()`.
  1494. */
  1495. RD_EXPORT
  1496. const char **rd_kafka_topic_conf_dump(rd_kafka_topic_conf_t *conf,
  1497. size_t *cntp);
  1498. /**
  1499. * @brief Frees a configuration dump returned from `rd_kafka_conf_dump()` or
  1500. * `rd_kafka_topic_conf_dump().
  1501. */
  1502. RD_EXPORT
  1503. void rd_kafka_conf_dump_free(const char **arr, size_t cnt);
  1504. /**
  1505. * @brief Prints a table to \p fp of all supported configuration properties,
  1506. * their default values as well as a description.
  1507. */
  1508. RD_EXPORT
  1509. void rd_kafka_conf_properties_show(FILE *fp);
  1510. /**@}*/
  1511. /**
  1512. * @name Topic configuration
  1513. * @{
  1514. *
  1515. * @brief Topic configuration property interface
  1516. *
  1517. */
  1518. /**
  1519. * @brief Create topic configuration object
  1520. *
  1521. * @sa Same semantics as for rd_kafka_conf_new().
  1522. */
  1523. RD_EXPORT
  1524. rd_kafka_topic_conf_t *rd_kafka_topic_conf_new(void);
  1525. /**
  1526. * @brief Creates a copy/duplicate of topic configuration object \p conf.
  1527. */
  1528. RD_EXPORT
  1529. rd_kafka_topic_conf_t *rd_kafka_topic_conf_dup(const rd_kafka_topic_conf_t
  1530. *conf);
  1531. /**
  1532. * @brief Creates a copy/duplicate of \p rk 's default topic configuration
  1533. * object.
  1534. */
  1535. RD_EXPORT
  1536. rd_kafka_topic_conf_t *rd_kafka_default_topic_conf_dup (rd_kafka_t *rk);
  1537. /**
  1538. * @brief Destroys a topic conf object.
  1539. */
  1540. RD_EXPORT
  1541. void rd_kafka_topic_conf_destroy(rd_kafka_topic_conf_t *topic_conf);
  1542. /**
  1543. * @brief Sets a single rd_kafka_topic_conf_t value by property name.
  1544. *
  1545. * \p topic_conf should have been previously set up
  1546. * with `rd_kafka_topic_conf_new()`.
  1547. *
  1548. * @returns rd_kafka_conf_res_t to indicate success or failure.
  1549. */
  1550. RD_EXPORT
  1551. rd_kafka_conf_res_t rd_kafka_topic_conf_set(rd_kafka_topic_conf_t *conf,
  1552. const char *name,
  1553. const char *value,
  1554. char *errstr, size_t errstr_size);
  1555. /**
  1556. * @brief Sets the application's opaque pointer that will be passed to all topic
  1557. * callbacks as the \c rkt_opaque argument.
  1558. */
  1559. RD_EXPORT
  1560. void rd_kafka_topic_conf_set_opaque(rd_kafka_topic_conf_t *conf, void *opaque);
  1561. /**
  1562. * @brief \b Producer: Set partitioner callback in provided topic conf object.
  1563. *
  1564. * The partitioner may be called in any thread at any time,
  1565. * it may be called multiple times for the same message/key.
  1566. *
  1567. * Partitioner function constraints:
  1568. * - MUST NOT call any rd_kafka_*() functions except:
  1569. * rd_kafka_topic_partition_available()
  1570. * - MUST NOT block or execute for prolonged periods of time.
  1571. * - MUST return a value between 0 and partition_cnt-1, or the
  1572. * special \c RD_KAFKA_PARTITION_UA value if partitioning
  1573. * could not be performed.
  1574. */
  1575. RD_EXPORT
  1576. void
  1577. rd_kafka_topic_conf_set_partitioner_cb (rd_kafka_topic_conf_t *topic_conf,
  1578. int32_t (*partitioner) (
  1579. const rd_kafka_topic_t *rkt,
  1580. const void *keydata,
  1581. size_t keylen,
  1582. int32_t partition_cnt,
  1583. void *rkt_opaque,
  1584. void *msg_opaque));
  1585. /**
  1586. * @brief \b Producer: Set message queueing order comparator callback.
  1587. *
  1588. * The callback may be called in any thread at any time,
  1589. * it may be called multiple times for the same message.
  1590. *
  1591. * Ordering comparator function constraints:
  1592. * - MUST be stable sort (same input gives same output).
  1593. * - MUST NOT call any rd_kafka_*() functions.
  1594. * - MUST NOT block or execute for prolonged periods of time.
  1595. *
  1596. * The comparator shall compare the two messages and return:
  1597. * - < 0 if message \p a should be inserted before message \p b.
  1598. * - >=0 if message \p a should be inserted after message \p b.
  1599. *
  1600. * @remark Insert sorting will be used to enqueue the message in the
  1601. * correct queue position, this comes at a cost of O(n).
  1602. *
  1603. * @remark If `queuing.strategy=fifo` new messages are enqueued to the
  1604. * tail of the queue regardless of msg_order_cmp, but retried messages
  1605. * are still affected by msg_order_cmp.
  1606. *
  1607. * @warning THIS IS AN EXPERIMENTAL API, SUBJECT TO CHANGE OR REMOVAL,
  1608. * DO NOT USE IN PRODUCTION.
  1609. */
  1610. RD_EXPORT void
  1611. rd_kafka_topic_conf_set_msg_order_cmp (rd_kafka_topic_conf_t *topic_conf,
  1612. int (*msg_order_cmp) (
  1613. const rd_kafka_message_t *a,
  1614. const rd_kafka_message_t *b));
  1615. /**
  1616. * @brief Check if partition is available (has a leader broker).
  1617. *
  1618. * @returns 1 if the partition is available, else 0.
  1619. *
  1620. * @warning This function must only be called from inside a partitioner function
  1621. */
  1622. RD_EXPORT
  1623. int rd_kafka_topic_partition_available(const rd_kafka_topic_t *rkt,
  1624. int32_t partition);
  1625. /*******************************************************************
  1626. * *
  1627. * Partitioners provided by rdkafka *
  1628. * *
  1629. *******************************************************************/
  1630. /**
  1631. * @brief Random partitioner.
  1632. *
  1633. * Will try not to return unavailable partitions.
  1634. *
  1635. * @returns a random partition between 0 and \p partition_cnt - 1.
  1636. *
  1637. */
  1638. RD_EXPORT
  1639. int32_t rd_kafka_msg_partitioner_random(const rd_kafka_topic_t *rkt,
  1640. const void *key, size_t keylen,
  1641. int32_t partition_cnt,
  1642. void *opaque, void *msg_opaque);
  1643. /**
  1644. * @brief Consistent partitioner.
  1645. *
  1646. * Uses consistent hashing to map identical keys onto identical partitions.
  1647. *
  1648. * @returns a \"random\" partition between 0 and \p partition_cnt - 1 based on
  1649. * the CRC value of the key
  1650. */
  1651. RD_EXPORT
  1652. int32_t rd_kafka_msg_partitioner_consistent (const rd_kafka_topic_t *rkt,
  1653. const void *key, size_t keylen,
  1654. int32_t partition_cnt,
  1655. void *opaque, void *msg_opaque);
  1656. /**
  1657. * @brief Consistent-Random partitioner.
  1658. *
  1659. * This is the default partitioner.
  1660. * Uses consistent hashing to map identical keys onto identical partitions, and
  1661. * messages without keys will be assigned via the random partitioner.
  1662. *
  1663. * @returns a \"random\" partition between 0 and \p partition_cnt - 1 based on
  1664. * the CRC value of the key (if provided)
  1665. */
  1666. RD_EXPORT
  1667. int32_t rd_kafka_msg_partitioner_consistent_random (const rd_kafka_topic_t *rkt,
  1668. const void *key, size_t keylen,
  1669. int32_t partition_cnt,
  1670. void *opaque, void *msg_opaque);
  1671. /**
  1672. * @brief Murmur2 partitioner (Java compatible).
  1673. *
  1674. * Uses consistent hashing to map identical keys onto identical partitions
  1675. * using Java-compatible Murmur2 hashing.
  1676. *
  1677. * @returns a partition between 0 and \p partition_cnt - 1.
  1678. */
  1679. RD_EXPORT
  1680. int32_t rd_kafka_msg_partitioner_murmur2 (const rd_kafka_topic_t *rkt,
  1681. const void *key, size_t keylen,
  1682. int32_t partition_cnt,
  1683. void *rkt_opaque,
  1684. void *msg_opaque);
  1685. /**
  1686. * @brief Consistent-Random Murmur2 partitioner (Java compatible).
  1687. *
  1688. * Uses consistent hashing to map identical keys onto identical partitions
  1689. * using Java-compatible Murmur2 hashing.
  1690. * Messages without keys will be assigned via the random partitioner.
  1691. *
  1692. * @returns a partition between 0 and \p partition_cnt - 1.
  1693. */
  1694. RD_EXPORT
  1695. int32_t rd_kafka_msg_partitioner_murmur2_random (const rd_kafka_topic_t *rkt,
  1696. const void *key, size_t keylen,
  1697. int32_t partition_cnt,
  1698. void *rkt_opaque,
  1699. void *msg_opaque);
  1700. /**@}*/
  1701. /**
  1702. * @name Main Kafka and Topic object handles
  1703. * @{
  1704. *
  1705. *
  1706. */
  1707. /**
  1708. * @brief Creates a new Kafka handle and starts its operation according to the
  1709. * specified \p type (\p RD_KAFKA_CONSUMER or \p RD_KAFKA_PRODUCER).
  1710. *
  1711. * \p conf is an optional struct created with `rd_kafka_conf_new()` that will
  1712. * be used instead of the default configuration.
  1713. * The \p conf object is freed by this function on success and must not be used
  1714. * or destroyed by the application sub-sequently.
  1715. * See `rd_kafka_conf_set()` et.al for more information.
  1716. *
  1717. * \p errstr must be a pointer to memory of at least size \p errstr_size where
  1718. * `rd_kafka_new()` may write a human readable error message in case the
  1719. * creation of a new handle fails. In which case the function returns NULL.
  1720. *
  1721. * @remark \b RD_KAFKA_CONSUMER: When a new \p RD_KAFKA_CONSUMER
  1722. * rd_kafka_t handle is created it may either operate in the
  1723. * legacy simple consumer mode using the rd_kafka_consume_start()
  1724. * interface, or the High-level KafkaConsumer API.
  1725. * @remark An application must only use one of these groups of APIs on a given
  1726. * rd_kafka_t RD_KAFKA_CONSUMER handle.
  1727. *
  1728. * @returns The Kafka handle on success or NULL on error (see \p errstr)
  1729. *
  1730. * @sa To destroy the Kafka handle, use rd_kafka_destroy().
  1731. */
  1732. RD_EXPORT
  1733. rd_kafka_t *rd_kafka_new(rd_kafka_type_t type, rd_kafka_conf_t *conf,
  1734. char *errstr, size_t errstr_size);
  1735. /**
  1736. * @brief Destroy Kafka handle.
  1737. *
  1738. * @remark This is a blocking operation.
  1739. */
  1740. RD_EXPORT
  1741. void rd_kafka_destroy(rd_kafka_t *rk);
  1742. /**
  1743. * @brief Returns Kafka handle name.
  1744. */
  1745. RD_EXPORT
  1746. const char *rd_kafka_name(const rd_kafka_t *rk);
  1747. /**
  1748. * @brief Returns Kafka handle type.
  1749. */
  1750. RD_EXPORT
  1751. rd_kafka_type_t rd_kafka_type(const rd_kafka_t *rk);
  1752. /**
  1753. * @brief Returns this client's broker-assigned group member id
  1754. *
  1755. * @remark This currently requires the high-level KafkaConsumer
  1756. *
  1757. * @returns An allocated string containing the current broker-assigned group
  1758. * member id, or NULL if not available.
  1759. * The application must free the string with \p free() or
  1760. * rd_kafka_mem_free()
  1761. */
  1762. RD_EXPORT
  1763. char *rd_kafka_memberid (const rd_kafka_t *rk);
  1764. /**
  1765. * @brief Returns the ClusterId as reported in broker metadata.
  1766. *
  1767. * @param timeout_ms If there is no cached value from metadata retrieval
  1768. * then this specifies the maximum amount of time
  1769. * (in milliseconds) the call will block waiting
  1770. * for metadata to be retrieved.
  1771. * Use 0 for non-blocking calls.
  1772. * @remark Requires broker version >=0.10.0 and api.version.request=true.
  1773. *
  1774. * @remark The application must free the returned pointer
  1775. * using rd_kafka_mem_free().
  1776. *
  1777. * @returns a newly allocated string containing the ClusterId, or NULL
  1778. * if no ClusterId could be retrieved in the allotted timespan.
  1779. */
  1780. RD_EXPORT
  1781. char *rd_kafka_clusterid (rd_kafka_t *rk, int timeout_ms);
  1782. /**
  1783. * @brief Creates a new topic handle for topic named \p topic.
  1784. *
  1785. * \p conf is an optional configuration for the topic created with
  1786. * `rd_kafka_topic_conf_new()` that will be used instead of the default
  1787. * topic configuration.
  1788. * The \p conf object is freed by this function and must not be used or
  1789. * destroyed by the application sub-sequently.
  1790. * See `rd_kafka_topic_conf_set()` et.al for more information.
  1791. *
  1792. * Topic handles are refcounted internally and calling rd_kafka_topic_new()
  1793. * again with the same topic name will return the previous topic handle
  1794. * without updating the original handle's configuration.
  1795. * Applications must eventually call rd_kafka_topic_destroy() for each
  1796. * succesfull call to rd_kafka_topic_new() to clear up resources.
  1797. *
  1798. * @returns the new topic handle or NULL on error (use rd_kafka_errno2err()
  1799. * to convert system \p errno to an rd_kafka_resp_err_t error code.
  1800. *
  1801. * @sa rd_kafka_topic_destroy()
  1802. */
  1803. RD_EXPORT
  1804. rd_kafka_topic_t *rd_kafka_topic_new(rd_kafka_t *rk, const char *topic,
  1805. rd_kafka_topic_conf_t *conf);
  1806. /**
  1807. * @brief Loose application's topic handle refcount as previously created
  1808. * with `rd_kafka_topic_new()`.
  1809. *
  1810. * @remark Since topic objects are refcounted (both internally and for the app)
  1811. * the topic object might not actually be destroyed by this call,
  1812. * but the application must consider the object destroyed.
  1813. */
  1814. RD_EXPORT
  1815. void rd_kafka_topic_destroy(rd_kafka_topic_t *rkt);
  1816. /**
  1817. * @brief Returns the topic name.
  1818. */
  1819. RD_EXPORT
  1820. const char *rd_kafka_topic_name(const rd_kafka_topic_t *rkt);
  1821. /**
  1822. * @brief Get the \p rkt_opaque pointer that was set in the topic configuration.
  1823. */
  1824. RD_EXPORT
  1825. void *rd_kafka_topic_opaque (const rd_kafka_topic_t *rkt);
  1826. /**
  1827. * @brief Unassigned partition.
  1828. *
  1829. * The unassigned partition is used by the producer API for messages
  1830. * that should be partitioned using the configured or default partitioner.
  1831. */
  1832. #define RD_KAFKA_PARTITION_UA ((int32_t)-1)
  1833. /**
  1834. * @brief Polls the provided kafka handle for events.
  1835. *
  1836. * Events will cause application provided callbacks to be called.
  1837. *
  1838. * The \p timeout_ms argument specifies the maximum amount of time
  1839. * (in milliseconds) that the call will block waiting for events.
  1840. * For non-blocking calls, provide 0 as \p timeout_ms.
  1841. * To wait indefinately for an event, provide -1.
  1842. *
  1843. * @remark An application should make sure to call poll() at regular
  1844. * intervals to serve any queued callbacks waiting to be called.
  1845. *
  1846. * Events:
  1847. * - delivery report callbacks (if dr_cb/dr_msg_cb is configured) [producer]
  1848. * - error callbacks (rd_kafka_conf_set_error_cb()) [all]
  1849. * - stats callbacks (rd_kafka_conf_set_stats_cb()) [all]
  1850. * - throttle callbacks (rd_kafka_conf_set_throttle_cb()) [all]
  1851. *
  1852. * @returns the number of events served.
  1853. */
  1854. RD_EXPORT
  1855. int rd_kafka_poll(rd_kafka_t *rk, int timeout_ms);
  1856. /**
  1857. * @brief Cancels the current callback dispatcher (rd_kafka_poll(),
  1858. * rd_kafka_consume_callback(), etc).
  1859. *
  1860. * A callback may use this to force an immediate return to the calling
  1861. * code (caller of e.g. rd_kafka_poll()) without processing any further
  1862. * events.
  1863. *
  1864. * @remark This function MUST ONLY be called from within a librdkafka callback.
  1865. */
  1866. RD_EXPORT
  1867. void rd_kafka_yield (rd_kafka_t *rk);
  1868. /**
  1869. * @brief Pause producing or consumption for the provided list of partitions.
  1870. *
  1871. * Success or error is returned per-partition \p err in the \p partitions list.
  1872. *
  1873. * @returns RD_KAFKA_RESP_ERR_NO_ERROR
  1874. */
  1875. RD_EXPORT rd_kafka_resp_err_t
  1876. rd_kafka_pause_partitions (rd_kafka_t *rk,
  1877. rd_kafka_topic_partition_list_t *partitions);
  1878. /**
  1879. * @brief Resume producing consumption for the provided list of partitions.
  1880. *
  1881. * Success or error is returned per-partition \p err in the \p partitions list.
  1882. *
  1883. * @returns RD_KAFKA_RESP_ERR_NO_ERROR
  1884. */
  1885. RD_EXPORT rd_kafka_resp_err_t
  1886. rd_kafka_resume_partitions (rd_kafka_t *rk,
  1887. rd_kafka_topic_partition_list_t *partitions);
  1888. /**
  1889. * @brief Query broker for low (oldest/beginning) and high (newest/end) offsets
  1890. * for partition.
  1891. *
  1892. * Offsets are returned in \p *low and \p *high respectively.
  1893. *
  1894. * @returns RD_KAFKA_RESP_ERR_NO_ERROR on success or an error code on failure.
  1895. */
  1896. RD_EXPORT rd_kafka_resp_err_t
  1897. rd_kafka_query_watermark_offsets (rd_kafka_t *rk,
  1898. const char *topic, int32_t partition,
  1899. int64_t *low, int64_t *high, int timeout_ms);
  1900. /**
  1901. * @brief Get last known low (oldest/beginning) and high (newest/end) offsets
  1902. * for partition.
  1903. *
  1904. * The low offset is updated periodically (if statistics.interval.ms is set)
  1905. * while the high offset is updated on each fetched message set from the broker.
  1906. *
  1907. * If there is no cached offset (either low or high, or both) then
  1908. * RD_KAFKA_OFFSET_INVALID will be returned for the respective offset.
  1909. *
  1910. * Offsets are returned in \p *low and \p *high respectively.
  1911. *
  1912. * @returns RD_KAFKA_RESP_ERR_NO_ERROR on success or an error code on failure.
  1913. *
  1914. * @remark Shall only be used with an active consumer instance.
  1915. */
  1916. RD_EXPORT rd_kafka_resp_err_t
  1917. rd_kafka_get_watermark_offsets (rd_kafka_t *rk,
  1918. const char *topic, int32_t partition,
  1919. int64_t *low, int64_t *high);
  1920. /**
  1921. * @brief Look up the offsets for the given partitions by timestamp.
  1922. *
  1923. * The returned offset for each partition is the earliest offset whose
  1924. * timestamp is greater than or equal to the given timestamp in the
  1925. * corresponding partition.
  1926. *
  1927. * The timestamps to query are represented as \c offset in \p offsets
  1928. * on input, and \c offset will contain the offset on output.
  1929. *
  1930. * The function will block for at most \p timeout_ms milliseconds.
  1931. *
  1932. * @remark Duplicate Topic+Partitions are not supported.
  1933. * @remark Per-partition errors may be returned in \c rd_kafka_topic_partition_t.err
  1934. *
  1935. * @returns RD_KAFKA_RESP_ERR_NO_ERROR if offsets were be queried (do note
  1936. * that per-partition errors might be set),
  1937. * RD_KAFKA_RESP_ERR__TIMED_OUT if not all offsets could be fetched
  1938. * within \p timeout_ms,
  1939. * RD_KAFKA_RESP_ERR__INVALID_ARG if the \p offsets list is empty,
  1940. * RD_KAFKA_RESP_ERR__UNKNOWN_PARTITION if all partitions are unknown,
  1941. * RD_KAFKA_RESP_ERR_LEADER_NOT_AVAILABLE if unable to query leaders
  1942. * for the given partitions.
  1943. */
  1944. RD_EXPORT rd_kafka_resp_err_t
  1945. rd_kafka_offsets_for_times (rd_kafka_t *rk,
  1946. rd_kafka_topic_partition_list_t *offsets,
  1947. int timeout_ms);
  1948. /**
  1949. * @brief Free pointer returned by librdkafka
  1950. *
  1951. * This is typically an abstraction for the free(3) call and makes sure
  1952. * the application can use the same memory allocator as librdkafka for
  1953. * freeing pointers returned by librdkafka.
  1954. *
  1955. * In standard setups it is usually not necessary to use this interface
  1956. * rather than the free(3) functione.
  1957. *
  1958. * @remark rd_kafka_mem_free() must only be used for pointers returned by APIs
  1959. * that explicitly mention using this function for freeing.
  1960. */
  1961. RD_EXPORT
  1962. void rd_kafka_mem_free (rd_kafka_t *rk, void *ptr);
  1963. /**@}*/
  1964. /**
  1965. * @name Queue API
  1966. * @{
  1967. *
  1968. * Message queues allows the application to re-route consumed messages
  1969. * from multiple topic+partitions into one single queue point.
  1970. * This queue point containing messages from a number of topic+partitions
  1971. * may then be served by a single rd_kafka_consume*_queue() call,
  1972. * rather than one call per topic+partition combination.
  1973. */
  1974. /**
  1975. * @brief Create a new message queue.
  1976. *
  1977. * See rd_kafka_consume_start_queue(), rd_kafka_consume_queue(), et.al.
  1978. */
  1979. RD_EXPORT
  1980. rd_kafka_queue_t *rd_kafka_queue_new(rd_kafka_t *rk);
  1981. /**
  1982. * Destroy a queue, purging all of its enqueued messages.
  1983. */
  1984. RD_EXPORT
  1985. void rd_kafka_queue_destroy(rd_kafka_queue_t *rkqu);
  1986. /**
  1987. * @returns a reference to the main librdkafka event queue.
  1988. * This is the queue served by rd_kafka_poll().
  1989. *
  1990. * Use rd_kafka_queue_destroy() to loose the reference.
  1991. */
  1992. RD_EXPORT
  1993. rd_kafka_queue_t *rd_kafka_queue_get_main (rd_kafka_t *rk);
  1994. /**
  1995. * @returns a reference to the librdkafka consumer queue.
  1996. * This is the queue served by rd_kafka_consumer_poll().
  1997. *
  1998. * Use rd_kafka_queue_destroy() to loose the reference.
  1999. *
  2000. * @remark rd_kafka_queue_destroy() MUST be called on this queue
  2001. * prior to calling rd_kafka_consumer_close().
  2002. */
  2003. RD_EXPORT
  2004. rd_kafka_queue_t *rd_kafka_queue_get_consumer (rd_kafka_t *rk);
  2005. /**
  2006. * @returns a reference to the partition's queue, or NULL if
  2007. * partition is invalid.
  2008. *
  2009. * Use rd_kafka_queue_destroy() to loose the reference.
  2010. *
  2011. * @remark rd_kafka_queue_destroy() MUST be called on this queue
  2012. *
  2013. * @remark This function only works on consumers.
  2014. */
  2015. RD_EXPORT
  2016. rd_kafka_queue_t *rd_kafka_queue_get_partition (rd_kafka_t *rk,
  2017. const char *topic,
  2018. int32_t partition);
  2019. /**
  2020. * @brief Forward/re-route queue \p src to \p dst.
  2021. * If \p dst is \c NULL the forwarding is removed.
  2022. *
  2023. * The internal refcounts for both queues are increased.
  2024. *
  2025. * @remark Regardless of whether \p dst is NULL or not, after calling this
  2026. * function, \p src will not forward it's fetch queue to the consumer
  2027. * queue.
  2028. */
  2029. RD_EXPORT
  2030. void rd_kafka_queue_forward (rd_kafka_queue_t *src, rd_kafka_queue_t *dst);
  2031. /**
  2032. * @brief Forward librdkafka logs (and debug) to the specified queue
  2033. * for serving with one of the ..poll() calls.
  2034. *
  2035. * This allows an application to serve log callbacks (\c log_cb)
  2036. * in its thread of choice.
  2037. *
  2038. * @param rkqu Queue to forward logs to. If the value is NULL the logs
  2039. * are forwarded to the main queue.
  2040. *
  2041. * @remark The configuration property \c log.queue MUST also be set to true.
  2042. *
  2043. * @remark librdkafka maintains its own reference to the provided queue.
  2044. *
  2045. * @returns RD_KAFKA_RESP_ERR_NO_ERROR on success or an error code on error.
  2046. */
  2047. RD_EXPORT
  2048. rd_kafka_resp_err_t rd_kafka_set_log_queue (rd_kafka_t *rk,
  2049. rd_kafka_queue_t *rkqu);
  2050. /**
  2051. * @returns the current number of elements in queue.
  2052. */
  2053. RD_EXPORT
  2054. size_t rd_kafka_queue_length (rd_kafka_queue_t *rkqu);
  2055. /**
  2056. * @brief Enable IO event triggering for queue.
  2057. *
  2058. * To ease integration with IO based polling loops this API
  2059. * allows an application to create a separate file-descriptor
  2060. * that librdkafka will write \p payload (of size \p size) to
  2061. * whenever a new element is enqueued on a previously empty queue.
  2062. *
  2063. * To remove event triggering call with \p fd = -1.
  2064. *
  2065. * librdkafka will maintain a copy of the \p payload.
  2066. *
  2067. * @remark When using forwarded queues the IO event must only be enabled
  2068. * on the final forwarded-to (destination) queue.
  2069. */
  2070. RD_EXPORT
  2071. void rd_kafka_queue_io_event_enable (rd_kafka_queue_t *rkqu, int fd,
  2072. const void *payload, size_t size);
  2073. /**@}*/
  2074. /**
  2075. *
  2076. * @name Simple Consumer API (legacy)
  2077. * @{
  2078. *
  2079. */
  2080. #define RD_KAFKA_OFFSET_BEGINNING -2 /**< Start consuming from beginning of
  2081. * kafka partition queue: oldest msg */
  2082. #define RD_KAFKA_OFFSET_END -1 /**< Start consuming from end of kafka
  2083. * partition queue: next msg */
  2084. #define RD_KAFKA_OFFSET_STORED -1000 /**< Start consuming from offset retrieved
  2085. * from offset store */
  2086. #define RD_KAFKA_OFFSET_INVALID -1001 /**< Invalid offset */
  2087. /** @cond NO_DOC */
  2088. #define RD_KAFKA_OFFSET_TAIL_BASE -2000 /* internal: do not use */
  2089. /** @endcond */
  2090. /**
  2091. * @brief Start consuming \p CNT messages from topic's current end offset.
  2092. *
  2093. * That is, if current end offset is 12345 and \p CNT is 200, it will start
  2094. * consuming from offset \c 12345-200 = \c 12145. */
  2095. #define RD_KAFKA_OFFSET_TAIL(CNT) (RD_KAFKA_OFFSET_TAIL_BASE - (CNT))
  2096. /**
  2097. * @brief Start consuming messages for topic \p rkt and \p partition
  2098. * at offset \p offset which may either be an absolute \c (0..N)
  2099. * or one of the logical offsets:
  2100. * - RD_KAFKA_OFFSET_BEGINNING
  2101. * - RD_KAFKA_OFFSET_END
  2102. * - RD_KAFKA_OFFSET_STORED
  2103. * - RD_KAFKA_OFFSET_TAIL
  2104. *
  2105. * rdkafka will attempt to keep \c queued.min.messages (config property)
  2106. * messages in the local queue by repeatedly fetching batches of messages
  2107. * from the broker until the threshold is reached.
  2108. *
  2109. * The application shall use one of the `rd_kafka_consume*()` functions
  2110. * to consume messages from the local queue, each kafka message being
  2111. * represented as a `rd_kafka_message_t *` object.
  2112. *
  2113. * `rd_kafka_consume_start()` must not be called multiple times for the same
  2114. * topic and partition without stopping consumption first with
  2115. * `rd_kafka_consume_stop()`.
  2116. *
  2117. * @returns 0 on success or -1 on error in which case errno is set accordingly:
  2118. * - EBUSY - Conflicts with an existing or previous subscription
  2119. * (RD_KAFKA_RESP_ERR__CONFLICT)
  2120. * - EINVAL - Invalid offset, or incomplete configuration (lacking group.id)
  2121. * (RD_KAFKA_RESP_ERR__INVALID_ARG)
  2122. * - ESRCH - requested \p partition is invalid.
  2123. * (RD_KAFKA_RESP_ERR__UNKNOWN_PARTITION)
  2124. * - ENOENT - topic is unknown in the Kafka cluster.
  2125. * (RD_KAFKA_RESP_ERR__UNKNOWN_TOPIC)
  2126. *
  2127. * Use `rd_kafka_errno2err()` to convert sytem \c errno to `rd_kafka_resp_err_t`
  2128. */
  2129. RD_EXPORT
  2130. int rd_kafka_consume_start(rd_kafka_topic_t *rkt, int32_t partition,
  2131. int64_t offset);
  2132. /**
  2133. * @brief Same as rd_kafka_consume_start() but re-routes incoming messages to
  2134. * the provided queue \p rkqu (which must have been previously allocated
  2135. * with `rd_kafka_queue_new()`.
  2136. *
  2137. * The application must use one of the `rd_kafka_consume_*_queue()` functions
  2138. * to receive fetched messages.
  2139. *
  2140. * `rd_kafka_consume_start_queue()` must not be called multiple times for the
  2141. * same topic and partition without stopping consumption first with
  2142. * `rd_kafka_consume_stop()`.
  2143. * `rd_kafka_consume_start()` and `rd_kafka_consume_start_queue()` must not
  2144. * be combined for the same topic and partition.
  2145. */
  2146. RD_EXPORT
  2147. int rd_kafka_consume_start_queue(rd_kafka_topic_t *rkt, int32_t partition,
  2148. int64_t offset, rd_kafka_queue_t *rkqu);
  2149. /**
  2150. * @brief Stop consuming messages for topic \p rkt and \p partition, purging
  2151. * all messages currently in the local queue.
  2152. *
  2153. * NOTE: To enforce synchronisation this call will block until the internal
  2154. * fetcher has terminated and offsets are committed to configured
  2155. * storage method.
  2156. *
  2157. * The application needs to be stop all consumers before calling
  2158. * `rd_kafka_destroy()` on the main object handle.
  2159. *
  2160. * @returns 0 on success or -1 on error (see `errno`).
  2161. */
  2162. RD_EXPORT
  2163. int rd_kafka_consume_stop(rd_kafka_topic_t *rkt, int32_t partition);
  2164. /**
  2165. * @brief Seek consumer for topic+partition to \p offset which is either an
  2166. * absolute or logical offset.
  2167. *
  2168. * If \p timeout_ms is not 0 the call will wait this long for the
  2169. * seek to be performed. If the timeout is reached the internal state
  2170. * will be unknown and this function returns `RD_KAFKA_RESP_ERR__TIMED_OUT`.
  2171. * If \p timeout_ms is 0 it will initiate the seek but return
  2172. * immediately without any error reporting (e.g., async).
  2173. *
  2174. * This call triggers a fetch queue barrier flush.
  2175. *
  2176. * @returns `RD_KAFKA_RESP_ERR__NO_ERROR` on success else an error code.
  2177. */
  2178. RD_EXPORT
  2179. rd_kafka_resp_err_t rd_kafka_seek (rd_kafka_topic_t *rkt,
  2180. int32_t partition,
  2181. int64_t offset,
  2182. int timeout_ms);
  2183. /**
  2184. * @brief Consume a single message from topic \p rkt and \p partition
  2185. *
  2186. * \p timeout_ms is maximum amount of time to wait for a message to be received.
  2187. * Consumer must have been previously started with `rd_kafka_consume_start()`.
  2188. *
  2189. * @returns a message object on success or \c NULL on error.
  2190. * The message object must be destroyed with `rd_kafka_message_destroy()`
  2191. * when the application is done with it.
  2192. *
  2193. * Errors (when returning NULL):
  2194. * - ETIMEDOUT - \p timeout_ms was reached with no new messages fetched.
  2195. * - ENOENT - \p rkt + \p partition is unknown.
  2196. * (no prior `rd_kafka_consume_start()` call)
  2197. *
  2198. * NOTE: The returned message's \c ..->err must be checked for errors.
  2199. * NOTE: \c ..->err \c == \c RD_KAFKA_RESP_ERR__PARTITION_EOF signals that the
  2200. * end of the partition has been reached, which should typically not be
  2201. * considered an error. The application should handle this case
  2202. * (e.g., ignore).
  2203. *
  2204. * @remark on_consume() interceptors may be called from this function prior to
  2205. * passing message to application.
  2206. */
  2207. RD_EXPORT
  2208. rd_kafka_message_t *rd_kafka_consume(rd_kafka_topic_t *rkt, int32_t partition,
  2209. int timeout_ms);
  2210. /**
  2211. * @brief Consume up to \p rkmessages_size from topic \p rkt and \p partition
  2212. * putting a pointer to each message in the application provided
  2213. * array \p rkmessages (of size \p rkmessages_size entries).
  2214. *
  2215. * `rd_kafka_consume_batch()` provides higher throughput performance
  2216. * than `rd_kafka_consume()`.
  2217. *
  2218. * \p timeout_ms is the maximum amount of time to wait for all of
  2219. * \p rkmessages_size messages to be put into \p rkmessages.
  2220. * If no messages were available within the timeout period this function
  2221. * returns 0 and \p rkmessages remains untouched.
  2222. * This differs somewhat from `rd_kafka_consume()`.
  2223. *
  2224. * The message objects must be destroyed with `rd_kafka_message_destroy()`
  2225. * when the application is done with it.
  2226. *
  2227. * @returns the number of rkmessages added in \p rkmessages,
  2228. * or -1 on error (same error codes as for `rd_kafka_consume()`.
  2229. *
  2230. * @sa rd_kafka_consume()
  2231. *
  2232. * @remark on_consume() interceptors may be called from this function prior to
  2233. * passing message to application.
  2234. */
  2235. RD_EXPORT
  2236. ssize_t rd_kafka_consume_batch(rd_kafka_topic_t *rkt, int32_t partition,
  2237. int timeout_ms,
  2238. rd_kafka_message_t **rkmessages,
  2239. size_t rkmessages_size);
  2240. /**
  2241. * @brief Consumes messages from topic \p rkt and \p partition, calling
  2242. * the provided callback for each consumed messsage.
  2243. *
  2244. * `rd_kafka_consume_callback()` provides higher throughput performance
  2245. * than both `rd_kafka_consume()` and `rd_kafka_consume_batch()`.
  2246. *
  2247. * \p timeout_ms is the maximum amount of time to wait for one or more messages
  2248. * to arrive.
  2249. *
  2250. * The provided \p consume_cb function is called for each message,
  2251. * the application \b MUST \b NOT call `rd_kafka_message_destroy()` on the
  2252. * provided \p rkmessage.
  2253. *
  2254. * The \p opaque argument is passed to the 'consume_cb' as \p opaque.
  2255. *
  2256. * @returns the number of messages processed or -1 on error.
  2257. *
  2258. * @sa rd_kafka_consume()
  2259. *
  2260. * @remark on_consume() interceptors may be called from this function prior to
  2261. * passing message to application.
  2262. */
  2263. RD_EXPORT
  2264. int rd_kafka_consume_callback(rd_kafka_topic_t *rkt, int32_t partition,
  2265. int timeout_ms,
  2266. void (*consume_cb) (rd_kafka_message_t
  2267. *rkmessage,
  2268. void *opaque),
  2269. void *opaque);
  2270. /**
  2271. * @name Simple Consumer API (legacy): Queue consumers
  2272. * @{
  2273. *
  2274. * The following `..._queue()` functions are analogue to the functions above
  2275. * but reads messages from the provided queue \p rkqu instead.
  2276. * \p rkqu must have been previously created with `rd_kafka_queue_new()`
  2277. * and the topic consumer must have been started with
  2278. * `rd_kafka_consume_start_queue()` utilising the the same queue.
  2279. */
  2280. /**
  2281. * @brief Consume from queue
  2282. *
  2283. * @sa rd_kafka_consume()
  2284. */
  2285. RD_EXPORT
  2286. rd_kafka_message_t *rd_kafka_consume_queue(rd_kafka_queue_t *rkqu,
  2287. int timeout_ms);
  2288. /**
  2289. * @brief Consume batch of messages from queue
  2290. *
  2291. * @sa rd_kafka_consume_batch()
  2292. */
  2293. RD_EXPORT
  2294. ssize_t rd_kafka_consume_batch_queue(rd_kafka_queue_t *rkqu,
  2295. int timeout_ms,
  2296. rd_kafka_message_t **rkmessages,
  2297. size_t rkmessages_size);
  2298. /**
  2299. * @brief Consume multiple messages from queue with callback
  2300. *
  2301. * @sa rd_kafka_consume_callback()
  2302. */
  2303. RD_EXPORT
  2304. int rd_kafka_consume_callback_queue(rd_kafka_queue_t *rkqu,
  2305. int timeout_ms,
  2306. void (*consume_cb) (rd_kafka_message_t
  2307. *rkmessage,
  2308. void *opaque),
  2309. void *opaque);
  2310. /**@}*/
  2311. /**
  2312. * @name Simple Consumer API (legacy): Topic+partition offset store.
  2313. * @{
  2314. *
  2315. * If \c auto.commit.enable is true the offset is stored automatically prior to
  2316. * returning of the message(s) in each of the rd_kafka_consume*() functions
  2317. * above.
  2318. */
  2319. /**
  2320. * @brief Store offset \p offset for topic \p rkt partition \p partition.
  2321. *
  2322. * The offset will be committed (written) to the offset store according
  2323. * to \c `auto.commit.interval.ms` or manual offset-less commit()
  2324. *
  2325. * @remark \c `enable.auto.offset.store` must be set to "false" when using this API.
  2326. *
  2327. * @returns RD_KAFKA_RESP_ERR_NO_ERROR on success or an error code on error.
  2328. */
  2329. RD_EXPORT
  2330. rd_kafka_resp_err_t rd_kafka_offset_store(rd_kafka_topic_t *rkt,
  2331. int32_t partition, int64_t offset);
  2332. /**
  2333. * @brief Store offsets for next auto-commit for one or more partitions.
  2334. *
  2335. * The offset will be committed (written) to the offset store according
  2336. * to \c `auto.commit.interval.ms` or manual offset-less commit().
  2337. *
  2338. * Per-partition success/error status propagated through each partition's
  2339. * \c .err field.
  2340. *
  2341. * @remark \c `enable.auto.offset.store` must be set to "false" when using this API.
  2342. *
  2343. * @returns RD_KAFKA_RESP_ERR_NO_ERROR on success, or
  2344. * RD_KAFKA_RESP_ERR__UNKNOWN_PARTITION if none of the
  2345. * offsets could be stored, or
  2346. * RD_KAFKA_RESP_ERR__INVALID_ARG if \c enable.auto.offset.store is true.
  2347. */
  2348. RD_EXPORT rd_kafka_resp_err_t
  2349. rd_kafka_offsets_store(rd_kafka_t *rk,
  2350. rd_kafka_topic_partition_list_t *offsets);
  2351. /**@}*/
  2352. /**
  2353. * @name KafkaConsumer (C)
  2354. * @{
  2355. * @brief High-level KafkaConsumer C API
  2356. *
  2357. *
  2358. *
  2359. */
  2360. /**
  2361. * @brief Subscribe to topic set using balanced consumer groups.
  2362. *
  2363. * Wildcard (regex) topics are supported by the librdkafka assignor:
  2364. * any topic name in the \p topics list that is prefixed with \c \"^\" will
  2365. * be regex-matched to the full list of topics in the cluster and matching
  2366. * topics will be added to the subscription list.
  2367. *
  2368. * @returns RD_KAFKA_RESP_ERR_NO_ERROR on success or
  2369. * RD_KAFKA_RESP_ERR__INVALID_ARG if list is empty, contains invalid
  2370. * topics or regexes.
  2371. */
  2372. RD_EXPORT rd_kafka_resp_err_t
  2373. rd_kafka_subscribe (rd_kafka_t *rk,
  2374. const rd_kafka_topic_partition_list_t *topics);
  2375. /**
  2376. * @brief Unsubscribe from the current subscription set.
  2377. */
  2378. RD_EXPORT
  2379. rd_kafka_resp_err_t rd_kafka_unsubscribe (rd_kafka_t *rk);
  2380. /**
  2381. * @brief Returns the current topic subscription
  2382. *
  2383. * @returns An error code on failure, otherwise \p topic is updated
  2384. * to point to a newly allocated topic list (possibly empty).
  2385. *
  2386. * @remark The application is responsible for calling
  2387. * rd_kafka_topic_partition_list_destroy on the returned list.
  2388. */
  2389. RD_EXPORT rd_kafka_resp_err_t
  2390. rd_kafka_subscription (rd_kafka_t *rk,
  2391. rd_kafka_topic_partition_list_t **topics);
  2392. /**
  2393. * @brief Poll the consumer for messages or events.
  2394. *
  2395. * Will block for at most \p timeout_ms milliseconds.
  2396. *
  2397. * @remark An application should make sure to call consumer_poll() at regular
  2398. * intervals, even if no messages are expected, to serve any
  2399. * queued callbacks waiting to be called. This is especially
  2400. * important when a rebalance_cb has been registered as it needs
  2401. * to be called and handled properly to synchronize internal
  2402. * consumer state.
  2403. *
  2404. * @returns A message object which is a proper message if \p ->err is
  2405. * RD_KAFKA_RESP_ERR_NO_ERROR, or an event or error for any other
  2406. * value.
  2407. *
  2408. * @remark on_consume() interceptors may be called from this function prior to
  2409. * passing message to application.
  2410. *
  2411. * @sa rd_kafka_message_t
  2412. */
  2413. RD_EXPORT
  2414. rd_kafka_message_t *rd_kafka_consumer_poll (rd_kafka_t *rk, int timeout_ms);
  2415. /**
  2416. * @brief Close down the KafkaConsumer.
  2417. *
  2418. * @remark This call will block until the consumer has revoked its assignment,
  2419. * calling the \c rebalance_cb if it is configured, committed offsets
  2420. * to broker, and left the consumer group.
  2421. * The maximum blocking time is roughly limited to session.timeout.ms.
  2422. *
  2423. * @returns An error code indicating if the consumer close was succesful
  2424. * or not.
  2425. *
  2426. * @remark The application still needs to call rd_kafka_destroy() after
  2427. * this call finishes to clean up the underlying handle resources.
  2428. *
  2429. */
  2430. RD_EXPORT
  2431. rd_kafka_resp_err_t rd_kafka_consumer_close (rd_kafka_t *rk);
  2432. /**
  2433. * @brief Atomic assignment of partitions to consume.
  2434. *
  2435. * The new \p partitions will replace the existing assignment.
  2436. *
  2437. * When used from a rebalance callback the application shall pass the
  2438. * partition list passed to the callback (or a copy of it) (even if the list
  2439. * is empty) rather than NULL to maintain internal join state.
  2440. * A zero-length \p partitions will treat the partitions as a valid,
  2441. * albeit empty, assignment, and maintain internal state, while a \c NULL
  2442. * value for \p partitions will reset and clear the internal state.
  2443. */
  2444. RD_EXPORT rd_kafka_resp_err_t
  2445. rd_kafka_assign (rd_kafka_t *rk,
  2446. const rd_kafka_topic_partition_list_t *partitions);
  2447. /**
  2448. * @brief Returns the current partition assignment
  2449. *
  2450. * @returns An error code on failure, otherwise \p partitions is updated
  2451. * to point to a newly allocated partition list (possibly empty).
  2452. *
  2453. * @remark The application is responsible for calling
  2454. * rd_kafka_topic_partition_list_destroy on the returned list.
  2455. */
  2456. RD_EXPORT rd_kafka_resp_err_t
  2457. rd_kafka_assignment (rd_kafka_t *rk,
  2458. rd_kafka_topic_partition_list_t **partitions);
  2459. /**
  2460. * @brief Commit offsets on broker for the provided list of partitions.
  2461. *
  2462. * \p offsets should contain \c topic, \c partition, \c offset and possibly
  2463. * \c metadata.
  2464. * If \p offsets is NULL the current partition assignment will be used instead.
  2465. *
  2466. * If \p async is false this operation will block until the broker offset commit
  2467. * is done, returning the resulting success or error code.
  2468. *
  2469. * If a rd_kafka_conf_set_offset_commit_cb() offset commit callback has been
  2470. * configured the callback will be enqueued for a future call to
  2471. * rd_kafka_poll(), rd_kafka_consumer_poll() or similar.
  2472. */
  2473. RD_EXPORT rd_kafka_resp_err_t
  2474. rd_kafka_commit (rd_kafka_t *rk, const rd_kafka_topic_partition_list_t *offsets,
  2475. int async);
  2476. /**
  2477. * @brief Commit message's offset on broker for the message's partition.
  2478. *
  2479. * @sa rd_kafka_commit
  2480. */
  2481. RD_EXPORT rd_kafka_resp_err_t
  2482. rd_kafka_commit_message (rd_kafka_t *rk, const rd_kafka_message_t *rkmessage,
  2483. int async);
  2484. /**
  2485. * @brief Commit offsets on broker for the provided list of partitions.
  2486. *
  2487. * See rd_kafka_commit for \p offsets semantics.
  2488. *
  2489. * The result of the offset commit will be posted on the provided \p rkqu queue.
  2490. *
  2491. * If the application uses one of the poll APIs (rd_kafka_poll(),
  2492. * rd_kafka_consumer_poll(), rd_kafka_queue_poll(), ..) to serve the queue
  2493. * the \p cb callback is required. \p opaque is passed to the callback.
  2494. *
  2495. * If using the event API the callback is ignored and the offset commit result
  2496. * will be returned as an RD_KAFKA_EVENT_COMMIT event. The \p opaque
  2497. * value will be available with rd_kafka_event_opaque()
  2498. *
  2499. * If \p rkqu is NULL a temporary queue will be created and the callback will
  2500. * be served by this call.
  2501. *
  2502. * @sa rd_kafka_commit()
  2503. * @sa rd_kafka_conf_set_offset_commit_cb()
  2504. */
  2505. RD_EXPORT rd_kafka_resp_err_t
  2506. rd_kafka_commit_queue (rd_kafka_t *rk,
  2507. const rd_kafka_topic_partition_list_t *offsets,
  2508. rd_kafka_queue_t *rkqu,
  2509. void (*cb) (rd_kafka_t *rk,
  2510. rd_kafka_resp_err_t err,
  2511. rd_kafka_topic_partition_list_t *offsets,
  2512. void *opaque),
  2513. void *opaque);
  2514. /**
  2515. * @brief Retrieve committed offsets for topics+partitions.
  2516. *
  2517. * The \p offset field of each requested partition will either be set to
  2518. * stored offset or to RD_KAFKA_OFFSET_INVALID in case there was no stored
  2519. * offset for that partition.
  2520. *
  2521. * @returns RD_KAFKA_RESP_ERR_NO_ERROR on success in which case the
  2522. * \p offset or \p err field of each \p partitions' element is filled
  2523. * in with the stored offset, or a partition specific error.
  2524. * Else returns an error code.
  2525. */
  2526. RD_EXPORT rd_kafka_resp_err_t
  2527. rd_kafka_committed (rd_kafka_t *rk,
  2528. rd_kafka_topic_partition_list_t *partitions,
  2529. int timeout_ms);
  2530. /**
  2531. * @brief Retrieve current positions (offsets) for topics+partitions.
  2532. *
  2533. * The \p offset field of each requested partition will be set to the offset
  2534. * of the last consumed message + 1, or RD_KAFKA_OFFSET_INVALID in case there was
  2535. * no previous message.
  2536. *
  2537. * @returns RD_KAFKA_RESP_ERR_NO_ERROR on success in which case the
  2538. * \p offset or \p err field of each \p partitions' element is filled
  2539. * in with the stored offset, or a partition specific error.
  2540. * Else returns an error code.
  2541. */
  2542. RD_EXPORT rd_kafka_resp_err_t
  2543. rd_kafka_position (rd_kafka_t *rk,
  2544. rd_kafka_topic_partition_list_t *partitions);
  2545. /**@}*/
  2546. /**
  2547. * @name Producer API
  2548. * @{
  2549. *
  2550. *
  2551. */
  2552. /**
  2553. * @brief Producer message flags
  2554. */
  2555. #define RD_KAFKA_MSG_F_FREE 0x1 /**< Delegate freeing of payload to rdkafka. */
  2556. #define RD_KAFKA_MSG_F_COPY 0x2 /**< rdkafka will make a copy of the payload. */
  2557. #define RD_KAFKA_MSG_F_BLOCK 0x4 /**< Block produce*() on message queue full.
  2558. * WARNING: If a delivery report callback
  2559. * is used the application MUST
  2560. * call rd_kafka_poll() (or equiv.)
  2561. * to make sure delivered messages
  2562. * are drained from the internal
  2563. * delivery report queue.
  2564. * Failure to do so will result
  2565. * in indefinately blocking on
  2566. * the produce() call when the
  2567. * message queue is full. */
  2568. #define RD_KAFKA_MSG_F_PARTITION 0x8 /**< produce_batch() will honor
  2569. * per-message partition. */
  2570. /**
  2571. * @brief Produce and send a single message to broker.
  2572. *
  2573. * \p rkt is the target topic which must have been previously created with
  2574. * `rd_kafka_topic_new()`.
  2575. *
  2576. * `rd_kafka_produce()` is an asynch non-blocking API.
  2577. *
  2578. * \p partition is the target partition, either:
  2579. * - RD_KAFKA_PARTITION_UA (unassigned) for
  2580. * automatic partitioning using the topic's partitioner function, or
  2581. * - a fixed partition (0..N)
  2582. *
  2583. * \p msgflags is zero or more of the following flags OR:ed together:
  2584. * RD_KAFKA_MSG_F_BLOCK - block \p produce*() call if
  2585. * \p queue.buffering.max.messages or
  2586. * \p queue.buffering.max.kbytes are exceeded.
  2587. * Messages are considered in-queue from the point they
  2588. * are accepted by produce() until their corresponding
  2589. * delivery report callback/event returns.
  2590. * It is thus a requirement to call
  2591. * rd_kafka_poll() (or equiv.) from a separate
  2592. * thread when F_BLOCK is used.
  2593. * See WARNING on \c RD_KAFKA_MSG_F_BLOCK above.
  2594. *
  2595. * RD_KAFKA_MSG_F_FREE - rdkafka will free(3) \p payload when it is done
  2596. * with it.
  2597. * RD_KAFKA_MSG_F_COPY - the \p payload data will be copied and the
  2598. * \p payload pointer will not be used by rdkafka
  2599. * after the call returns.
  2600. * RD_KAFKA_MSG_F_PARTITION - produce_batch() will honour per-message
  2601. * partition, either set manually or by the
  2602. * configured partitioner.
  2603. *
  2604. * .._F_FREE and .._F_COPY are mutually exclusive.
  2605. *
  2606. * If the function returns -1 and RD_KAFKA_MSG_F_FREE was specified, then
  2607. * the memory associated with the payload is still the caller's
  2608. * responsibility.
  2609. *
  2610. * \p payload is the message payload of size \p len bytes.
  2611. *
  2612. * \p key is an optional message key of size \p keylen bytes, if non-NULL it
  2613. * will be passed to the topic partitioner as well as be sent with the
  2614. * message to the broker and passed on to the consumer.
  2615. *
  2616. * \p msg_opaque is an optional application-provided per-message opaque
  2617. * pointer that will provided in the delivery report callback (`dr_cb`) for
  2618. * referencing this message.
  2619. *
  2620. * @remark on_send() and on_acknowledgement() interceptors may be called
  2621. * from this function. on_acknowledgement() will only be called if the
  2622. * message fails partitioning.
  2623. *
  2624. * @returns 0 on success or -1 on error in which case errno is set accordingly:
  2625. * - ENOBUFS - maximum number of outstanding messages has been reached:
  2626. * "queue.buffering.max.messages"
  2627. * (RD_KAFKA_RESP_ERR__QUEUE_FULL)
  2628. * - EMSGSIZE - message is larger than configured max size:
  2629. * "messages.max.bytes".
  2630. * (RD_KAFKA_RESP_ERR_MSG_SIZE_TOO_LARGE)
  2631. * - ESRCH - requested \p partition is unknown in the Kafka cluster.
  2632. * (RD_KAFKA_RESP_ERR__UNKNOWN_PARTITION)
  2633. * - ENOENT - topic is unknown in the Kafka cluster.
  2634. * (RD_KAFKA_RESP_ERR__UNKNOWN_TOPIC)
  2635. *
  2636. * @sa Use rd_kafka_errno2err() to convert `errno` to rdkafka error code.
  2637. */
  2638. RD_EXPORT
  2639. int rd_kafka_produce(rd_kafka_topic_t *rkt, int32_t partition,
  2640. int msgflags,
  2641. void *payload, size_t len,
  2642. const void *key, size_t keylen,
  2643. void *msg_opaque);
  2644. /**
  2645. * @brief Produce and send a single message to broker.
  2646. *
  2647. * The message is defined by a va-arg list using \c rd_kafka_vtype_t
  2648. * tag tuples which must be terminated with a single \c RD_KAFKA_V_END.
  2649. *
  2650. * @returns \c RD_KAFKA_RESP_ERR_NO_ERROR on success, else an error code.
  2651. * \c RD_KAFKA_RESP_ERR__CONFLICT is returned if _V_HEADER and
  2652. * _V_HEADERS are mixed.
  2653. *
  2654. * @sa rd_kafka_produce, RD_KAFKA_V_END
  2655. */
  2656. RD_EXPORT
  2657. rd_kafka_resp_err_t rd_kafka_producev (rd_kafka_t *rk, ...);
  2658. /**
  2659. * @brief Produce multiple messages.
  2660. *
  2661. * If partition is RD_KAFKA_PARTITION_UA the configured partitioner will
  2662. * be run for each message (slower), otherwise the messages will be enqueued
  2663. * to the specified partition directly (faster).
  2664. *
  2665. * The messages are provided in the array \p rkmessages of count \p message_cnt
  2666. * elements.
  2667. * The \p partition and \p msgflags are used for all provided messages.
  2668. *
  2669. * Honoured \p rkmessages[] fields are:
  2670. * - payload,len Message payload and length
  2671. * - key,key_len Optional message key
  2672. * - _private Message opaque pointer (msg_opaque)
  2673. * - err Will be set according to success or failure.
  2674. * Application only needs to check for errors if
  2675. * return value != \p message_cnt.
  2676. *
  2677. * @returns the number of messages succesfully enqueued for producing.
  2678. *
  2679. * @remark This interface does NOT support setting message headers on
  2680. * the provided \p rkmessages.
  2681. */
  2682. RD_EXPORT
  2683. int rd_kafka_produce_batch(rd_kafka_topic_t *rkt, int32_t partition,
  2684. int msgflags,
  2685. rd_kafka_message_t *rkmessages, int message_cnt);
  2686. /**
  2687. * @brief Wait until all outstanding produce requests, et.al, are completed.
  2688. * This should typically be done prior to destroying a producer instance
  2689. * to make sure all queued and in-flight produce requests are completed
  2690. * before terminating.
  2691. *
  2692. * @remark This function will call rd_kafka_poll() and thus trigger callbacks.
  2693. *
  2694. * @returns RD_KAFKA_RESP_ERR__TIMED_OUT if \p timeout_ms was reached before all
  2695. * outstanding requests were completed, else RD_KAFKA_RESP_ERR_NO_ERROR
  2696. */
  2697. RD_EXPORT
  2698. rd_kafka_resp_err_t rd_kafka_flush (rd_kafka_t *rk, int timeout_ms);
  2699. /**@}*/
  2700. /**
  2701. * @name Metadata API
  2702. * @{
  2703. *
  2704. *
  2705. */
  2706. /**
  2707. * @brief Broker information
  2708. */
  2709. typedef struct rd_kafka_metadata_broker {
  2710. int32_t id; /**< Broker Id */
  2711. char *host; /**< Broker hostname */
  2712. int port; /**< Broker listening port */
  2713. } rd_kafka_metadata_broker_t;
  2714. /**
  2715. * @brief Partition information
  2716. */
  2717. typedef struct rd_kafka_metadata_partition {
  2718. int32_t id; /**< Partition Id */
  2719. rd_kafka_resp_err_t err; /**< Partition error reported by broker */
  2720. int32_t leader; /**< Leader broker */
  2721. int replica_cnt; /**< Number of brokers in \p replicas */
  2722. int32_t *replicas; /**< Replica brokers */
  2723. int isr_cnt; /**< Number of ISR brokers in \p isrs */
  2724. int32_t *isrs; /**< In-Sync-Replica brokers */
  2725. } rd_kafka_metadata_partition_t;
  2726. /**
  2727. * @brief Topic information
  2728. */
  2729. typedef struct rd_kafka_metadata_topic {
  2730. char *topic; /**< Topic name */
  2731. int partition_cnt; /**< Number of partitions in \p partitions*/
  2732. struct rd_kafka_metadata_partition *partitions; /**< Partitions */
  2733. rd_kafka_resp_err_t err; /**< Topic error reported by broker */
  2734. } rd_kafka_metadata_topic_t;
  2735. /**
  2736. * @brief Metadata container
  2737. */
  2738. typedef struct rd_kafka_metadata {
  2739. int broker_cnt; /**< Number of brokers in \p brokers */
  2740. struct rd_kafka_metadata_broker *brokers; /**< Brokers */
  2741. int topic_cnt; /**< Number of topics in \p topics */
  2742. struct rd_kafka_metadata_topic *topics; /**< Topics */
  2743. int32_t orig_broker_id; /**< Broker originating this metadata */
  2744. char *orig_broker_name; /**< Name of originating broker */
  2745. } rd_kafka_metadata_t;
  2746. /**
  2747. * @brief Request Metadata from broker.
  2748. *
  2749. * Parameters:
  2750. * - \p all_topics if non-zero: request info about all topics in cluster,
  2751. * if zero: only request info about locally known topics.
  2752. * - \p only_rkt only request info about this topic
  2753. * - \p metadatap pointer to hold metadata result.
  2754. * The \p *metadatap pointer must be released
  2755. * with rd_kafka_metadata_destroy().
  2756. * - \p timeout_ms maximum response time before failing.
  2757. *
  2758. * Returns RD_KAFKA_RESP_ERR_NO_ERROR on success (in which case *metadatap)
  2759. * will be set, else RD_KAFKA_RESP_ERR__TIMED_OUT on timeout or
  2760. * other error code on error.
  2761. */
  2762. RD_EXPORT
  2763. rd_kafka_resp_err_t
  2764. rd_kafka_metadata (rd_kafka_t *rk, int all_topics,
  2765. rd_kafka_topic_t *only_rkt,
  2766. const struct rd_kafka_metadata **metadatap,
  2767. int timeout_ms);
  2768. /**
  2769. * @brief Release metadata memory.
  2770. */
  2771. RD_EXPORT
  2772. void rd_kafka_metadata_destroy(const struct rd_kafka_metadata *metadata);
  2773. /**@}*/
  2774. /**
  2775. * @name Client group information
  2776. * @{
  2777. *
  2778. *
  2779. */
  2780. /**
  2781. * @brief Group member information
  2782. *
  2783. * For more information on \p member_metadata format, see
  2784. * https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol#AGuideToTheKafkaProtocol-GroupMembershipAPI
  2785. *
  2786. */
  2787. struct rd_kafka_group_member_info {
  2788. char *member_id; /**< Member id (generated by broker) */
  2789. char *client_id; /**< Client's \p client.id */
  2790. char *client_host; /**< Client's hostname */
  2791. void *member_metadata; /**< Member metadata (binary),
  2792. * format depends on \p protocol_type. */
  2793. int member_metadata_size; /**< Member metadata size in bytes */
  2794. void *member_assignment; /**< Member assignment (binary),
  2795. * format depends on \p protocol_type. */
  2796. int member_assignment_size; /**< Member assignment size in bytes */
  2797. };
  2798. /**
  2799. * @brief Group information
  2800. */
  2801. struct rd_kafka_group_info {
  2802. struct rd_kafka_metadata_broker broker; /**< Originating broker info */
  2803. char *group; /**< Group name */
  2804. rd_kafka_resp_err_t err; /**< Broker-originated error */
  2805. char *state; /**< Group state */
  2806. char *protocol_type; /**< Group protocol type */
  2807. char *protocol; /**< Group protocol */
  2808. struct rd_kafka_group_member_info *members; /**< Group members */
  2809. int member_cnt; /**< Group member count */
  2810. };
  2811. /**
  2812. * @brief List of groups
  2813. *
  2814. * @sa rd_kafka_group_list_destroy() to release list memory.
  2815. */
  2816. struct rd_kafka_group_list {
  2817. struct rd_kafka_group_info *groups; /**< Groups */
  2818. int group_cnt; /**< Group count */
  2819. };
  2820. /**
  2821. * @brief List and describe client groups in cluster.
  2822. *
  2823. * \p group is an optional group name to describe, otherwise (\p NULL) all
  2824. * groups are returned.
  2825. *
  2826. * \p timeout_ms is the (approximate) maximum time to wait for response
  2827. * from brokers and must be a positive value.
  2828. *
  2829. * @returns \c RD_KAFKA_RESP_ERR__NO_ERROR on success and \p grplistp is
  2830. * updated to point to a newly allocated list of groups.
  2831. * \c RD_KAFKA_RESP_ERR__PARTIAL if not all brokers responded
  2832. * in time but at least one group is returned in \p grplistlp.
  2833. * \c RD_KAFKA_RESP_ERR__TIMED_OUT if no groups were returned in the
  2834. * given timeframe but not all brokers have yet responded, or
  2835. * if the list of brokers in the cluster could not be obtained within
  2836. * the given timeframe.
  2837. * \c RD_KAFKA_RESP_ERR__TRANSPORT if no brokers were found.
  2838. * Other error codes may also be returned from the request layer.
  2839. *
  2840. * The \p grplistp remains untouched if any error code is returned,
  2841. * with the exception of RD_KAFKA_RESP_ERR__PARTIAL which behaves
  2842. * as RD_KAFKA_RESP_ERR__NO_ERROR (success) but with an incomplete
  2843. * group list.
  2844. *
  2845. * @sa Use rd_kafka_group_list_destroy() to release list memory.
  2846. */
  2847. RD_EXPORT
  2848. rd_kafka_resp_err_t
  2849. rd_kafka_list_groups (rd_kafka_t *rk, const char *group,
  2850. const struct rd_kafka_group_list **grplistp,
  2851. int timeout_ms);
  2852. /**
  2853. * @brief Release list memory
  2854. */
  2855. RD_EXPORT
  2856. void rd_kafka_group_list_destroy (const struct rd_kafka_group_list *grplist);
  2857. /**@}*/
  2858. /**
  2859. * @name Miscellaneous APIs
  2860. * @{
  2861. *
  2862. */
  2863. /**
  2864. * @brief Adds one or more brokers to the kafka handle's list of initial
  2865. * bootstrap brokers.
  2866. *
  2867. * Additional brokers will be discovered automatically as soon as rdkafka
  2868. * connects to a broker by querying the broker metadata.
  2869. *
  2870. * If a broker name resolves to multiple addresses (and possibly
  2871. * address families) all will be used for connection attempts in
  2872. * round-robin fashion.
  2873. *
  2874. * \p brokerlist is a ,-separated list of brokers in the format:
  2875. * \c \<broker1\>,\<broker2\>,..
  2876. * Where each broker is in either the host or URL based format:
  2877. * \c \<host\>[:\<port\>]
  2878. * \c \<proto\>://\<host\>[:port]
  2879. * \c \<proto\> is either \c PLAINTEXT, \c SSL, \c SASL, \c SASL_PLAINTEXT
  2880. * The two formats can be mixed but ultimately the value of the
  2881. * `security.protocol` config property decides what brokers are allowed.
  2882. *
  2883. * Example:
  2884. * brokerlist = "broker1:10000,broker2"
  2885. * brokerlist = "SSL://broker3:9000,ssl://broker2"
  2886. *
  2887. * @returns the number of brokers successfully added.
  2888. *
  2889. * @remark Brokers may also be defined with the \c metadata.broker.list or
  2890. * \c bootstrap.servers configuration property (preferred method).
  2891. */
  2892. RD_EXPORT
  2893. int rd_kafka_brokers_add(rd_kafka_t *rk, const char *brokerlist);
  2894. /**
  2895. * @brief Set logger function.
  2896. *
  2897. * The default is to print to stderr, but a syslog logger is also available,
  2898. * see rd_kafka_log_(print|syslog) for the builtin alternatives.
  2899. * Alternatively the application may provide its own logger callback.
  2900. * Or pass 'func' as NULL to disable logging.
  2901. *
  2902. * @deprecated Use rd_kafka_conf_set_log_cb()
  2903. *
  2904. * @remark \p rk may be passed as NULL in the callback.
  2905. */
  2906. RD_EXPORT RD_DEPRECATED
  2907. void rd_kafka_set_logger(rd_kafka_t *rk,
  2908. void (*func) (const rd_kafka_t *rk, int level,
  2909. const char *fac, const char *buf));
  2910. /**
  2911. * @brief Specifies the maximum logging level produced by
  2912. * internal kafka logging and debugging.
  2913. *
  2914. * If the \p \"debug\" configuration property is set the level is automatically
  2915. * adjusted to \c LOG_DEBUG (7).
  2916. */
  2917. RD_EXPORT
  2918. void rd_kafka_set_log_level(rd_kafka_t *rk, int level);
  2919. /**
  2920. * @brief Builtin (default) log sink: print to stderr
  2921. */
  2922. RD_EXPORT
  2923. void rd_kafka_log_print(const rd_kafka_t *rk, int level,
  2924. const char *fac, const char *buf);
  2925. /**
  2926. * @brief Builtin log sink: print to syslog.
  2927. */
  2928. RD_EXPORT
  2929. void rd_kafka_log_syslog(const rd_kafka_t *rk, int level,
  2930. const char *fac, const char *buf);
  2931. /**
  2932. * @brief Returns the current out queue length.
  2933. *
  2934. * The out queue contains messages waiting to be sent to, or acknowledged by,
  2935. * the broker.
  2936. *
  2937. * An application should wait for this queue to reach zero before terminating
  2938. * to make sure outstanding requests (such as offset commits) are fully
  2939. * processed.
  2940. *
  2941. * @returns number of messages in the out queue.
  2942. */
  2943. RD_EXPORT
  2944. int rd_kafka_outq_len(rd_kafka_t *rk);
  2945. /**
  2946. * @brief Dumps rdkafka's internal state for handle \p rk to stream \p fp
  2947. *
  2948. * This is only useful for debugging rdkafka, showing state and statistics
  2949. * for brokers, topics, partitions, etc.
  2950. */
  2951. RD_EXPORT
  2952. void rd_kafka_dump(FILE *fp, rd_kafka_t *rk);
  2953. /**
  2954. * @brief Retrieve the current number of threads in use by librdkafka.
  2955. *
  2956. * Used by regression tests.
  2957. */
  2958. RD_EXPORT
  2959. int rd_kafka_thread_cnt(void);
  2960. /**
  2961. * @brief Wait for all rd_kafka_t objects to be destroyed.
  2962. *
  2963. * Returns 0 if all kafka objects are now destroyed, or -1 if the
  2964. * timeout was reached.
  2965. *
  2966. * @remark This function is deprecated.
  2967. */
  2968. RD_EXPORT
  2969. int rd_kafka_wait_destroyed(int timeout_ms);
  2970. /**
  2971. * @brief Run librdkafka's built-in unit-tests.
  2972. *
  2973. * @returns the number of failures, or 0 if all tests passed.
  2974. */
  2975. RD_EXPORT
  2976. int rd_kafka_unittest (void);
  2977. /**@}*/
  2978. /**
  2979. * @name Experimental APIs
  2980. * @{
  2981. */
  2982. /**
  2983. * @brief Redirect the main (rd_kafka_poll()) queue to the KafkaConsumer's
  2984. * queue (rd_kafka_consumer_poll()).
  2985. *
  2986. * @warning It is not permitted to call rd_kafka_poll() after directing the
  2987. * main queue with rd_kafka_poll_set_consumer().
  2988. */
  2989. RD_EXPORT
  2990. rd_kafka_resp_err_t rd_kafka_poll_set_consumer (rd_kafka_t *rk);
  2991. /**@}*/
  2992. /**
  2993. * @name Event interface
  2994. *
  2995. * @brief The event API provides an alternative pollable non-callback interface
  2996. * to librdkafka's message and event queues.
  2997. *
  2998. * @{
  2999. */
  3000. /**
  3001. * @brief Event types
  3002. */
  3003. typedef int rd_kafka_event_type_t;
  3004. #define RD_KAFKA_EVENT_NONE 0x0
  3005. #define RD_KAFKA_EVENT_DR 0x1 /**< Producer Delivery report batch */
  3006. #define RD_KAFKA_EVENT_FETCH 0x2 /**< Fetched message (consumer) */
  3007. #define RD_KAFKA_EVENT_LOG 0x4 /**< Log message */
  3008. #define RD_KAFKA_EVENT_ERROR 0x8 /**< Error */
  3009. #define RD_KAFKA_EVENT_REBALANCE 0x10 /**< Group rebalance (consumer) */
  3010. #define RD_KAFKA_EVENT_OFFSET_COMMIT 0x20 /**< Offset commit result */
  3011. #define RD_KAFKA_EVENT_STATS 0x40 /**< Stats */
  3012. typedef struct rd_kafka_op_s rd_kafka_event_t;
  3013. /**
  3014. * @returns the event type for the given event.
  3015. *
  3016. * @remark As a convenience it is okay to pass \p rkev as NULL in which case
  3017. * RD_KAFKA_EVENT_NONE is returned.
  3018. */
  3019. RD_EXPORT
  3020. rd_kafka_event_type_t rd_kafka_event_type (const rd_kafka_event_t *rkev);
  3021. /**
  3022. * @returns the event type's name for the given event.
  3023. *
  3024. * @remark As a convenience it is okay to pass \p rkev as NULL in which case
  3025. * the name for RD_KAFKA_EVENT_NONE is returned.
  3026. */
  3027. RD_EXPORT
  3028. const char *rd_kafka_event_name (const rd_kafka_event_t *rkev);
  3029. /**
  3030. * @brief Destroy an event.
  3031. *
  3032. * @remark Any references to this event, such as extracted messages,
  3033. * will not be usable after this call.
  3034. *
  3035. * @remark As a convenience it is okay to pass \p rkev as NULL in which case
  3036. * no action is performed.
  3037. */
  3038. RD_EXPORT
  3039. void rd_kafka_event_destroy (rd_kafka_event_t *rkev);
  3040. /**
  3041. * @returns the next message from an event.
  3042. *
  3043. * Call repeatedly until it returns NULL.
  3044. *
  3045. * Event types:
  3046. * - RD_KAFKA_EVENT_FETCH (1 message)
  3047. * - RD_KAFKA_EVENT_DR (>=1 message(s))
  3048. *
  3049. * @remark The returned message(s) MUST NOT be
  3050. * freed with rd_kafka_message_destroy().
  3051. *
  3052. * @remark on_consume() interceptor may be called
  3053. * from this function prior to passing message to application.
  3054. */
  3055. RD_EXPORT
  3056. const rd_kafka_message_t *rd_kafka_event_message_next (rd_kafka_event_t *rkev);
  3057. /**
  3058. * @brief Extacts \p size message(s) from the event into the
  3059. * pre-allocated array \p rkmessages.
  3060. *
  3061. * Event types:
  3062. * - RD_KAFKA_EVENT_FETCH (1 message)
  3063. * - RD_KAFKA_EVENT_DR (>=1 message(s))
  3064. *
  3065. * @returns the number of messages extracted.
  3066. *
  3067. * @remark on_consume() interceptor may be called
  3068. * from this function prior to passing message to application.
  3069. */
  3070. RD_EXPORT
  3071. size_t rd_kafka_event_message_array (rd_kafka_event_t *rkev,
  3072. const rd_kafka_message_t **rkmessages,
  3073. size_t size);
  3074. /**
  3075. * @returns the number of remaining messages in the event.
  3076. *
  3077. * Event types:
  3078. * - RD_KAFKA_EVENT_FETCH (1 message)
  3079. * - RD_KAFKA_EVENT_DR (>=1 message(s))
  3080. */
  3081. RD_EXPORT
  3082. size_t rd_kafka_event_message_count (rd_kafka_event_t *rkev);
  3083. /**
  3084. * @returns the error code for the event.
  3085. *
  3086. * Event types:
  3087. * - all
  3088. */
  3089. RD_EXPORT
  3090. rd_kafka_resp_err_t rd_kafka_event_error (rd_kafka_event_t *rkev);
  3091. /**
  3092. * @returns the error string (if any).
  3093. * An application should check that rd_kafka_event_error() returns
  3094. * non-zero before calling this function.
  3095. *
  3096. * Event types:
  3097. * - all
  3098. */
  3099. RD_EXPORT
  3100. const char *rd_kafka_event_error_string (rd_kafka_event_t *rkev);
  3101. /**
  3102. * @returns the user opaque (if any)
  3103. *
  3104. * Event types:
  3105. * - RD_KAFKA_OFFSET_COMMIT
  3106. */
  3107. RD_EXPORT
  3108. void *rd_kafka_event_opaque (rd_kafka_event_t *rkev);
  3109. /**
  3110. * @brief Extract log message from the event.
  3111. *
  3112. * Event types:
  3113. * - RD_KAFKA_EVENT_LOG
  3114. *
  3115. * @returns 0 on success or -1 if unsupported event type.
  3116. */
  3117. RD_EXPORT
  3118. int rd_kafka_event_log (rd_kafka_event_t *rkev,
  3119. const char **fac, const char **str, int *level);
  3120. /**
  3121. * @brief Extract stats from the event.
  3122. *
  3123. * Event types:
  3124. * - RD_KAFKA_EVENT_STATS
  3125. *
  3126. * @returns stats json string.
  3127. *
  3128. * @remark the returned string will be freed automatically along with the event object
  3129. *
  3130. */
  3131. RD_EXPORT
  3132. const char *rd_kafka_event_stats (rd_kafka_event_t *rkev);
  3133. /**
  3134. * @returns the topic partition list from the event.
  3135. *
  3136. * @remark The list MUST NOT be freed with rd_kafka_topic_partition_list_destroy()
  3137. *
  3138. * Event types:
  3139. * - RD_KAFKA_EVENT_REBALANCE
  3140. * - RD_KAFKA_EVENT_OFFSET_COMMIT
  3141. */
  3142. RD_EXPORT rd_kafka_topic_partition_list_t *
  3143. rd_kafka_event_topic_partition_list (rd_kafka_event_t *rkev);
  3144. /**
  3145. * @returns a newly allocated topic_partition container, if applicable for the event type,
  3146. * else NULL.
  3147. *
  3148. * @remark The returned pointer MUST be freed with rd_kafka_topic_partition_destroy().
  3149. *
  3150. * Event types:
  3151. * RD_KAFKA_EVENT_ERROR (for partition level errors)
  3152. */
  3153. RD_EXPORT rd_kafka_topic_partition_t *
  3154. rd_kafka_event_topic_partition (rd_kafka_event_t *rkev);
  3155. /**
  3156. * @brief Poll a queue for an event for max \p timeout_ms.
  3157. *
  3158. * @returns an event, or NULL.
  3159. *
  3160. * @remark Use rd_kafka_event_destroy() to free the event.
  3161. */
  3162. RD_EXPORT
  3163. rd_kafka_event_t *rd_kafka_queue_poll (rd_kafka_queue_t *rkqu, int timeout_ms);
  3164. /**
  3165. * @brief Poll a queue for events served through callbacks for max \p timeout_ms.
  3166. *
  3167. * @returns the number of events served.
  3168. *
  3169. * @remark This API must only be used for queues with callbacks registered
  3170. * for all expected event types. E.g., not a message queue.
  3171. */
  3172. RD_EXPORT
  3173. int rd_kafka_queue_poll_callback (rd_kafka_queue_t *rkqu, int timeout_ms);
  3174. /**@}*/
  3175. /**
  3176. * @name Plugin interface
  3177. *
  3178. * @brief A plugin interface that allows external runtime-loaded libraries
  3179. * to integrate with a client instance without modifications to
  3180. * the application code.
  3181. *
  3182. * Plugins are loaded when referenced through the `plugin.library.paths`
  3183. * configuration property and operates on the \c rd_kafka_conf_t
  3184. * object prior \c rd_kafka_t instance creation.
  3185. *
  3186. * @warning Plugins require the application to link librdkafka dynamically
  3187. * and not statically. Failure to do so will lead to missing symbols
  3188. * or finding symbols in another librdkafka library than the
  3189. * application was linked with.
  3190. */
  3191. /**
  3192. * @brief Plugin's configuration initializer method called each time the
  3193. * library is referenced from configuration (even if previously loaded by
  3194. * another client instance).
  3195. *
  3196. * @remark This method MUST be implemented by plugins and have the symbol name
  3197. * \c conf_init
  3198. *
  3199. * @param conf Configuration set up to this point.
  3200. * @param plug_opaquep Plugin can set this pointer to a per-configuration
  3201. * opaque pointer.
  3202. * @param errstr String buffer of size \p errstr_size where plugin must write
  3203. * a human readable error string in the case the initializer
  3204. * fails (returns non-zero).
  3205. *
  3206. * @remark A plugin may add an on_conf_destroy() interceptor to clean up
  3207. * plugin-specific resources created in the plugin's conf_init() method.
  3208. *
  3209. * @returns RD_KAFKA_RESP_ERR_NO_ERROR on success or an error code on error.
  3210. */
  3211. typedef rd_kafka_resp_err_t
  3212. (rd_kafka_plugin_f_conf_init_t) (rd_kafka_conf_t *conf,
  3213. void **plug_opaquep,
  3214. char *errstr, size_t errstr_size);
  3215. /**@}*/
  3216. /**
  3217. * @name Interceptors
  3218. *
  3219. * @{
  3220. *
  3221. * @brief A callback interface that allows message interception for both
  3222. * producer and consumer data pipelines.
  3223. *
  3224. * Except for the on_new(), on_conf_set(), on_conf_dup() and on_conf_destroy()
  3225. * interceptors, interceptors are added to the
  3226. * newly created rd_kafka_t client instance. These interceptors MUST only
  3227. * be added from on_new() and MUST NOT be added after rd_kafka_new() returns.
  3228. *
  3229. * The on_new(), on_conf_set(), on_conf_dup() and on_conf_destroy() interceptors
  3230. * are added to the configuration object which is later passed to
  3231. * rd_kafka_new() where on_new() is called to allow addition of
  3232. * other interceptors.
  3233. *
  3234. * Each interceptor reference consists of a display name (ic_name),
  3235. * a callback function, and an application-specified opaque value that is
  3236. * passed as-is to the callback.
  3237. * The ic_name must be unique for the interceptor implementation and is used
  3238. * to reject duplicate interceptor methods.
  3239. *
  3240. * Any number of interceptors can be added and they are called in the order
  3241. * they were added, unless otherwise noted.
  3242. * The list of registered interceptor methods are referred to as
  3243. * interceptor chains.
  3244. *
  3245. * @remark Contrary to the Java client the librdkafka interceptor interface
  3246. * does not support message key and value modification.
  3247. * Message mutability is discouraged in the Java client and the
  3248. * combination of serializers and headers cover most use-cases.
  3249. *
  3250. * @remark Interceptors are NOT copied to the new configuration on
  3251. * rd_kafka_conf_dup() since it would be hard for interceptors to
  3252. * track usage of the interceptor's opaque value.
  3253. * An interceptor should rely on the plugin, which will be copied
  3254. * in rd_kafka_conf_conf_dup(), to set up the initial interceptors.
  3255. * An interceptor should implement the on_conf_dup() method
  3256. * to manually set up its internal configuration on the newly created
  3257. * configuration object that is being copied-to based on the
  3258. * interceptor-specific configuration properties.
  3259. * conf_dup() should thus be treated the same as conf_init().
  3260. *
  3261. * @remark Interceptors are keyed by the interceptor type (on_..()), the
  3262. * interceptor name (ic_name) and the interceptor method function.
  3263. * Duplicates are not allowed and the .._add_on_..() method will
  3264. * return RD_KAFKA_RESP_ERR__CONFLICT if attempting to add a duplicate
  3265. * method.
  3266. * The only exception is on_conf_destroy() which may be added multiple
  3267. * times by the same interceptor to allow proper cleanup of
  3268. * interceptor configuration state.
  3269. */
  3270. /**
  3271. * @brief on_conf_set() is called from rd_kafka_*_conf_set() in the order
  3272. * the interceptors were added.
  3273. *
  3274. * @param ic_opaque The interceptor's opaque pointer specified in ..add..().
  3275. * @param name The configuration property to set.
  3276. * @param val The configuration value to set, or NULL for reverting to default
  3277. * in which case the previous value should be freed.
  3278. * @param errstr A human readable error string in case the interceptor fails.
  3279. * @param errstr_size Maximum space (including \0) in \p errstr.
  3280. *
  3281. * @returns RD_KAFKA_CONF_RES_OK if the property was known and successfully
  3282. * handled by the interceptor, RD_KAFKA_CONF_RES_INVALID if the
  3283. * property was handled by the interceptor but the value was invalid,
  3284. * or RD_KAFKA_CONF_RES_UNKNOWN if the interceptor did not handle
  3285. * this property, in which case the property is passed on on the
  3286. * interceptor in the chain, finally ending up at the built-in
  3287. * configuration handler.
  3288. */
  3289. typedef rd_kafka_conf_res_t
  3290. (rd_kafka_interceptor_f_on_conf_set_t) (rd_kafka_conf_t *conf,
  3291. const char *name, const char *val,
  3292. char *errstr, size_t errstr_size,
  3293. void *ic_opaque);
  3294. /**
  3295. * @brief on_conf_dup() is called from rd_kafka_conf_dup() in the
  3296. * order the interceptors were added and is used to let
  3297. * an interceptor re-register its conf interecptors with a new
  3298. * opaque value.
  3299. * The on_conf_dup() method is called prior to the configuration from
  3300. * \p old_conf being copied to \p new_conf.
  3301. *
  3302. * @param ic_opaque The interceptor's opaque pointer specified in ..add..().
  3303. *
  3304. * @returns RD_KAFKA_RESP_ERR_NO_ERROR on success or an error code
  3305. * on failure (which is logged but otherwise ignored).
  3306. *
  3307. * @remark No on_conf_* interceptors are copied to the new configuration
  3308. * object on rd_kafka_conf_dup().
  3309. */
  3310. typedef rd_kafka_resp_err_t
  3311. (rd_kafka_interceptor_f_on_conf_dup_t) (rd_kafka_conf_t *new_conf,
  3312. const rd_kafka_conf_t *old_conf,
  3313. size_t filter_cnt,
  3314. const char **filter,
  3315. void *ic_opaque);
  3316. /**
  3317. * @brief on_conf_destroy() is called from rd_kafka_*_conf_destroy() in the
  3318. * order the interceptors were added.
  3319. *
  3320. * @param ic_opaque The interceptor's opaque pointer specified in ..add..().
  3321. */
  3322. typedef rd_kafka_resp_err_t
  3323. (rd_kafka_interceptor_f_on_conf_destroy_t) (void *ic_opaque);
  3324. /**
  3325. * @brief on_new() is called from rd_kafka_new() prior toreturning
  3326. * the newly created client instance to the application.
  3327. *
  3328. * @param rk The client instance.
  3329. * @param conf The client instance's final configuration.
  3330. * @param ic_opaque The interceptor's opaque pointer specified in ..add..().
  3331. * @param errstr A human readable error string in case the interceptor fails.
  3332. * @param errstr_size Maximum space (including \0) in \p errstr.
  3333. *
  3334. * @returns an error code on failure, the error is logged but otherwise ignored.
  3335. *
  3336. * @warning The \p rk client instance will not be fully set up when this
  3337. * interceptor is called and the interceptor MUST NOT call any
  3338. * other rk-specific APIs than rd_kafka_interceptor_add..().
  3339. *
  3340. */
  3341. typedef rd_kafka_resp_err_t
  3342. (rd_kafka_interceptor_f_on_new_t) (rd_kafka_t *rk, const rd_kafka_conf_t *conf,
  3343. void *ic_opaque,
  3344. char *errstr, size_t errstr_size);
  3345. /**
  3346. * @brief on_destroy() is called from rd_kafka_destroy() or (rd_kafka_new()
  3347. * if rd_kafka_new() fails during initialization).
  3348. *
  3349. * @param rk The client instance.
  3350. * @param ic_opaque The interceptor's opaque pointer specified in ..add..().
  3351. */
  3352. typedef rd_kafka_resp_err_t
  3353. (rd_kafka_interceptor_f_on_destroy_t) (rd_kafka_t *rk, void *ic_opaque);
  3354. /**
  3355. * @brief on_send() is called from rd_kafka_produce*() (et.al) prior to
  3356. * the partitioner being called.
  3357. *
  3358. * @param rk The client instance.
  3359. * @param rkmessage The message being produced. Immutable.
  3360. * @param ic_opaque The interceptor's opaque pointer specified in ..add..().
  3361. *
  3362. * @remark This interceptor is only used by producer instances.
  3363. *
  3364. * @remark The \p rkmessage object is NOT mutable and MUST NOT be modified
  3365. * by the interceptor.
  3366. *
  3367. * @remark If the partitioner fails or an unknown partition was specified,
  3368. * the on_acknowledgement() interceptor chain will be called from
  3369. * within the rd_kafka_produce*() call to maintain send-acknowledgement
  3370. * symmetry.
  3371. *
  3372. * @returns an error code on failure, the error is logged but otherwise ignored.
  3373. */
  3374. typedef rd_kafka_resp_err_t
  3375. (rd_kafka_interceptor_f_on_send_t) (rd_kafka_t *rk,
  3376. rd_kafka_message_t *rkmessage,
  3377. void *ic_opaque);
  3378. /**
  3379. * @brief on_acknowledgement() is called to inform interceptors that a message
  3380. * was succesfully delivered or permanently failed delivery.
  3381. * The interceptor chain is called from internal librdkafka background
  3382. * threads, or rd_kafka_produce*() if the partitioner failed.
  3383. *
  3384. * @param rk The client instance.
  3385. * @param rkmessage The message being produced. Immutable.
  3386. * @param ic_opaque The interceptor's opaque pointer specified in ..add..().
  3387. *
  3388. * @remark This interceptor is only used by producer instances.
  3389. *
  3390. * @remark The \p rkmessage object is NOT mutable and MUST NOT be modified
  3391. * by the interceptor.
  3392. *
  3393. * @warning The on_acknowledgement() method may be called from internal
  3394. * librdkafka threads. An on_acknowledgement() interceptor MUST NOT
  3395. * call any librdkafka API's associated with the \p rk, or perform
  3396. * any blocking or prolonged work.
  3397. *
  3398. * @returns an error code on failure, the error is logged but otherwise ignored.
  3399. */
  3400. typedef rd_kafka_resp_err_t
  3401. (rd_kafka_interceptor_f_on_acknowledgement_t) (rd_kafka_t *rk,
  3402. rd_kafka_message_t *rkmessage,
  3403. void *ic_opaque);
  3404. /**
  3405. * @brief on_consume() is called just prior to passing the message to the
  3406. * application in rd_kafka_consumer_poll(), rd_kafka_consume*(),
  3407. * the event interface, etc.
  3408. *
  3409. * @param rk The client instance.
  3410. * @param rkmessage The message being consumed. Immutable.
  3411. * @param ic_opaque The interceptor's opaque pointer specified in ..add..().
  3412. *
  3413. * @remark This interceptor is only used by consumer instances.
  3414. *
  3415. * @remark The \p rkmessage object is NOT mutable and MUST NOT be modified
  3416. * by the interceptor.
  3417. *
  3418. * @returns an error code on failure, the error is logged but otherwise ignored.
  3419. */
  3420. typedef rd_kafka_resp_err_t
  3421. (rd_kafka_interceptor_f_on_consume_t) (rd_kafka_t *rk,
  3422. rd_kafka_message_t *rkmessage,
  3423. void *ic_opaque);
  3424. /**
  3425. * @brief on_commit() is called on completed or failed offset commit.
  3426. * It is called from internal librdkafka threads.
  3427. *
  3428. * @param rk The client instance.
  3429. * @param offsets List of topic+partition+offset+error that were committed.
  3430. * The error message of each partition should be checked for
  3431. * error.
  3432. * @param ic_opaque The interceptor's opaque pointer specified in ..add..().
  3433. *
  3434. * @remark This interceptor is only used by consumer instances.
  3435. *
  3436. * @warning The on_commit() interceptor is called from internal
  3437. * librdkafka threads. An on_commit() interceptor MUST NOT
  3438. * call any librdkafka API's associated with the \p rk, or perform
  3439. * any blocking or prolonged work.
  3440. *
  3441. *
  3442. * @returns an error code on failure, the error is logged but otherwise ignored.
  3443. */
  3444. typedef rd_kafka_resp_err_t
  3445. (rd_kafka_interceptor_f_on_commit_t) (
  3446. rd_kafka_t *rk,
  3447. const rd_kafka_topic_partition_list_t *offsets,
  3448. rd_kafka_resp_err_t err, void *ic_opaque);
  3449. /**
  3450. * @brief on_request_sent() is called when a request has been fully written
  3451. * to a broker TCP connections socket.
  3452. *
  3453. * @param rk The client instance.
  3454. * @param sockfd Socket file descriptor.
  3455. * @param brokername Broker request is being sent to.
  3456. * @param brokerid Broker request is being sent to.
  3457. * @param ApiKey Kafka protocol request type.
  3458. * @param ApiVersion Kafka protocol request type version.
  3459. * @param Corrid Kafka protocol request correlation id.
  3460. * @param size Size of request.
  3461. * @param ic_opaque The interceptor's opaque pointer specified in ..add..().
  3462. *
  3463. * @warning The on_request_sent() interceptor is called from internal
  3464. * librdkafka broker threads. An on_request_sent() interceptor MUST NOT
  3465. * call any librdkafka API's associated with the \p rk, or perform
  3466. * any blocking or prolonged work.
  3467. *
  3468. * @returns an error code on failure, the error is logged but otherwise ignored.
  3469. */
  3470. typedef rd_kafka_resp_err_t
  3471. (rd_kafka_interceptor_f_on_request_sent_t) (
  3472. rd_kafka_t *rk,
  3473. int sockfd,
  3474. const char *brokername,
  3475. int32_t brokerid,
  3476. int16_t ApiKey,
  3477. int16_t ApiVersion,
  3478. int32_t CorrId,
  3479. size_t size,
  3480. void *ic_opaque);
  3481. /**
  3482. * @brief Append an on_conf_set() interceptor.
  3483. *
  3484. * @param conf Configuration object.
  3485. * @param ic_name Interceptor name, used in logging.
  3486. * @param on_conf_set Function pointer.
  3487. * @param ic_opaque Opaque value that will be passed to the function.
  3488. *
  3489. * @returns RD_KAFKA_RESP_ERR_NO_ERROR on success or RD_KAFKA_RESP_ERR__CONFLICT
  3490. * if an existing intercepted with the same \p ic_name and function
  3491. * has already been added to \p conf.
  3492. */
  3493. RD_EXPORT rd_kafka_resp_err_t
  3494. rd_kafka_conf_interceptor_add_on_conf_set (
  3495. rd_kafka_conf_t *conf, const char *ic_name,
  3496. rd_kafka_interceptor_f_on_conf_set_t *on_conf_set,
  3497. void *ic_opaque);
  3498. /**
  3499. * @brief Append an on_conf_dup() interceptor.
  3500. *
  3501. * @param conf Configuration object.
  3502. * @param ic_name Interceptor name, used in logging.
  3503. * @param on_conf_dup Function pointer.
  3504. * @param ic_opaque Opaque value that will be passed to the function.
  3505. *
  3506. * @returns RD_KAFKA_RESP_ERR_NO_ERROR on success or RD_KAFKA_RESP_ERR__CONFLICT
  3507. * if an existing intercepted with the same \p ic_name and function
  3508. * has already been added to \p conf.
  3509. */
  3510. RD_EXPORT rd_kafka_resp_err_t
  3511. rd_kafka_conf_interceptor_add_on_conf_dup (
  3512. rd_kafka_conf_t *conf, const char *ic_name,
  3513. rd_kafka_interceptor_f_on_conf_dup_t *on_conf_dup,
  3514. void *ic_opaque);
  3515. /**
  3516. * @brief Append an on_conf_destroy() interceptor.
  3517. *
  3518. * @param conf Configuration object.
  3519. * @param ic_name Interceptor name, used in logging.
  3520. * @param on_conf_destroy Function pointer.
  3521. * @param ic_opaque Opaque value that will be passed to the function.
  3522. *
  3523. * @returns RD_KAFKA_RESP_ERR_NO_ERROR
  3524. *
  3525. * @remark Multiple on_conf_destroy() interceptors are allowed to be added
  3526. * to the same configuration object.
  3527. */
  3528. RD_EXPORT rd_kafka_resp_err_t
  3529. rd_kafka_conf_interceptor_add_on_conf_destroy (
  3530. rd_kafka_conf_t *conf, const char *ic_name,
  3531. rd_kafka_interceptor_f_on_conf_destroy_t *on_conf_destroy,
  3532. void *ic_opaque);
  3533. /**
  3534. * @brief Append an on_new() interceptor.
  3535. *
  3536. * @param conf Configuration object.
  3537. * @param ic_name Interceptor name, used in logging.
  3538. * @param on_send Function pointer.
  3539. * @param ic_opaque Opaque value that will be passed to the function.
  3540. *
  3541. * @remark Since the on_new() interceptor is added to the configuration object
  3542. * it may be copied by rd_kafka_conf_dup().
  3543. * An interceptor implementation must thus be able to handle
  3544. * the same interceptor,ic_opaque tuple to be used by multiple
  3545. * client instances.
  3546. *
  3547. * @remark An interceptor plugin should check the return value to make sure it
  3548. * has not already been added.
  3549. *
  3550. * @returns RD_KAFKA_RESP_ERR_NO_ERROR on success or RD_KAFKA_RESP_ERR__CONFLICT
  3551. * if an existing intercepted with the same \p ic_name and function
  3552. * has already been added to \p conf.
  3553. */
  3554. RD_EXPORT rd_kafka_resp_err_t
  3555. rd_kafka_conf_interceptor_add_on_new (
  3556. rd_kafka_conf_t *conf, const char *ic_name,
  3557. rd_kafka_interceptor_f_on_new_t *on_new,
  3558. void *ic_opaque);
  3559. /**
  3560. * @brief Append an on_destroy() interceptor.
  3561. *
  3562. * @param rk Client instance.
  3563. * @param ic_name Interceptor name, used in logging.
  3564. * @param on_destroy Function pointer.
  3565. * @param ic_opaque Opaque value that will be passed to the function.
  3566. *
  3567. * @returns RD_KAFKA_RESP_ERR_NO_ERROR on success or RD_KAFKA_RESP_ERR__CONFLICT
  3568. * if an existing intercepted with the same \p ic_name and function
  3569. * has already been added to \p conf.
  3570. */
  3571. RD_EXPORT rd_kafka_resp_err_t
  3572. rd_kafka_interceptor_add_on_destroy (
  3573. rd_kafka_t *rk, const char *ic_name,
  3574. rd_kafka_interceptor_f_on_destroy_t *on_destroy,
  3575. void *ic_opaque);
  3576. /**
  3577. * @brief Append an on_send() interceptor.
  3578. *
  3579. * @param rk Client instance.
  3580. * @param ic_name Interceptor name, used in logging.
  3581. * @param on_send Function pointer.
  3582. * @param ic_opaque Opaque value that will be passed to the function.
  3583. *
  3584. * @returns RD_KAFKA_RESP_ERR_NO_ERROR on success or RD_KAFKA_RESP_ERR__CONFLICT
  3585. * if an existing intercepted with the same \p ic_name and function
  3586. * has already been added to \p conf.
  3587. */
  3588. RD_EXPORT rd_kafka_resp_err_t
  3589. rd_kafka_interceptor_add_on_send (
  3590. rd_kafka_t *rk, const char *ic_name,
  3591. rd_kafka_interceptor_f_on_send_t *on_send,
  3592. void *ic_opaque);
  3593. /**
  3594. * @brief Append an on_acknowledgement() interceptor.
  3595. *
  3596. * @param rk Client instance.
  3597. * @param ic_name Interceptor name, used in logging.
  3598. * @param on_acknowledgement Function pointer.
  3599. * @param ic_opaque Opaque value that will be passed to the function.
  3600. *
  3601. * @returns RD_KAFKA_RESP_ERR_NO_ERROR on success or RD_KAFKA_RESP_ERR__CONFLICT
  3602. * if an existing intercepted with the same \p ic_name and function
  3603. * has already been added to \p conf.
  3604. */
  3605. RD_EXPORT rd_kafka_resp_err_t
  3606. rd_kafka_interceptor_add_on_acknowledgement (
  3607. rd_kafka_t *rk, const char *ic_name,
  3608. rd_kafka_interceptor_f_on_acknowledgement_t *on_acknowledgement,
  3609. void *ic_opaque);
  3610. /**
  3611. * @brief Append an on_consume() interceptor.
  3612. *
  3613. * @param rk Client instance.
  3614. * @param ic_name Interceptor name, used in logging.
  3615. * @param on_consume Function pointer.
  3616. * @param ic_opaque Opaque value that will be passed to the function.
  3617. *
  3618. * @returns RD_KAFKA_RESP_ERR_NO_ERROR on success or RD_KAFKA_RESP_ERR__CONFLICT
  3619. * if an existing intercepted with the same \p ic_name and function
  3620. * has already been added to \p conf.
  3621. */
  3622. RD_EXPORT rd_kafka_resp_err_t
  3623. rd_kafka_interceptor_add_on_consume (
  3624. rd_kafka_t *rk, const char *ic_name,
  3625. rd_kafka_interceptor_f_on_consume_t *on_consume,
  3626. void *ic_opaque);
  3627. /**
  3628. * @brief Append an on_commit() interceptor.
  3629. *
  3630. * @param rk Client instance.
  3631. * @param ic_name Interceptor name, used in logging.
  3632. * @param on_commit() Function pointer.
  3633. * @param ic_opaque Opaque value that will be passed to the function.
  3634. *
  3635. * @returns RD_KAFKA_RESP_ERR_NO_ERROR on success or RD_KAFKA_RESP_ERR__CONFLICT
  3636. * if an existing intercepted with the same \p ic_name and function
  3637. * has already been added to \p conf.
  3638. */
  3639. RD_EXPORT rd_kafka_resp_err_t
  3640. rd_kafka_interceptor_add_on_commit (
  3641. rd_kafka_t *rk, const char *ic_name,
  3642. rd_kafka_interceptor_f_on_commit_t *on_commit,
  3643. void *ic_opaque);
  3644. /**
  3645. * @brief Append an on_request_sent() interceptor.
  3646. *
  3647. * @param rk Client instance.
  3648. * @param ic_name Interceptor name, used in logging.
  3649. * @param on_request_sent() Function pointer.
  3650. * @param ic_opaque Opaque value that will be passed to the function.
  3651. *
  3652. * @returns RD_KAFKA_RESP_ERR_NO_ERROR on success or RD_KAFKA_RESP_ERR__CONFLICT
  3653. * if an existing intercepted with the same \p ic_name and function
  3654. * has already been added to \p conf.
  3655. */
  3656. RD_EXPORT rd_kafka_resp_err_t
  3657. rd_kafka_interceptor_add_on_request_sent (
  3658. rd_kafka_t *rk, const char *ic_name,
  3659. rd_kafka_interceptor_f_on_request_sent_t *on_request_sent,
  3660. void *ic_opaque);
  3661. /**@}*/
  3662. #ifdef __cplusplus
  3663. }
  3664. #endif
  3665. #endif /* _RDKAFKA_H_ */