You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

890 lines
25 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
la_mojo: fix memory leaks and heap corruption Continuous leaks: - protocolParser: on package-pool overflow the oldest package was removed but never freed while the newest (still pooled) one was freed. Every packet a handler does not consume (e.g. other sensors on a shared bus) leaked once the pool was full. Free the removed package, free pooled packages in the destructor and getPackage(), use memmove for the overlapping buffer shifts. - SQLite_Connector::Query: loop only while sqlite3_step() returns SQLITE_ROW. Looping until SQLITE_DONE spun forever allocating rows on SQLITE_BUSY/ERROR. Set a busy timeout, close handles after a failed open, fix escapeBinary() writing into uninitialised buffers. - basicThread/basicDualThread: threads that ended by themselves were never joined, leaking their stacks on every stream drop/restart. Always join once (detach when called from the thread itself); check pthread_create result correctly. - curlRequest: free the header list; initialise m_pPostData and the content type; curlRequestsManager deletes requests it cannot queue. - kernelModuleModemManager: free the phonebook ID list on every reload. - deviceNodeFactory: do not append the same pending node every cycle. - streamHandler: free frames left in the encoding queue on destruction. Heap corruption: - kernelModuleFactory: module that failed to start was deleted twice. - mojoRemoteClient: basicRing::push() returns an ID (may be 0), not a bool; compare with -1. Fix packetExtractor and destructor leaks. - utilizeBasicEvent: payloads are malloc'ed, release with free(). - videoAVLIBSource: avoid sws context double free, NULL check order. - trim(): memmove for overlapping copy. Smaller leaks: dropSession duplicate query, LRF upload data, report backupper / fly hunter settings, Kafka consumer handle, BVMS uniq ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
1 day ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
la_mojo: fix memory leaks and heap corruption Continuous leaks: - protocolParser: on package-pool overflow the oldest package was removed but never freed while the newest (still pooled) one was freed. Every packet a handler does not consume (e.g. other sensors on a shared bus) leaked once the pool was full. Free the removed package, free pooled packages in the destructor and getPackage(), use memmove for the overlapping buffer shifts. - SQLite_Connector::Query: loop only while sqlite3_step() returns SQLITE_ROW. Looping until SQLITE_DONE spun forever allocating rows on SQLITE_BUSY/ERROR. Set a busy timeout, close handles after a failed open, fix escapeBinary() writing into uninitialised buffers. - basicThread/basicDualThread: threads that ended by themselves were never joined, leaking their stacks on every stream drop/restart. Always join once (detach when called from the thread itself); check pthread_create result correctly. - curlRequest: free the header list; initialise m_pPostData and the content type; curlRequestsManager deletes requests it cannot queue. - kernelModuleModemManager: free the phonebook ID list on every reload. - deviceNodeFactory: do not append the same pending node every cycle. - streamHandler: free frames left in the encoding queue on destruction. Heap corruption: - kernelModuleFactory: module that failed to start was deleted twice. - mojoRemoteClient: basicRing::push() returns an ID (may be 0), not a bool; compare with -1. Fix packetExtractor and destructor leaks. - utilizeBasicEvent: payloads are malloc'ed, release with free(). - videoAVLIBSource: avoid sws context double free, NULL check order. - trim(): memmove for overlapping copy. Smaller leaks: dropSession duplicate query, LRF upload data, report backupper / fly hunter settings, Kafka consumer handle, BVMS uniq ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
1 day ago
​
la_mojo: fix memory leaks and heap corruption Continuous leaks: - protocolParser: on package-pool overflow the oldest package was removed but never freed while the newest (still pooled) one was freed. Every packet a handler does not consume (e.g. other sensors on a shared bus) leaked once the pool was full. Free the removed package, free pooled packages in the destructor and getPackage(), use memmove for the overlapping buffer shifts. - SQLite_Connector::Query: loop only while sqlite3_step() returns SQLITE_ROW. Looping until SQLITE_DONE spun forever allocating rows on SQLITE_BUSY/ERROR. Set a busy timeout, close handles after a failed open, fix escapeBinary() writing into uninitialised buffers. - basicThread/basicDualThread: threads that ended by themselves were never joined, leaking their stacks on every stream drop/restart. Always join once (detach when called from the thread itself); check pthread_create result correctly. - curlRequest: free the header list; initialise m_pPostData and the content type; curlRequestsManager deletes requests it cannot queue. - kernelModuleModemManager: free the phonebook ID list on every reload. - deviceNodeFactory: do not append the same pending node every cycle. - streamHandler: free frames left in the encoding queue on destruction. Heap corruption: - kernelModuleFactory: module that failed to start was deleted twice. - mojoRemoteClient: basicRing::push() returns an ID (may be 0), not a bool; compare with -1. Fix packetExtractor and destructor leaks. - utilizeBasicEvent: payloads are malloc'ed, release with free(). - videoAVLIBSource: avoid sws context double free, NULL check order. - trim(): memmove for overlapping copy. Smaller leaks: dropSession duplicate query, LRF upload data, report backupper / fly hunter settings, Kafka consumer handle, BVMS uniq ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
1 day ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
la_mojo: fix memory leaks and heap corruption Continuous leaks: - protocolParser: on package-pool overflow the oldest package was removed but never freed while the newest (still pooled) one was freed. Every packet a handler does not consume (e.g. other sensors on a shared bus) leaked once the pool was full. Free the removed package, free pooled packages in the destructor and getPackage(), use memmove for the overlapping buffer shifts. - SQLite_Connector::Query: loop only while sqlite3_step() returns SQLITE_ROW. Looping until SQLITE_DONE spun forever allocating rows on SQLITE_BUSY/ERROR. Set a busy timeout, close handles after a failed open, fix escapeBinary() writing into uninitialised buffers. - basicThread/basicDualThread: threads that ended by themselves were never joined, leaking their stacks on every stream drop/restart. Always join once (detach when called from the thread itself); check pthread_create result correctly. - curlRequest: free the header list; initialise m_pPostData and the content type; curlRequestsManager deletes requests it cannot queue. - kernelModuleModemManager: free the phonebook ID list on every reload. - deviceNodeFactory: do not append the same pending node every cycle. - streamHandler: free frames left in the encoding queue on destruction. Heap corruption: - kernelModuleFactory: module that failed to start was deleted twice. - mojoRemoteClient: basicRing::push() returns an ID (may be 0), not a bool; compare with -1. Fix packetExtractor and destructor leaks. - utilizeBasicEvent: payloads are malloc'ed, release with free(). - videoAVLIBSource: avoid sws context double free, NULL check order. - trim(): memmove for overlapping copy. Smaller leaks: dropSession duplicate query, LRF upload data, report backupper / fly hunter settings, Kafka consumer handle, BVMS uniq ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
1 day ago
​
​
​
​
​
​
​
​
​
​
​
​
​
la_mojo: fix memory leaks and heap corruption Continuous leaks: - protocolParser: on package-pool overflow the oldest package was removed but never freed while the newest (still pooled) one was freed. Every packet a handler does not consume (e.g. other sensors on a shared bus) leaked once the pool was full. Free the removed package, free pooled packages in the destructor and getPackage(), use memmove for the overlapping buffer shifts. - SQLite_Connector::Query: loop only while sqlite3_step() returns SQLITE_ROW. Looping until SQLITE_DONE spun forever allocating rows on SQLITE_BUSY/ERROR. Set a busy timeout, close handles after a failed open, fix escapeBinary() writing into uninitialised buffers. - basicThread/basicDualThread: threads that ended by themselves were never joined, leaking their stacks on every stream drop/restart. Always join once (detach when called from the thread itself); check pthread_create result correctly. - curlRequest: free the header list; initialise m_pPostData and the content type; curlRequestsManager deletes requests it cannot queue. - kernelModuleModemManager: free the phonebook ID list on every reload. - deviceNodeFactory: do not append the same pending node every cycle. - streamHandler: free frames left in the encoding queue on destruction. Heap corruption: - kernelModuleFactory: module that failed to start was deleted twice. - mojoRemoteClient: basicRing::push() returns an ID (may be 0), not a bool; compare with -1. Fix packetExtractor and destructor leaks. - utilizeBasicEvent: payloads are malloc'ed, release with free(). - videoAVLIBSource: avoid sws context double free, NULL check order. - trim(): memmove for overlapping copy. Smaller leaks: dropSession duplicate query, LRF upload data, report backupper / fly hunter settings, Kafka consumer handle, BVMS uniq ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
1 day ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "protocolKAFKA.h"
  2. #include "../../alg/generic/md5.h"
  3. #include "../json/json_tool.h"
  4. #include <json/reader.h>
  5. #include <json/value.h>
  6. #include <json/writer.h>
  7. #include <strings.h>
  8. // https://il.iherb.com/pr/KAL-Blood-Sugar-Defense-60-Tablets/70138
  9. #define LOG(X) m_pLog->Log("KAFKA", this, X)
  10. #define LOGS(X) basicLogCollection::getInstance()->Log("KAFKA_S", NULL, X)
  11. #define LOG_ERROR(X) m_pLog->Log("KAFKA", this, _LOG_ERROR, X)
  12. /*
  13. CSTR protocolKAFKA::buildURL( CSTR templ, int dim, CSTR devID ){
  14. CSTR RetVal;
  15. RetVal = (CSTR) malloc( 256 );
  16. if (RetVal != NULL) {
  17. if (m_bUseSSL) {
  18. sprintf(RetVal, "https://%s:%d%s", m_pServerIP, m_nServerPort, m_pAccessURL);
  19. } else {
  20. sprintf(RetVal, "http://%s:%d%s", m_pServerIP, m_nServerPort, m_pAccessURL);
  21. };
  22. };
  23. return RetVal;
  24. };
  25. */
  26. /* Default Constructor */
  27. /*
  28. protocolKAFKA::protocolKAFKA( config_setting_t *Settings ){
  29. m_pLog = basicLogCollection::getInstance();
  30. m_pSettings = basicSettingsProvider::getInstance()->getSubNode(Settings, "INFOSTRESS_CONNECTION");
  31. n_pProducer = NULL;
  32. n_pProducerBrokerSTR = (CSTR)malloc(CLOG);
  33. if( n_pProducerBrokerSTR == NULL ) return;
  34. memset( n_pProducerBrokerSTR, 0 , CLOG);
  35. n_pProducerTopicSTR= (CSTR)malloc(CLOG);
  36. if( n_pProducerTopicSTR == NULL ) return;
  37. memset( n_pProducerTopicSTR, 0 , CLOG);
  38. n_pProducerTopic = NULL;
  39. m_pScannerName = (CSTR)malloc(OS_SCANNER_NAME_SIZE);
  40. if( m_pScannerName == NULL ) return;
  41. memset( m_pScannerName, 0 , OS_SCANNER_NAME_SIZE);
  42. m_pServerIP = (CSTR)malloc(OS_CEP_ADDRESS_SIZE);
  43. if( m_pServerIP == NULL ) return;
  44. memset( m_pServerIP, 0 , OS_CEP_ADDRESS_SIZE);
  45. m_pAccessURL = (CSTR)malloc(CTEXT);
  46. if (m_pAccessURL == NULL) return;
  47. memset(m_pAccessURL, 0, CTEXT);
  48. m_bCurrentStatus = false;
  49. m_bMitigationStatus = false;
  50. m_bEnabled = false;
  51. m_bEnableStatus = false;
  52. if( m_pSettings != NULL ){
  53. int intVar;
  54. double floatVar;
  55. config_setting_t *pSetting;
  56. if (!config_setting_lookup_float(m_pSettings, "LOCATION_LON", &floatVar)) {
  57. m_fLon = floatVar = 35.0938962;
  58. pSetting = config_setting_add(m_pSettings, "LOCATION_LON", CONFIG_TYPE_FLOAT);
  59. config_setting_set_float(pSetting, floatVar);
  60. basicSettingsProvider::getInstance()->compromise();
  61. } else {
  62. m_fLon = floatVar;
  63. };
  64. if (!config_setting_lookup_float(m_pSettings, "LOCATION_LAT", &floatVar)) {
  65. m_fLat = floatVar = 32.904208;
  66. pSetting = config_setting_add(m_pSettings, "LOCATION_LAT", CONFIG_TYPE_FLOAT);
  67. config_setting_set_float(pSetting, floatVar);
  68. basicSettingsProvider::getInstance()->compromise();
  69. } else {
  70. m_fLat = floatVar;
  71. };
  72. if (!config_setting_lookup_bool(m_pSettings, "USE_SSL", &intVar)) {
  73. intVar = m_bUseSSL = false;
  74. LOG("SSL DISABLED[default]");
  75. pSetting = config_setting_add(m_pSettings, "USE_SSL", CONFIG_TYPE_BOOL);
  76. config_setting_set_bool(pSetting, intVar);
  77. basicSettingsProvider::getInstance()->compromise();
  78. } else {
  79. m_bUseSSL = (bool)intVar;
  80. };
  81. if (!config_setting_lookup_bool(m_pSettings, "ENABLE_STATUS_REPORT", &intVar)) {
  82. intVar = m_bEnableStatus = false;
  83. LOG("Status Report DISABLED[default]");
  84. pSetting = config_setting_add(m_pSettings, "ENABLE_STATUS_REPORT", CONFIG_TYPE_BOOL);
  85. config_setting_set_bool(pSetting, intVar);
  86. basicSettingsProvider::getInstance()->compromise();
  87. } else {
  88. m_bEnableStatus = (bool)intVar;
  89. };
  90. if (!config_setting_lookup_string(m_pSettings, "SCANNER_NAME", (const char**)&m_pScannerName)) {
  91. strncpy(m_pScannerName, "LRF_2D_001", 64);
  92. LOG(m_pScannerName);
  93. pSetting = config_setting_add(m_pSettings, "SCANNER_NAME", CONFIG_TYPE_STRING);
  94. config_setting_set_string(pSetting, m_pScannerName);
  95. basicSettingsProvider::getInstance()->compromise();
  96. };
  97. if (!config_setting_lookup_int(m_pSettings, "SCANNER_DIMENTIONS", &m_nScannerDimentions)) {
  98. m_nScannerDimentions = 2;
  99. pSetting = config_setting_add(m_pSettings, "SCANNER_DIMENTIONS", CONFIG_TYPE_INT);
  100. config_setting_set_int(pSetting, m_nScannerDimentions);
  101. basicSettingsProvider::getInstance()->compromise();
  102. };
  103. if (!config_setting_lookup_string(m_pSettings, "KAFKA_BROKER_IP", (const char**)&m_pServerIP)) {
  104. strncpy(m_pServerIP, "192.168.200.204", 16);
  105. LOG(m_pServerIP);
  106. pSetting = config_setting_add(m_pSettings, "KAFKA_BROKER_IP", CONFIG_TYPE_STRING);
  107. config_setting_set_string(pSetting, m_pServerIP);
  108. basicSettingsProvider::getInstance()->compromise();
  109. };
  110. LOG(m_pServerIP);
  111. if (!config_setting_lookup_int(m_pSettings, "KAFKA_BROKER_PORT", &m_nServerPort)) {
  112. m_nServerPort = 80;
  113. pSetting = config_setting_add(m_pSettings, "KAFKA_BROKER_PORT", CONFIG_TYPE_INT);
  114. config_setting_set_int(pSetting, m_nServerPort);
  115. basicSettingsProvider::getInstance()->compromise();
  116. };
  117. sprintf( n_pProducerBrokerSTR, "%s:%d", m_pServerIP, m_nServerPort );
  118. LOG( n_pProducerBrokerSTR );
  119. if (!config_setting_lookup_string(m_pSettings, "KAFKA_TOPIC", (const char**)&n_pProducerTopicSTR)) {
  120. strncpy( n_pProducerTopicSTR, DFSL_INFOSTRESS_DEFAULT_KAFKA_TOPIC, CTEXT );
  121. pSetting = config_setting_add(m_pSettings, "KAFKA_TOPIC", CONFIG_TYPE_STRING);
  122. config_setting_set_string(pSetting, n_pProducerTopicSTR);
  123. basicSettingsProvider::getInstance()->compromise();
  124. };
  125. LOG( n_pProducerTopicSTR );
  126. basicSettingsProvider::getInstance()->validate();
  127. };
  128. }
  129. ;*/
  130. protocolKAFKA::protocolKAFKA(KAFKA_SETTINGS * Settings)
  131. {
  132. m_pLog = basicLogCollection::getInstance();
  133. n_pProducer = NULL;
  134. m_pConsumer = NULL;
  135. // m_pServerIP = NULL;
  136. m_pSettings = Settings;
  137. // memset( m_pKafkaBrokerSTR, 0 , sizeof( m_pKafkaBrokerSTR ));
  138. if (Settings != NULL)
  139. {
  140. // m_pServerIP = (CSTR)malloc(OS_CEP_ADDRESS_SIZE);
  141. // if( m_pServerIP == NULL ) return;
  142. // memset( m_pServerIP, 0 , OS_CEP_ADDRESS_SIZE);
  143. // strncpy( m_pServerIP, Settings->brocker_addr, OS_CEP_ADDRESS_SIZE );
  144. // m_nServerPort = Settings->brocker_port;
  145. // sprintf( m_pKafkaBrokerSTR, "%s:%d", m_pServerIP, m_nServerPort );
  146. };
  147. }
  148. // protocolKAFKA::protocolKAFKA( CSTR ServerAddress, uint16_t Port ){
  149. // m_pLog = basicLogCollection::getInstance();
  150. // n_pProducer = NULL;
  151. // m_pServerIP = NULL;
  152. // if( ServerAddress == 0 || Port == 0 ) return;
  153. // m_pServerIP = (CSTR)malloc(OS_CEP_ADDRESS_SIZE);
  154. // if( m_pServerIP == NULL ) return;
  155. // memset( m_pServerIP, 0 , OS_CEP_ADDRESS_SIZE);
  156. // memset( m_pKafkaBrokerSTR, 0 , sizeof( m_pKafkaBrokerSTR ));
  157. // strncpy( m_pServerIP, ServerAddress, OS_CEP_ADDRESS_SIZE );
  158. // m_nServerPort = Port;
  159. // sprintf( m_pKafkaBrokerSTR, "%s:%d", m_pServerIP, m_nServerPort );
  160. // };
  161. /**
  162. * @brief Message delivery report callback.
  163. *
  164. * This callback is called exactly once per message, indicating if
  165. * the message was succesfully delivered
  166. * (rkmessage->err == RD_KAFKA_RESP_ERR_NO_ERROR) or permanently
  167. * failed delivery (rkmessage->err != RD_KAFKA_RESP_ERR_NO_ERROR).
  168. *
  169. * The callback is triggered from rd_kafka_poll() and executes on
  170. * the application's thread.
  171. */
  172. /*
  173. static void dr_msg_cb( rd_kafka_t *rk, const rd_kafka_message_t *rkmessage, void *opaque ){
  174. if (rkmessage->err)
  175. fprintf(stderr, "%% Message delivery failed: %s\n",
  176. rd_kafka_err2str(rkmessage->err));
  177. else
  178. fprintf(stderr,
  179. "%% Message delivered (%zd bytes, "
  180. "partition %"PRId32")\n",
  181. rkmessage->len, rkmessage->partition);
  182. // The rkmessage is destroyed automatically by librdkafka
  183. };
  184. */
  185. protocolKAFKA::~protocolKAFKA()
  186. {
  187. // m_bEnabled = false;
  188. if (n_pProducer != NULL)
  189. {
  190. /* Wait for final messages to be delivered or fail.
  191. * rd_kafka_flush() is an abstraction over rd_kafka_poll() which
  192. * waits for all messages to be delivered. */
  193. LOG("Flushing final messages..");
  194. n_pProducer->flush(3000 /* wait for max 3 seconds */);
  195. /* If the output queue is still not empty there is an issue
  196. * with producing messages to the clusters. */
  197. if (n_pProducer->outq_len() > 0)
  198. {
  199. LOG_ERROR("Some messages are not delivered!");
  200. }
  201. delete n_pProducer;
  202. n_pProducer = NULL;
  203. // if( n_pProducerTopic!= NULL ) delete n_pProducerTopic;
  204. };
  205. // The consumer handle (with its librdkafka threads and buffers) was never released
  206. if (m_pConsumer != NULL)
  207. {
  208. delete m_pConsumer;
  209. m_pConsumer = NULL;
  210. };
  211. // if( m_pScannerName != NULL ) free(m_pScannerName);
  212. // if( m_pServerIP != NULL ) free(m_pServerIP);
  213. // if( m_pAccessURL != NULL ) free(m_pAccessURL);
  214. }
  215. // https://github.com/edenhill/librdkafka/blob/master/examples/producer.c
  216. // https://github.com/edenhill/librdkafka/blob/master/examples/producer.cpp
  217. void protocolKAFKA::dr_cb(RdKafka::Message & message)
  218. {
  219. /* If message.err() is non-zero the message delivery failed permanently
  220. * for the message. */
  221. char tBuffer[CTEXT];
  222. if (message.err())
  223. {
  224. sprintf(tBuffer, "Message delivery failed: %s", message.errstr().c_str());
  225. LOG_ERROR(tBuffer);
  226. }
  227. #ifdef DEBUG_KAFKA
  228. else
  229. {
  230. sprintf(tBuffer, "Message delivered to topic: %s [%d] at offset %ld", message.topic_name().c_str(), message.partition(), message.offset());
  231. LOG(tBuffer);
  232. }
  233. #endif
  234. ;
  235. }
  236. bool protocolKAFKA::init()
  237. {
  238. RdKafka::Conf * tGlobalConf;
  239. char zBuffer[CTEXT];
  240. std::string tBuffer;
  241. std::string tValue;
  242. if (m_pSettings == NULL)
  243. {
  244. return false;
  245. }
  246. tValue.reserve(256);
  247. #ifdef DEBUG_KAFKA
  248. LOG("INIT Begin");
  249. #endif
  250. tGlobalConf = RdKafka::Conf::create(RdKafka::Conf::CONF_GLOBAL);
  251. if (tGlobalConf == NULL)
  252. {
  253. LOG_ERROR("Eror Creating Producer Conf!");
  254. return false;
  255. };
  256. // ToDo: Checking in case of SSL -> if library is build with SSL support!!
  257. #ifdef DEBUG_KAFKA
  258. LOG("RdKafka::Conf::CONF_GLOBAL Created");
  259. std::string features;
  260. tGlobalConf->get("builtin.features", features);
  261. sprintf(zBuffer, "librdkafka version %s (0x%08x, builtin.features \"%s\")", RdKafka::version_str().c_str(), RdKafka::version(), features.c_str());
  262. LOG(zBuffer);
  263. #endif
  264. if (strlen(m_pSettings->brocker_addr) == 0)
  265. {
  266. LOG_ERROR("No Kafka Brokers are defined!");
  267. delete(tGlobalConf);
  268. return false;
  269. };
  270. sprintf((char *) tValue.c_str(), "%s:%d", m_pSettings->brocker_addr, m_pSettings->brocker_port);
  271. if (tGlobalConf->set("bootstrap.servers", tValue, tBuffer) != RdKafka::Conf::CONF_OK)
  272. {
  273. LOG_ERROR(tBuffer.c_str());
  274. delete(tGlobalConf);
  275. return false;
  276. #ifdef DEBUG_KAFKA
  277. }
  278. else
  279. {
  280. LOG("bootstrap.servers is set");
  281. #endif
  282. };
  283. if (tGlobalConf->set("metadata.broker.list", tValue, tBuffer) != RdKafka::Conf::CONF_OK)
  284. {
  285. LOG_ERROR(tBuffer.c_str());
  286. delete(tGlobalConf);
  287. return false;
  288. #ifdef DEBUG_KAFKA
  289. }
  290. else
  291. {
  292. LOG(tValue.c_str());
  293. LOG("metadata.broker.list is SET");
  294. #endif
  295. };
  296. if (m_pSettings->use_ssl)
  297. {
  298. LOG("USE SSL!");
  299. if (m_pSettings->auth_by_cred)
  300. {
  301. sprintf((char *) tValue.c_str(), "SASL_SSL");
  302. if (tGlobalConf->set("security.protocol", tValue, tBuffer) != RdKafka::Conf::CONF_OK)
  303. {
  304. LOG_ERROR(tBuffer.c_str());
  305. delete(tGlobalConf);
  306. return false;
  307. #ifdef DEBUG_KAFKA
  308. }
  309. else
  310. {
  311. LOG("SEC Proto is SASL_SSL");
  312. #endif
  313. };
  314. sprintf((char *) tValue.c_str(), "%s", m_pSettings->cred_username);
  315. if (tGlobalConf->set("sasl.username", tValue, tBuffer) != RdKafka::Conf::CONF_OK)
  316. {
  317. LOG_ERROR(tBuffer.c_str());
  318. delete(tGlobalConf);
  319. return false;
  320. #ifdef DEBUG_KAFKA
  321. }
  322. else
  323. {
  324. LOG("SASL username is SET");
  325. #endif
  326. };
  327. sprintf((char *) tValue.c_str(), "%s", m_pSettings->cred_password);
  328. if (tGlobalConf->set("sasl.password", tValue, tBuffer) != RdKafka::Conf::CONF_OK)
  329. {
  330. LOG_ERROR(tBuffer.c_str());
  331. delete(tGlobalConf);
  332. return false;
  333. #ifdef DEBUG_KAFKA
  334. }
  335. else
  336. {
  337. LOG("SASL password is SET");
  338. #endif
  339. };
  340. }
  341. else
  342. {
  343. sprintf((char *) tValue.c_str(), "SSL");
  344. if (tGlobalConf->set("security.protocol", tValue, tBuffer) != RdKafka::Conf::CONF_OK)
  345. {
  346. LOG_ERROR(tBuffer.c_str());
  347. delete(tGlobalConf);
  348. return false;
  349. #ifdef DEBUG_KAFKA
  350. }
  351. else
  352. {
  353. LOG("SEC Proto is SSL");
  354. #endif
  355. };
  356. };
  357. if (m_pSettings->truststore)
  358. {
  359. sprintf((char *) tValue.c_str(), "./data/modules/VAULT/%s/%s.CA.pem", m_pSettings->vault_md5, m_pSettings->vault_md5);
  360. if (tGlobalConf->set("ssl.ca.location", tValue, tBuffer) != RdKafka::Conf::CONF_OK)
  361. {
  362. LOG_ERROR(tBuffer.c_str());
  363. delete(tGlobalConf);
  364. return false;
  365. #ifdef DEBUG_KAFKA
  366. }
  367. else
  368. {
  369. LOG("SSL CA Root is SET");
  370. #endif
  371. };
  372. };
  373. if (m_pSettings->certstore)
  374. {
  375. sprintf((char *) tValue.c_str(), "./data/modules/VAULT/%s/%s.CERT.pem", m_pSettings->vault_md5, m_pSettings->vault_md5);
  376. if (tGlobalConf->set("ssl.certificate.location", tValue, tBuffer) != RdKafka::Conf::CONF_OK)
  377. {
  378. LOG_ERROR(tBuffer.c_str());
  379. delete(tGlobalConf);
  380. return false;
  381. #ifdef DEBUG_KAFKA
  382. }
  383. else
  384. {
  385. LOG("SSL CERT is SET");
  386. #endif
  387. };
  388. };
  389. if (m_pSettings->keystore)
  390. {
  391. sprintf((char *) tValue.c_str(), "./data/modules/VAULT/%s/%s.key", m_pSettings->vault_md5, m_pSettings->vault_md5);
  392. if (tGlobalConf->set("ssl.key.location", tValue, tBuffer) != RdKafka::Conf::CONF_OK)
  393. {
  394. LOG_ERROR(tBuffer.c_str());
  395. delete(tGlobalConf);
  396. return false;
  397. #ifdef DEBUG_KAFKA
  398. }
  399. else
  400. {
  401. LOG("SSL KEY is SET");
  402. #endif
  403. };
  404. };
  405. if (strlen(m_pSettings->cred_password))
  406. {
  407. sprintf((char *) tValue.c_str(), m_pSettings->cred_password);
  408. if (tGlobalConf->set("ssl.key.password", tValue, tBuffer) != RdKafka::Conf::CONF_OK)
  409. {
  410. LOG_ERROR(tBuffer.c_str());
  411. delete(tGlobalConf);
  412. return false;
  413. #ifdef DEBUG_KAFKA
  414. }
  415. else
  416. {
  417. LOG("SSL KEY password is SET");
  418. #endif
  419. };
  420. };
  421. }
  422. else
  423. {
  424. if (m_pSettings->auth_by_cred)
  425. {
  426. sprintf((char *) tValue.c_str(), "SASL");
  427. if (tGlobalConf->set("security.protocol", tValue, tBuffer) != RdKafka::Conf::CONF_OK)
  428. {
  429. LOG_ERROR(tBuffer.c_str());
  430. delete(tGlobalConf);
  431. return false;
  432. #ifdef DEBUG_KAFKA
  433. }
  434. else
  435. {
  436. LOG("SEC Proto is SASL");
  437. #endif
  438. };
  439. sprintf((char *) tValue.c_str(), "PLAIN");
  440. if (tGlobalConf->set("sasl.mechanisms", tValue, tBuffer) != RdKafka::Conf::CONF_OK)
  441. {
  442. LOG_ERROR(tBuffer.c_str());
  443. delete(tGlobalConf);
  444. return false;
  445. #ifdef DEBUG_KAFKA
  446. }
  447. else
  448. {
  449. LOG("SASL mechanism is PLAIN");
  450. #endif
  451. };
  452. sprintf((char *) tValue.c_str(), "%s", m_pSettings->cred_username);
  453. if (tGlobalConf->set("sasl.username", tValue, tBuffer) != RdKafka::Conf::CONF_OK)
  454. {
  455. LOG_ERROR(tBuffer.c_str());
  456. delete(tGlobalConf);
  457. return false;
  458. #ifdef DEBUG_KAFKA
  459. }
  460. else
  461. {
  462. LOG("SASL username is SET");
  463. #endif
  464. };
  465. sprintf((char *) tValue.c_str(), "%s", m_pSettings->cred_password);
  466. if (tGlobalConf->set("sasl.password", tValue, tBuffer) != RdKafka::Conf::CONF_OK)
  467. {
  468. LOG_ERROR(tBuffer.c_str());
  469. delete(tGlobalConf);
  470. return false;
  471. #ifdef DEBUG_KAFKA
  472. }
  473. else
  474. {
  475. LOG("SASL password is SET");
  476. #endif
  477. };
  478. #ifdef DEBUG_KAFKA
  479. }
  480. else
  481. {
  482. LOG("No Auth Settings!");
  483. #endif
  484. };
  485. };
  486. /* Set the delivery report callback.
  487. * This callback will be called once per message to inform
  488. * the application if delivery succeeded or failed.
  489. * See dr_msg_cb() above.
  490. * The callback is only triggered from rd_kafka_poll() and
  491. * rd_kafka_flush(). */
  492. // tProducerConf->set("queue.buffering.max.ms", "100", tBuffer );
  493. // tProducerConf->set("socket.blocking.max.ms", "100", tBuffer );
  494. if (tGlobalConf->set("dr_cb", (RdKafka::DeliveryReportCb *) this, tBuffer) != RdKafka::Conf::CONF_OK)
  495. {
  496. LOG_ERROR(tBuffer.c_str());
  497. delete(tGlobalConf);
  498. return false;
  499. #ifdef DEBUG_KAFKA
  500. }
  501. else
  502. {
  503. LOG("dr_cb is SET");
  504. #endif
  505. };
  506. // if( tProducerConf->set("default_topic_conf", tTopicConf, tBuffer ) != RdKafka::Conf::CONF_OK ){
  507. // LOG_ERROR( tBuffer.c_str() );
  508. // delete( tProducerConf );
  509. // delete( tTopicConf );
  510. // tProducerConf = NULL;
  511. // tTopicConf = NULL;
  512. // return false;
  513. // };
  514. // LOG("default_topic_conf is SET");
  515. /*
  516. * Create producer instance.
  517. *
  518. * NOTE: rd_kafka_new() takes ownership of the conf object
  519. * and the application must not reference it again after
  520. * this call.
  521. */
  522. n_pProducer = RdKafka::Producer::create(tGlobalConf, tBuffer);
  523. if (n_pProducer == NULL)
  524. {
  525. LOG_ERROR(tBuffer.c_str());
  526. delete(tGlobalConf);
  527. return false;
  528. #ifdef DEBUG_KAFKA
  529. }
  530. else
  531. {
  532. LOG("RdKafka::Producer Created");
  533. #endif
  534. };
  535. if (tGlobalConf->set("enable.partition.eof", "true", tBuffer) != RdKafka::Conf::CONF_OK)
  536. {
  537. delete(n_pProducer);
  538. n_pProducer = NULL; // destructor would flush/delete it again
  539. delete(tGlobalConf);
  540. LOG_ERROR(tBuffer.c_str());
  541. return false;
  542. #ifdef DEBUG_KAFKA
  543. }
  544. else
  545. {
  546. LOG("enable.partition.eof is SET");
  547. #endif
  548. };
  549. m_pConsumer = RdKafka::Consumer::create(tGlobalConf, tBuffer);
  550. if (m_pConsumer == NULL)
  551. {
  552. delete(n_pProducer);
  553. n_pProducer = NULL; // destructor would flush/delete it again
  554. delete(tGlobalConf);
  555. LOG_ERROR("Failed to create consumer:");
  556. LOG_ERROR(tBuffer.c_str());
  557. return false;
  558. #ifdef DEBUG_KAFKA
  559. }
  560. else
  561. {
  562. LOG("RdKafka::Consumer Created");
  563. #endif
  564. };
  565. #ifdef DEBUG_KAFKA
  566. LOG("INIT Complete");
  567. #endif
  568. delete(tGlobalConf);
  569. return true;
  570. }
  571. bool protocolKAFKA::issuePost(CSTR tpc, CSTR Buffer, int BufferSize)
  572. {
  573. uint8_t rCnt = 3;
  574. char tBuf[128];
  575. RdKafka::ErrorCode err;
  576. RdKafka::Conf * tTopicConf = NULL;
  577. RdKafka::Topic * tKafkaTopic = NULL;
  578. std::string tBuffer;
  579. // std::string brokers = m_pKafkaBrokerSTR;
  580. std::string topic = tpc;
  581. if (n_pProducer == NULL)
  582. {
  583. return false;
  584. }
  585. tTopicConf = RdKafka::Conf::create(RdKafka::Conf::CONF_TOPIC);
  586. if (tTopicConf == NULL)
  587. {
  588. LOG_ERROR("Eror Creating Topic Conf!");
  589. return false;
  590. };
  591. #ifdef DEBUG_KAFKA
  592. LOG("RdKafka::Conf::CONF_TOPIC Created");
  593. #endif
  594. tKafkaTopic = RdKafka::Topic::create(n_pProducer, topic, tTopicConf, tBuffer);
  595. if (tKafkaTopic == NULL)
  596. {
  597. LOG_ERROR("No Topic Created!!");
  598. LOG_ERROR(tpc);
  599. LOG_ERROR(tBuffer.c_str());
  600. delete(tTopicConf);
  601. return false;
  602. };
  603. #ifdef DEBUG_KAFKA
  604. LOG("RdKafka::Topic Created");
  605. #endif
  606. /*
  607. if( tProducerConf->set( "default_topic_conf", tTopicConf, tBuffer ) != RdKafka::Conf::CONF_OK ){
  608. LOG_ERROR( tBuffer.c_str() );
  609. delete( tTopicConf );
  610. tProducerConf = NULL;
  611. tTopicConf = NULL;
  612. return false;
  613. };
  614. #ifdef DEBUG
  615. LOG("default_topic_conf is SET");
  616. #endif
  617. //*/
  618. retry:
  619. err = n_pProducer->produce(tKafkaTopic, RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, (void *) Buffer, BufferSize, NULL, NULL);
  620. if (err != RdKafka::ERR_NO_ERROR)
  621. {
  622. /// std::cerr << "% Failed to produce to topic " << topic << ": " << RdKafka::err2str(err) << std::endl;
  623. sprintf(tBuf, "Failed to produce to topic[%s]: %s", topic.c_str(), RdKafka::err2str(err).c_str());
  624. LOG_ERROR(tBuf);
  625. if (err == RdKafka::ERR__QUEUE_FULL)
  626. {
  627. LOG_ERROR("Internal queue is full!");
  628. /* If the internal queue is full, wait for
  629. * messages to be delivered and then retry.
  630. * The internal queue represents both
  631. * messages to be sent and messages that have
  632. * been sent or failed, awaiting their
  633. * delivery report callback to be called.
  634. *
  635. * The internal queue is limited by the
  636. * configuration property
  637. * queue.buffering.max.messages */
  638. n_pProducer->poll(1000 /*block for max 1000ms*/);
  639. if (rCnt--)
  640. {
  641. goto retry;
  642. }
  643. };
  644. }
  645. #ifdef DEBUG_KAFKA
  646. else
  647. {
  648. // MOCK
  649. FILE * fd;
  650. fd = fopen("KAFKA_M.txt", "a+");
  651. if (fd)
  652. {
  653. fprintf(fd, "\n*****************\n");
  654. fprintf(fd, Buffer);
  655. fprintf(fd, "\n*****************\nEnqueued message (%d bytes) for topic %s\n", BufferSize, topic.c_str());
  656. fclose(fd);
  657. };
  658. sprintf(tBuf, "Enqueued message (%d bytes) for topic %s", BufferSize, topic.c_str());
  659. LOG(tBuf);
  660. }
  661. #endif
  662. ;
  663. /* A producer application should continually serve
  664. * the delivery report queue by calling poll()
  665. * at frequent intervals.
  666. * Either put the poll call in your main loop, or in a
  667. * dedicated thread, or call it after every produce() call.
  668. * Just make sure that poll() is still called
  669. * during periods where you are not producing any messages
  670. * to make sure previously produced messages have their
  671. * delivery report callback served (and any other callbacks
  672. * you register). */
  673. n_pProducer->poll(100);
  674. // uint8_t cnt = 100;
  675. // while ( cnt && n_pProducer->outq_len() > 0) {
  676. // LOG("Wait ...");
  677. // cnt--;
  678. // n_pProducer->poll(100);
  679. // };
  680. delete(tKafkaTopic);
  681. delete(tTopicConf);
  682. tKafkaTopic = NULL;
  683. tTopicConf = NULL;
  684. return true;
  685. }
  686. void protocolKAFKA::consume_cb(RdKafka::Message & A, void * B)
  687. {
  688. if((A.err() == RdKafka::ERR_NO_ERROR ) || ( B != NULL )) LOG("CB Called!");
  689. /*
  690. char tBuff[256];
  691. switch (message->err()) {
  692. case RdKafka::ERR__TIMED_OUT: break;
  693. case RdKafka::ERR_NO_ERROR:
  694. // Real message
  695. sprintf( tBuff, "Read msg at offset %dd ", message->offset() );
  696. LOG( tBuff );
  697. if( message->key() ){
  698. sprintf( tBuff, "Key: %s ", *message->key()->c_str() );
  699. LOG( tBuff );
  700. };
  701. RdKafka::Headers *headers = message->headers();
  702. if( headers ){
  703. std::vector<RdKafka::Headers::Header> hdrs = headers->get_all();
  704. for (size_t i = 0 ; i < hdrs.size() ; i++) {
  705. const RdKafka::Headers::Header hdr = hdrs[i];
  706. if (hdr.value() != NULL) {
  707. sprintf( tBuff, " Header: %s = \"%.*s\"\n", hdr.key().c_str(), (int)hdr.value_size(), (const char *)hdr.value());
  708. } else {
  709. sprintf( tBuff, " Header: %s = NULL\n", hdr.key().c_str());
  710. };
  711. LOG( tBuff );
  712. };
  713. };
  714. //printf("%.*s\n", static_cast<int>(message->len()), static_cast<const char *>(message->payload()));
  715. break;
  716. case RdKafka::ERR__PARTITION_EOF:
  717. // Last message
  718. //if (exit_eof) {
  719. //}
  720. break;
  721. case RdKafka::ERR__UNKNOWN_TOPIC:
  722. case RdKafka::ERR__UNKNOWN_PARTITION:
  723. default:
  724. LOG_ERROR( "Consume failed!" );
  725. LOG_ERROR( message->errstr().c_str() );
  726. }; */
  727. }
  728. bool protocolKAFKA::receivePost(CSTR Channel, int32_t Partition, int64_t & Offset, CSTR Buffer, int & BufferSize)
  729. {
  730. //uint8_t rCnt = 3;
  731. char tBuf[128];
  732. //RdKafka::ErrorCode err;
  733. RdKafka::Conf * tTopicConf = NULL;
  734. RdKafka::Topic * tKafkaTopic = NULL;
  735. std::string tBuffer;
  736. std::string topic = Channel;
  737. BufferSize = 0;
  738. if (m_pConsumer == NULL)
  739. {
  740. return false;
  741. }
  742. tTopicConf = RdKafka::Conf::create(RdKafka::Conf::CONF_TOPIC);
  743. if (tTopicConf == NULL)
  744. {
  745. LOG_ERROR("Eror Creating Consumer Topic Conf!");
  746. return false;
  747. };
  748. #ifdef DEBUG_KAFKA
  749. LOG("Consumer RdKafka::Conf::CONF_TOPIC Created");
  750. #endif
  751. tKafkaTopic = RdKafka::Topic::create(m_pConsumer, topic, tTopicConf, tBuffer);
  752. if (tKafkaTopic == NULL)
  753. {
  754. LOG_ERROR("Failed to create Consumer topic!");
  755. delete(tTopicConf);
  756. return false;
  757. };
  758. #ifdef DEBUG_KAFKA
  759. LOG("Consumer RdKafka::Topic Created");
  760. #endif
  761. /*
  762. * Start consumer for topic+partition at start offset
  763. */
  764. // Get To Last Message
  765. if (Offset == 0)
  766. {
  767. LOG("Correcting Offset");
  768. int64_t bOff = m_pConsumer->OffsetTail(Offset);
  769. Offset += bOff - 1;
  770. };
  771. RdKafka::ErrorCode resp = m_pConsumer->start(tKafkaTopic, Partition, Offset); // Partition, Offset );
  772. if (resp != RdKafka::ERR_NO_ERROR)
  773. {
  774. LOG_ERROR("Failed to start consumer!");
  775. LOG_ERROR(RdKafka::err2str(resp).c_str());
  776. delete(tKafkaTopic);
  777. delete(tTopicConf);
  778. return false;
  779. };
  780. RdKafka::Message * message = m_pConsumer->consume(tKafkaTopic, Partition, 1000);
  781. if (message == NULL)
  782. {
  783. LOG_ERROR("FAILURE");
  784. delete(tKafkaTopic);
  785. delete(tTopicConf);
  786. return false;
  787. }
  788. else
  789. {
  790. switch (message->err())
  791. {
  792. case RdKafka::ERR__TIMED_OUT: LOG("TIME OUT"); break;
  793. case RdKafka::ERR_NO_ERROR:
  794. /* Real message */
  795. Offset = message->offset();
  796. #ifdef DEBUG_KAFKA
  797. sprintf(tBuf, "Read msg at offset %ld ", Offset);
  798. LOG(tBuf);
  799. if (message->key())
  800. {
  801. sprintf(tBuf, "Key: %c ", *message->key()->c_str());
  802. LOG(tBuf);
  803. };
  804. #endif
  805. // printf("%.*s\n", static_cast<int>(message->len()), static_cast<const char *>(message->payload()));
  806. BufferSize = message->len();
  807. memcpy(Buffer, message->payload(), BufferSize);
  808. Buffer[BufferSize] = (char) 0;
  809. break;
  810. case RdKafka::ERR__PARTITION_EOF:
  811. #ifdef DEBUG_KAFKA
  812. sprintf(tBuf, "EOF Read msg at partition %d and offset %ld ", Partition, Offset);
  813. LOG(tBuf);
  814. #endif
  815. break;
  816. case RdKafka::ERR__UNKNOWN_TOPIC:
  817. case RdKafka::ERR__UNKNOWN_PARTITION:
  818. default:
  819. LOG_ERROR("Consume failed!");
  820. LOG_ERROR(message->errstr().c_str());
  821. delete(message);
  822. delete(tKafkaTopic);
  823. delete(tTopicConf);
  824. return false;
  825. };
  826. }
  827. delete(message);
  828. m_pConsumer->stop(tKafkaTopic, 0);
  829. m_pConsumer->poll(1000);
  830. delete(tKafkaTopic);
  831. delete(tTopicConf);
  832. return true;
  833. }
  834. void protocolKAFKA::event_cb(RdKafka::Event & event)
  835. {
  836. if( event.type() == RdKafka::Event::EVENT_ERROR ) LOG("Evt ERROR!");
  837. /* switch (event.type()){
  838. case RdKafka::Event::EVENT_ERROR:
  839. if (event.fatal()) {
  840. std::cerr << "FATAL ";
  841. run = 0;
  842. }
  843. std::cerr << "ERROR (" << RdKafka::err2str(event.err()) << "): " << event.str() << std::endl;
  844. break;
  845. case RdKafka::Event::EVENT_STATS:
  846. std::cerr << "\"STATS\": " << event.str() << std::endl;
  847. break;
  848. case RdKafka::Event::EVENT_LOG:
  849. fprintf(stderr, "LOG-%i-%s: %s\n", event.severity(), event.fac().c_str(), event.str().c_str());
  850. break;
  851. default:
  852. std::cerr << "EVENT " << event.type() << " (" << RdKafka::err2str(event.err()) << "): " << event.str() << std::endl;
  853. break;
  854. }; */
  855. }
  856. #undef LOG
  857. #undef LOG_ERROR