-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrb_kafka.c
102 lines (82 loc) · 3.02 KB
/
rb_kafka.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
Copyright (C) 2015 Eneo Tecnologia S.L.
Author: Eugenio Perez <eupm90@gmail.com>
Based on Luca Deri nprobe 6.22 collector
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#ifdef HAVE_LIBRDKAFKA
#include "rb_kafka.h"
#include "f2k.h"
#include "util.h"
int32_t rb_client_mac_partitioner (const rd_kafka_topic_t *rkt,
const void *key __attribute__((unused)),
size_t keylen __attribute__((unused)),
int32_t partition_cnt,
void *rkt_opaque,
void *msg_opaque){
const uint64_t client_mac = (intptr_t)msg_opaque;
if(client_mac == 0)
return rd_kafka_msg_partitioner_random(rkt,NULL,0,partition_cnt,rkt_opaque,msg_opaque);
else
return client_mac % partition_cnt;
}
void msg_delivered (rd_kafka_t *rk __attribute__((unused)),
void *payload __attribute__((unused)), size_t len,
int error_code,
void *opaque __attribute__((unused)),
void *msg_opaque __attribute__((unused))) {
if (error_code)
traceEvent(TRACE_ERROR, "Message delivery failed: %s\n",
rd_kafka_err2str(error_code));
else if (unlikely(readOnlyGlobals.enable_debug))
traceEvent(TRACE_INFO, "Message delivered (%zd bytes)\n", len);
}
void parse_kafka_config(rd_kafka_conf_t *rk_conf,rd_kafka_topic_conf_t *rkt_conf,
const char *option){
if(unlikely(readOnlyGlobals.enable_debug))
traceEvent(TRACE_INFO,"Applying %s to rdkafka",option);
char errstr[512];
char *name, *val;
rd_kafka_conf_res_t res;
name = strdup(option);
if(!name) {
traceEvent(TRACE_ERROR, "Can't duplicate %s string",option);
return;
}
if (!(val = strchr(name, '='))) {
traceEvent(TRACE_ERROR, "rdkafka config: Expected "
"-X/Y property=value, not %s, ",name);
free(name);
return;
}
*val = '\0';
val++;
res = RD_KAFKA_CONF_UNKNOWN;
/* Try "topic." prefixed properties on topic
* conf first, and then fall through to global if
* it didnt match a topic configuration property. */
if (!strncmp(name, "topic.", strlen("topic.")))
res = rd_kafka_topic_conf_set(rkt_conf,
name+
strlen("topic."),
val,
errstr,
sizeof(errstr));
if (res == RD_KAFKA_CONF_UNKNOWN)
res = rd_kafka_conf_set(rk_conf, name, val,
errstr, sizeof(errstr));
if (res != RD_KAFKA_CONF_OK)
traceEvent(TRACE_ERROR,"Error parsing rdkafka option: %s", errstr);
free(name);
}
#endif