Giter Club home page Giter Club logo

kafka-php's Introduction

kafka-php

kafka-php allows you to produce messages to the Apache Kafka distributed publish/subscribe messaging service.

Requirements

  • Minimum PHP version: 5.3.3.
  • Apache Kafka 0.6.x or 0.7.x.
  • You need to have access to your Kafka instance and be able to connect through TCP. You can obtain a copy and instructions on how to setup kafka at https://github.com/kafka-dev/kafka
  • The PHP Zookeeper extension is required if you want to use the Zookeeper-based consumer.

Installation

Add the lib directory to the PHP include_path and use an autoloader like the one in the examples directory (the code follows the PEAR/Zend one-class-per-file convention).

Usage

The examples directory contains an example of a Producer and a simple Consumer, and an example of the Zookeeper-based Consumer.

Example Producer:

$producer = new Kafka_Producer('localhost', 9092, Kafka_Encoder::COMPRESSION_NONE);
$messages = array('some', 'messages', 'here');
$topic = 'test';
$bytes = $producer->send($messages, $topic);

Example Consumer:

$topic         = 'test';
$partition     = 0;
$offset        = 0;
$maxSize       = 1000000;
$socketTimeout = 5;

while (true) {
    $consumer = new Kafka_SimpleConsumer('localhost', 9092, $socketTimeout, $maxSize);
    $fetchRequest = new Kafka_FetchRequest($topic, $partition, $offset, $maxSize);
    $messages = $consumer->fetch($fetchRequest);
    foreach ($messages as $msg) {
        echo "\nMessage: " . $msg->payload();
    }
    //advance the offset after consuming each MessageSet
    $offset += $messages->validBytes();
    unset($fetchRequest);
}

TODO

  • support for Snappy compression

Contact for questions

Lorenzo Alberton

l.alberton at(@) quipo.it

http://twitter.com/lorenzoalberton

http://alberton.info/

kafka-php's People

Contributors

quipo avatar shyamalprasad avatar adrienbrault avatar mheap avatar mpitid avatar saji89 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.