Example of integrating Kafka with Nginx

Example of integrating Kafka with Nginx

background

nginx-kafka-module is a plug-in for nginx that can integrate Kafka into nginx to facilitate the collection of data from front-end pages in web projects. If data is embedded on the front-end page, some user access and request data can be sent directly to the message middleware Kafka through http requests. The backend can consume messages in Kafka through programs to perform real-time calculations. For example, SparkStream can be used to consume data in Kafka in real time to analyze user PV, UV, some user behaviors, and the funnel model conversion rate of the page to better optimize the system or conduct real-time dynamic analysis of visiting users.

Specific integration steps

1. Install git

yum install -y git

2. Switch to the /usr/local/src directory and clone the Kafka C client source code to the local

cd /usr/local/src
git clone https://github.com/edenhill/librdkafka

3. Enter librdkafka and compile

cd librdkafka
yum install -y gcc gcc-c++ pcre-devel zlib-devel
./configure
make && make install

4. Install the nginx integrated kafka plug-in, enter /usr/local/src, clone nginx integrated kafka source code

cd /usr/local/src
git clone https://github.com/brg-liuwei/ngx_kafka_module

5. Enter the nginx source package directory (compile nginx, and then compile the plug-in at the same time)

cd /usr/local/src/nginx-1.12.2
./configure --add-module=/usr/local/src/ngx_kafka_module/
make && make install

6. Modify the nginx configuration file: set a location and kafka topic. For details, please see nginx.conf in the current directory

#Add configuration (2 places)
kafka;
kafka_broker_list f1:9092 f2:9092 f3:9092;

location = /kafka/access {
kafka_topic access888;
}

As shown below:

7. Start zk and kafka clusters (create topics)

zkServer.sh start
kafka-server-start.sh -daemon config/server.properties

8. Start nginx, report an error, and cannot find the kafka.so.1 file

error while loading shared libraries: librdkafka.so.1: cannot open shared object file: No such file or directory

9. Load the so library

#Load the library under /usr/local/lib at boot time echo "/usr/local/lib" >> /etc/ld.so.conf
#Manually load ldconfig

10. Test, write data to nginx, and then observe whether Kafka consumers can consume the data

curl http://localhost/kafka/access -d "message send to kafka topic"
curl http://localhost/kafka/access -d "Xiaowei666" test

You can also simulate the page embedding request interface to send information:

The background Kafka consumption information is as follows:

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Detailed explanation of Spring Boot WebSocket integration and nginx configuration
  • How to install and configure FastDFS and integrate it with Nginx-1.13.3
  • Detailed explanation of the installation and configuration of Nginx+Tomcat integration under Linux
  • Detailed explanation of the integration process of centos6.4+nginx+mysql+php+phpmyadmin
  • How to Integrate Redmine and SVN into Nginx in Linux

<<:  js to implement verification code interference (static)

>>:  js to implement verification code interference (dynamic)

Recommend

Page Speed ​​Optimization at a Glance

I believe that the Internet has become an increas...

Detailed explanation of common commands in MySQL 8.0+

Enable remote access Enable remote access rights ...

JavaScript to achieve simple drag effect

This article shares the specific code of JavaScri...

Web design tips on form input boxes

1. Dashed box when cancel button is pressed <br...

How to use React forwardRef and what to note

Previously, react.forwardRef could not be applied...

Implementing circular scrolling list function based on Vue

Note: You need to give the parent container a hei...

Cross-domain issues in front-end and back-end separation of Vue+SpringBoot

In the front-end and back-end separation developm...

In-depth analysis of MySQL 8.0 redo log

Table of contents Preface Generation of redo log ...

Vue implements a complete process record of a single file component

Table of contents Preface Single file components ...

Detailed tutorial on integrating Apache Tomcat with IDEA editor

1. Download the tomcat compressed package from th...