Skip to content

Commit

Permalink
Extracted rdkafka from librd to its own library.
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhill committed Sep 19, 2012
1 parent d911d20 commit 96b4615
Show file tree
Hide file tree
Showing 25 changed files with 3,694 additions and 3 deletions.
1 change: 1 addition & 0 deletions .dir-locals.el
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
( (c-mode . ((c-file-style . "linux"))) )
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*~
\#*
*.o
*.so
*.so.?
*.a
*.d
core
25 changes: 25 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
librdkafka - Apache Kafka C driver library

Copyright (c) 2012, Magnus Edenhill
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
23 changes: 23 additions & 0 deletions LICENSE.pycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
The following license applies to the files rdcrc32.c and rdcrc32.h which
have been generated by the pycrc tool.
============================================================================

Copyright (c) 2006-2012, Thomas Pircher <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
68 changes: 68 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

LIBNAME=librdkafka
LIBVER=0
LIBVER_FULL=$(LIBVER).0.0


PREFIX?=/usr/local

# The preferred way to compile is to have a separate checkout of librd
# and link with it. If that is not desirable or possible the required librd
# functionality is included with librdkafka for compile-time inclusion.
# Define WITH_LIBRD to use an external librd, or leave undefined for the
# integrated version.
#WITH_LIBRD=1

# Use gcc as ld to avoid __stack_chk_fail_error symbol error.
LD=gcc


SRCS= rdkafka.c

ifndef WITH_LIBRD
SRCS+=rdcrc32.c rdgz.c rdaddr.c rdrand.c rdfile.c
endif

HDRS= rdkafka.h

OBJS= $(SRCS:.c=.o)
DEPS= ${OBJS:%.o=%.d}

CFLAGS+=-O2 -Wall -Werror -Wfloat-equal -Wpointer-arith -fPIC -I.
CFLAGS+=-g

# Profiling
#CFLAGS+=-O0
#CFLAGS += -pg
#LDFLAGS += -pg

LDFLAGS+=-shared -g -fPIC -lpthread -lrt -lz -lc

.PHONY:

all: libs

libs: $(LIBNAME).so $(LIBNAME).a

%.o: %.c
$(CC) -MD -MP $(CFLAGS) -c $<

$(LIBNAME).so: $(OBJS)
$(LD) -shared -Wl,-soname,$(LIBNAME).so.$(LIBVER) \
$(LDFLAGS) $(OBJS) -o $@
ln -fs $(LIBNAME).so $(LIBNAME).so.$(LIBVER)

$(LIBNAME).a: $(OBJS)
$(AR) rcs $@ $(OBJS)

install:
install -d $(PREFIX)/include/librdkafka $(PREFIX)/lib
install -t $(PREFIX)/include/$(LIBNAME) $(HDRS)
install -t $(PREFIX)/lib $(LIBNAME).so
install -t $(PREFIX)/lib $(LIBNAME).so.$(LIBVER)
install -t $(PREFIX)/lib $(LIBNAME).a

clean:
rm -f $(OBJS) $(DEPS) $(LIBNAME)*.a $(LIBNAME)*.so $(LIBNAME)*.so.?

-include $(DEPS)
74 changes: 71 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,72 @@
librdkafka
==========
librdkafka - Apache Kafka C client library
==========================================

Copyright (c) 2012, [Magnus Edenhill](http://www.edenhill.se/), et.al.

[https://github.com/edenhill/librdkafka](https://github.com/edenhill/librdkafka)

**librdkafka** is a C implementation of the
[Apache Kafka](http://incubator.apache.org/kafka/) protocol, containing both
Producer and Consumer support.
It currently supports Apache Kafka version 0.7.* (and possibly earlier).

ZooKeeper integration is planned but currently not available.

**librdkafka** is licensed under the 2-clause BSD license.


# Usage

## Requirements
The GNU toolchain
pthreads
zlib

## Instructions

### Building

make all
make install
# or to install in another location than /usr/local:
PREFIX=/my/prefix make install


### Usage in code

See `examples/rdkafka_example.c` for full examples of both
producer and consumer sides.


#include <librdkafka/rdkafka.h>

..

rd_kafka_t *rk;

rk = rd_kafka_new_consumer(broker, topic, partition, 0, &conf)

while (run) {
rko = rd_kafka_consume(rk, RD_POLL_INFINITE);
if (rko->rko_err)
..errhandling..
else if (rko->rko_len)
handle_message(rko->rko_payload, rko->rko_len);
}

rd_kafka_destroy(rk);



Link your program with `-lrdkafka -lz -lpthread -lrt`.


## Documentation

The API is documented in `rdkafka.h`

## Examples

See the `examples/`sub-directory.


Apache Kafka C library
1 change: 1 addition & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rdkafka_example
33 changes: 33 additions & 0 deletions examples/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
CC ?= cc
CFLAGS += -g
CFLAGS += -Wall -Werror -Wfloat-equal -Wpointer-arith -O2 -I../
LDFLAGS += -L../ -lrdkafka
LDFLAGS += -lpthread -lrt -lz

# Profiling
#CFLAGS += -O0 -pg
#LDFLAGS += -pg

all:
@echo "# Examples are built individually, i.e.:"
@echo " make rdkafka_example"


rdkafka_example: rdkafka_example.c
@(test $@ -nt $< || \
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS))
@echo "# $@ is ready"
@echo "#"
@echo "# Run producer (write messages on stdin)"
@echo "LD_LIBRARY_PATH=../ ./rdkafka_example -P -t <topic> -p <partition>"
@echo ""
@echo "# or consumer"
@echo "LD_LIBRARY_PATH=../ ./rdkafka_example -C -t <topic> -p <partition>"
@echo ""
@echo "#"
@echo "# More usage options:"
@echo "LD_LIBRARY_PATH=../ ./rdkafka_example --help"


clean:
rm -f rdkafka_example
Loading

0 comments on commit 96b4615

Please sign in to comment.