Skip to content

Commit 96b4615

Browse files
committed
Extracted rdkafka from librd to its own library.
1 parent d911d20 commit 96b4615

25 files changed

+3694
-3
lines changed

Diff for: .dir-locals.el

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
( (c-mode . ((c-file-style . "linux"))) )

Diff for: .gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*~
2+
\#*
3+
*.o
4+
*.so
5+
*.so.?
6+
*.a
7+
*.d
8+
core

Diff for: LICENSE

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
librdkafka - Apache Kafka C driver library
2+
3+
Copyright (c) 2012, Magnus Edenhill
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
1. Redistributions of source code must retain the above copyright notice,
10+
this list of conditions and the following disclaimer.
11+
2. Redistributions in binary form must reproduce the above copyright notice,
12+
this list of conditions and the following disclaimer in the documentation
13+
and/or other materials provided with the distribution.
14+
15+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25+
POSSIBILITY OF SUCH DAMAGE.

Diff for: LICENSE.pycrc

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
The following license applies to the files rdcrc32.c and rdcrc32.h which
2+
have been generated by the pycrc tool.
3+
============================================================================
4+
5+
Copyright (c) 2006-2012, Thomas Pircher <[email protected]>
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
THE SOFTWARE.

Diff for: Makefile

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
LIBNAME=librdkafka
3+
LIBVER=0
4+
LIBVER_FULL=$(LIBVER).0.0
5+
6+
7+
PREFIX?=/usr/local
8+
9+
# The preferred way to compile is to have a separate checkout of librd
10+
# and link with it. If that is not desirable or possible the required librd
11+
# functionality is included with librdkafka for compile-time inclusion.
12+
# Define WITH_LIBRD to use an external librd, or leave undefined for the
13+
# integrated version.
14+
#WITH_LIBRD=1
15+
16+
# Use gcc as ld to avoid __stack_chk_fail_error symbol error.
17+
LD=gcc
18+
19+
20+
SRCS= rdkafka.c
21+
22+
ifndef WITH_LIBRD
23+
SRCS+=rdcrc32.c rdgz.c rdaddr.c rdrand.c rdfile.c
24+
endif
25+
26+
HDRS= rdkafka.h
27+
28+
OBJS= $(SRCS:.c=.o)
29+
DEPS= ${OBJS:%.o=%.d}
30+
31+
CFLAGS+=-O2 -Wall -Werror -Wfloat-equal -Wpointer-arith -fPIC -I.
32+
CFLAGS+=-g
33+
34+
# Profiling
35+
#CFLAGS+=-O0
36+
#CFLAGS += -pg
37+
#LDFLAGS += -pg
38+
39+
LDFLAGS+=-shared -g -fPIC -lpthread -lrt -lz -lc
40+
41+
.PHONY:
42+
43+
all: libs
44+
45+
libs: $(LIBNAME).so $(LIBNAME).a
46+
47+
%.o: %.c
48+
$(CC) -MD -MP $(CFLAGS) -c $<
49+
50+
$(LIBNAME).so: $(OBJS)
51+
$(LD) -shared -Wl,-soname,$(LIBNAME).so.$(LIBVER) \
52+
$(LDFLAGS) $(OBJS) -o $@
53+
ln -fs $(LIBNAME).so $(LIBNAME).so.$(LIBVER)
54+
55+
$(LIBNAME).a: $(OBJS)
56+
$(AR) rcs $@ $(OBJS)
57+
58+
install:
59+
install -d $(PREFIX)/include/librdkafka $(PREFIX)/lib
60+
install -t $(PREFIX)/include/$(LIBNAME) $(HDRS)
61+
install -t $(PREFIX)/lib $(LIBNAME).so
62+
install -t $(PREFIX)/lib $(LIBNAME).so.$(LIBVER)
63+
install -t $(PREFIX)/lib $(LIBNAME).a
64+
65+
clean:
66+
rm -f $(OBJS) $(DEPS) $(LIBNAME)*.a $(LIBNAME)*.so $(LIBNAME)*.so.?
67+
68+
-include $(DEPS)

Diff for: README.md

+71-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,72 @@
1-
librdkafka
2-
==========
1+
librdkafka - Apache Kafka C client library
2+
==========================================
3+
4+
Copyright (c) 2012, [Magnus Edenhill](http://www.edenhill.se/), et.al.
5+
6+
[https://github.com/edenhill/librdkafka](https://github.com/edenhill/librdkafka)
7+
8+
**librdkafka** is a C implementation of the
9+
[Apache Kafka](http://incubator.apache.org/kafka/) protocol, containing both
10+
Producer and Consumer support.
11+
It currently supports Apache Kafka version 0.7.* (and possibly earlier).
12+
13+
ZooKeeper integration is planned but currently not available.
14+
15+
**librdkafka** is licensed under the 2-clause BSD license.
16+
17+
18+
# Usage
19+
20+
## Requirements
21+
The GNU toolchain
22+
pthreads
23+
zlib
24+
25+
## Instructions
26+
27+
### Building
28+
29+
make all
30+
make install
31+
# or to install in another location than /usr/local:
32+
PREFIX=/my/prefix make install
33+
34+
35+
### Usage in code
36+
37+
See `examples/rdkafka_example.c` for full examples of both
38+
producer and consumer sides.
39+
40+
41+
#include <librdkafka/rdkafka.h>
42+
43+
..
44+
45+
rd_kafka_t *rk;
46+
47+
rk = rd_kafka_new_consumer(broker, topic, partition, 0, &conf)
48+
49+
while (run) {
50+
rko = rd_kafka_consume(rk, RD_POLL_INFINITE);
51+
if (rko->rko_err)
52+
..errhandling..
53+
else if (rko->rko_len)
54+
handle_message(rko->rko_payload, rko->rko_len);
55+
}
56+
57+
rd_kafka_destroy(rk);
58+
59+
60+
61+
Link your program with `-lrdkafka -lz -lpthread -lrt`.
62+
63+
64+
## Documentation
65+
66+
The API is documented in `rdkafka.h`
67+
68+
## Examples
69+
70+
See the `examples/`sub-directory.
71+
372

4-
Apache Kafka C library

Diff for: examples/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rdkafka_example

Diff for: examples/Makefile

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
CC ?= cc
2+
CFLAGS += -g
3+
CFLAGS += -Wall -Werror -Wfloat-equal -Wpointer-arith -O2 -I../
4+
LDFLAGS += -L../ -lrdkafka
5+
LDFLAGS += -lpthread -lrt -lz
6+
7+
# Profiling
8+
#CFLAGS += -O0 -pg
9+
#LDFLAGS += -pg
10+
11+
all:
12+
@echo "# Examples are built individually, i.e.:"
13+
@echo " make rdkafka_example"
14+
15+
16+
rdkafka_example: rdkafka_example.c
17+
@(test $@ -nt $< || \
18+
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS))
19+
@echo "# $@ is ready"
20+
@echo "#"
21+
@echo "# Run producer (write messages on stdin)"
22+
@echo "LD_LIBRARY_PATH=../ ./rdkafka_example -P -t <topic> -p <partition>"
23+
@echo ""
24+
@echo "# or consumer"
25+
@echo "LD_LIBRARY_PATH=../ ./rdkafka_example -C -t <topic> -p <partition>"
26+
@echo ""
27+
@echo "#"
28+
@echo "# More usage options:"
29+
@echo "LD_LIBRARY_PATH=../ ./rdkafka_example --help"
30+
31+
32+
clean:
33+
rm -f rdkafka_example

0 commit comments

Comments
 (0)