- Refer to the CPP demo to install the Kafka library first.
- This Demo is based on the open source client php-rdkafka. Install the corresponding module based on the installation guide first. You may need to configure php.ini after you install the module. To confirm whether the installation is successful, call php -m|grep kafka.
- Configure setting.php based on the following instructions.
- Modify other configurations in the code. Example:
$conf->set('xxx', 'xxx');
. For information about the description of the configurations, see Configuration properties. - Run the php kafka-producer.php file to send messages.
- Run the php kafka-consumer.php file to consume messages.
Configuration file in demo | Parameter | Description |
---|---|---|
setting.php | topic_name | The name of the topic that you created in the Message Queue for Apache Kafka console. For more information, see Create resources. |
setting.php | consumer_id | The ID of the consumer group that you created in the Message Queue for Apache Kafka console. For more information, see Create resources. |
setting.php | bootstrap_servers | The endpoint. For more information, see View endpoints. |
setting.php | sasl_plain_username | The username. You can obtain the username on the Instance Details page in the Message Queue for Apache Kafka console. |
setting.php | sasl_plain_password | The password. You can obtain the password on the Instance Details page in the Message Queue for Apache Kafka console. |