国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home PHP Libraries Other libraries php-rdkafka client library
php-rdkafka client library

This is a client that can send and receive messages. Let me demonstrate the sending and receiving operations for you. Friends who need it can download it and try it out.

Send message

<?phptry {
    $rcf = new RdKafka\Conf();
    $rcf->set('group.id', 'test');
    $cf = new RdKafka\TopicConf();
    $cf->set('offset.store.method', 'broker');
    $cf->set('auto.offset.reset', 'smallest');
    $rk = new RdKafka\Producer($rcf);
    $rk->setLogLevel(LOG_DEBUG);
    $rk->addBrokers("127.0.0.1");
    $topic = $rk->newTopic("test", $cf);
    for($i = 0; $i < 1000; $i++) {
        $topic->produce(0,0,'test' . $i);//沒有setMessge接口了,使用produce  參考:https://libraries.io/github/mentionapp/php-rdkafka
    } 
} catch (Exception $e) {
    echo $e->getMessage();

Receive message

<?phptry {
    $rcf = new RdKafka\Conf();
    $rcf->set('group.id', 'test');
    $cf = new RdKafka\TopicConf();/*
    $cf->set('offset.store.method', 'file');
*/
    $cf->set('auto.offset.reset', 'smallest');
    $cf->set('auto.commit.enable', true);
    $rk = new RdKafka\Consumer($rcf);
    $rk->setLogLevel(LOG_DEBUG);
    $rk->addBrokers("127.0.0.1");
    $topic = $rk->newTopic("test", $cf);    //$topic->consumeStart(0, RD_KAFKA_OFFSET_BEGINNING);
    while (true) {
        $topic->consumeStart(0, RD_KAFKA_OFFSET_STORED);
        $msg = $topic->consume(0, 1000);
        var_dump($msg);        if ($msg->err) {            echo $msg->errstr(), "\n";            break;
        } else {            echo $msg->payload, "\n";
        }
        $topic->consumeStop(0);
        sleep(1);
    }
} catch (Exception $e) {    echo $e->getMessage();
}


Disclaimer

All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn

Related Article

**Which Python SOAP Client Library Is Right for You? Navigating the Diverse Options and Their Documentation.** **Which Python SOAP Client Library Is Right for You? Navigating the Diverse Options and Their Documentation.**

25 Oct 2024

Diverse Python SOAP Client Libraries: Navigating the Documentation LabyrinthFor novice Python developers exploring SOAP and its client libraries,...

## What SOAP Client Library Should You Choose for Your Python Project? ## What SOAP Client Library Should You Choose for Your Python Project?

28 Oct 2024

SOAP Client Libraries for PythonIntroduction:When exploring SOAP technologies in Python, selecting an appropriate client library is crucial. This...

Memcache vs. Memcached: Which PHP Library Should You Choose? Memcache vs. Memcached: Which PHP Library Should You Choose?

09 Nov 2024

Distinguishing "Memcache" and "Memcached" in PHPPHP offers two memcached libraries: memcache and memcached. Understanding their differences helps...

Memcache vs Memcached: Which PHP Memcached Library Should You Choose? Memcache vs Memcached: Which PHP Memcached Library Should You Choose?

19 Nov 2024

Memcache vs Memcached: Choosing the Right PHP Memcached LibraryIntroductionPHP offers two seemingly similar memcached libraries: memcache and...

Which PHP Library Best Fits Your Email Address Validation Needs? Which PHP Library Best Fits Your Email Address Validation Needs?

18 Nov 2024

PHP Email Address Validation Libraries UncoveredEmail address validation plays a crucial role in data validation, but creating a...

laravel - What should the standardized PHP class library naming look like? laravel - What should the standardized PHP class library naming look like?

06 Jul 2016

I have seen many open source projects in the form of class.classname.php, but I have also seen many frameworks in the form of classname.class.php. Where should I place this class? I personally prefer the .class.php form, because in some frameworks, after importing third-party class libraries and specifying class libraries...

See all articles