Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_kafka.h
Go to the documentation of this file.
1
9#ifndef __N_KAFKA
10#define __N_KAFKA
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
21#include "nilorea/n_log.h"
22#include "nilorea/n_network.h"
23#include "nilorea/n_network.h"
24#include "cJSON.h"
25
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <locale.h>
30#include <libgen.h>
31#include <errno.h>
32#include <unistd.h>
33
34#include "rdkafka.h"
35
37#define N_KAFKA_EVENT_QUEUED 0
39#define N_KAFKA_EVENT_WAITING_ACK 1
41#define N_KAFKA_EVENT_ERROR 2
43#define N_KAFKA_EVENT_OK 4
45#define N_KAFKA_EVENT_CREATED 5
46
66
68typedef struct N_KAFKA {
74 char* groupid;
75 /* list of topics to subscribe to */
76 char** topics;
77 /* subscribed topics */
78 rd_kafka_topic_partition_list_t* subscription;
80 rd_kafka_conf_t* rd_kafka_conf;
82 rd_kafka_t* rd_kafka_handle;
84 char* topic;
88 rd_kafka_topic_t* rd_kafka_topic;
94 pthread_rwlock_t rwlock;
96 int mode;
106 pthread_t pooling_thread;
107 /* number of waiting events in the producer waiting list */
108 size_t nb_queued;
109 /* number of events waiting for an ack in the waiting list */
111 /* number of errored events */
112 size_t nb_error;
113} N_KAFKA;
114
115int32_t n_kafka_get_schema_from_char(char* string);
116int32_t n_kafka_get_schema_from_nstr(N_STR* string);
117int n_kafka_put_schema_in_char(char* string, int schema_id);
118int n_kafka_put_schema_in_nstr(N_STR* string, int schema_id);
119
120int n_kafka_get_status(N_KAFKA* kafka, size_t* nb_queued, size_t* nb_waiting, size_t* nb_error);
121void n_kafka_delete(N_KAFKA* kafka);
122N_KAFKA* n_kafka_new(int32_t poll_timeout, int32_t poll_interval, size_t errstr_len);
124
125int n_kafka_new_headers(N_KAFKA_EVENT* event, size_t count);
126int n_kafka_add_header_ex(N_KAFKA_EVENT* event, char* key, size_t key_length, char* value, size_t value_length);
127int n_kafka_add_header(N_KAFKA_EVENT* event, N_STR* key, N_STR* value);
128
129int n_kafka_produce(N_KAFKA* kafka, N_KAFKA_EVENT* event);
130
131N_KAFKA_EVENT* n_kafka_new_event(int schema_id);
132N_KAFKA_EVENT* n_kafka_new_event_from_char(char* string, size_t written, int schema_id);
133N_KAFKA_EVENT* n_kafka_new_event_from_string(N_STR* string, int schema_id);
134N_KAFKA_EVENT* n_kafka_new_event_from_file(char* filename, int schema_id);
135void n_kafka_event_destroy_ptr(void* event);
137
138int n_kafka_poll(N_KAFKA* kafka);
141
142int n_kafka_dump_unprocessed(N_KAFKA* kafka, char* directory);
143int n_kafka_load_unprocessed(N_KAFKA* kafka, char* directory);
144
146
151#ifdef __cplusplus
152}
153#endif
154
155#endif // header guard
char * config_file
Definition ex_kafka.c:27
int mode
Network for managing conenctions.
Definition ex_network.c:22
char * key
Structure of a generic LIST container.
Definition n_list.h:40
int32_t poll_interval
poll interval in usecs
Definition n_kafka.h:102
rd_kafka_topic_partition_list_t * subscription
Definition n_kafka.h:78
cJSON * configuration
kafka json configuration holder
Definition n_kafka.h:98
pthread_t pooling_thread
pooling thread id
Definition n_kafka.h:106
size_t nb_waiting
Definition n_kafka.h:110
int mode
kafka handle mode: RD_KAFKA_CONSUMER or RD_KAFKA_PRODUCER
Definition n_kafka.h:96
char ** topics
Definition n_kafka.h:76
int schema_id
kafka schema_id
Definition n_kafka.h:62
rd_kafka_topic_t * rd_kafka_topic
kafka topic handle
Definition n_kafka.h:88
rd_kafka_headers_t * rd_kafka_headers
kafka produce event headers structure handle
Definition n_kafka.h:58
pthread_rwlock_t rwlock
access lock
Definition n_kafka.h:94
N_STR * errstr
kafka error string holder
Definition n_kafka.h:90
int pooling_thread_status
pooling thread status, 0 => off , 1 => on , 2 => wants to stop, will be turned out to 0 by exiting po...
Definition n_kafka.h:104
rd_kafka_conf_t * rd_kafka_conf
kafka structure handle
Definition n_kafka.h:80
LIST * received_events
list of received N_KAFKA_EVENT
Definition n_kafka.h:72
LIST * events_to_send
list of N_KAFKA_EVENT to send
Definition n_kafka.h:70
int32_t poll_timeout
poll timeout in usecs
Definition n_kafka.h:100
rd_kafka_t * rd_kafka_handle
kafka handle (producer or consumer)
Definition n_kafka.h:82
LIST * received_headers
kafka consume event headers structure handle
Definition n_kafka.h:60
N_STR * event_string
string containing the topic id + payload
Definition n_kafka.h:50
char * groupid
consumer group id
Definition n_kafka.h:74
N_STR * event_files_to_delete
string containing the original event source file name if it is to be deleted when event is produced.
Definition n_kafka.h:52
int schema_id
kafka schema id in network order
Definition n_kafka.h:92
struct N_KAFKA * parent_table
access lock
Definition n_kafka.h:64
size_t nb_queued
Definition n_kafka.h:108
size_t nb_error
Definition n_kafka.h:112
char * bootstrap_servers
kafka bootstrap servers string
Definition n_kafka.h:86
char * from_topic
in case of received event, else NULL
Definition n_kafka.h:54
unsigned int status
state of the event: N_KAFKA_EVENT_CREATED ,N_KAFKA_EVENT_QUEUED , N_KAFKA_EVENT_WAITING_ACK ,...
Definition n_kafka.h:56
char * topic
kafka topic string
Definition n_kafka.h:84
int n_kafka_add_header_ex(N_KAFKA_EVENT *event, char *key, size_t key_length, char *value, size_t value_length)
add a header entry to an event.
Definition n_kafka.c:560
int n_kafka_dump_unprocessed(N_KAFKA *kafka, char *directory)
dump unprocessed/unset events
Definition n_kafka.c:1025
N_KAFKA_EVENT * n_kafka_get_event(N_KAFKA *kafka)
get a received event from the N_KAFKA kafka handle
Definition n_kafka.c:1093
int n_kafka_new_headers(N_KAFKA_EVENT *event, size_t count)
allocate a headers array for the event
Definition n_kafka.c:535
int32_t n_kafka_get_schema_from_char(char *string)
get a schema from the first 4 bytes of a char *string, returning ntohl of the value
Definition n_kafka.c:18
int n_kafka_put_schema_in_nstr(N_STR *string, int schema_id)
put a htonl schema id into the first 4 bytes of a N_STR *string
Definition n_kafka.c:58
N_KAFKA * n_kafka_load_config(char *config_file, int mode)
load a kafka configuration from a file
Definition n_kafka.c:263
int n_kafka_get_status(N_KAFKA *kafka, size_t *nb_queued, size_t *nb_waiting, size_t *nb_error)
return the queues status
Definition n_kafka.c:73
int n_kafka_put_schema_in_char(char *string, int schema_id)
put a htonl schema id into the first 4 bytes of a char *string
Definition n_kafka.c:45
int n_kafka_poll(N_KAFKA *kafka)
Poll kafka handle in producer or consumer mode.
Definition n_kafka.c:792
int n_kafka_event_destroy(N_KAFKA_EVENT **event)
destroy a kafka event and set it's pointer to NULL
Definition n_kafka.c:780
void n_kafka_event_destroy_ptr(void *event)
festroy a kafka event
Definition n_kafka.c:752
int n_kafka_load_unprocessed(N_KAFKA *kafka, char *directory)
load unprocessed/unset events
Definition n_kafka.c:1076
int n_kafka_add_header(N_KAFKA_EVENT *event, N_STR *key, N_STR *value)
add a header entry to an event.
Definition n_kafka.c:594
int n_kafka_stop_pooling_thread(N_KAFKA *kafka)
stop the pooling thread of a kafka handle
Definition n_kafka.c:994
int n_kafka_produce(N_KAFKA *kafka, N_KAFKA_EVENT *event)
put an event in the events_to_send list
Definition n_kafka.c:610
N_KAFKA_EVENT * n_kafka_new_event_from_char(char *string, size_t written, int schema_id)
make a new event from a char *string
Definition n_kafka.c:686
int32_t n_kafka_get_schema_from_nstr(N_STR *string)
get a schema from the first 4 bytes of a N_STR *string, returning ntohl of the value
Definition n_kafka.c:32
int n_kafka_start_pooling_thread(N_KAFKA *kafka)
start the pooling thread of a kafka handle
Definition n_kafka.c:962
N_KAFKA_EVENT * n_kafka_new_event(int schema_id)
create a new empty event
Definition n_kafka.c:512
N_KAFKA_EVENT * n_kafka_new_event_from_file(char *filename, int schema_id)
make a new event from a N_STR *string
Definition n_kafka.c:739
N_KAFKA * n_kafka_new(int32_t poll_timeout, int32_t poll_interval, size_t errstr_len)
allocate a new kafka handle
Definition n_kafka.c:215
void n_kafka_delete(N_KAFKA *kafka)
delete a N_KAFKA handle
Definition n_kafka.c:160
N_KAFKA_EVENT * n_kafka_new_event_from_string(N_STR *string, int schema_id)
make a new event from a N_STR *string
Definition n_kafka.c:724
structure of a KAFKA consumer or producer handle
Definition n_kafka.h:68
structure of a KAFKA message
Definition n_kafka.h:48
A box including a string and his lenght.
Definition n_str.h:39
Generic log system.
Network Engine.