Lua SDK
This chapter describes how to access a DMS Kafka queue by using a Linux Lua client. To obtain related configuration information, see Preparing the Environment.
DMS is compatible with native Kafka APIs. For details on how to call native Kafka APIs, see the Kafka Documentation.
Preparing the Client Environment
- Download the SDK package.
Decompress the kafka-dms-lua.tar.gz file from the SDK package.
- Install the LuaJIT tool.
Run the following command to check whether the LuaJIT tool has been installed:
luajit -v
Install the LuaJIT tool if it has not been installed.- Ubuntu OS:
- Run the apt-cache search luajit command to check whether LuaJIT exists in the software repository. If not, configure the correct software repository address.
- Run the apt-get install luajit command to install LuaJIT.
- SUSE OS:
- Run the zypper search luajit command to check whether LuaJIT exists in the software repository. If not, configure the correct software repository address.
- Run the zypper install luajit command to install LuaJIT.
- CentOS or Red Hat OS:
- yum search luajit
- yum install luajit
- Ubuntu OS:
- Decompress the kafka-dms-lua.tar.gz package.
The following assumes that the package is decompressed in the {DMSPATH} directory.
- Run the following command to copy the Kafka dependency packages to the lib directory:
cp {DMSPATH}/kafka-dms-lua/librdkafka/lib/* /usr/lib/ -R
- Modify the parameters in the example_dms.lua file.
cd {DMSPATH}/kafka-dmslua/luadms
vi example_dms.lua
Modify the following parameters:
local BROKERS_ADDRESS = { "broker" } local TOPIC_NAME = "your kafka topic" config["sasl.project.id"]="your projectId" config["sasl.access.key"]="your ak" config["sasl.security.key"]="your sk"
Table 1 Parameter description Parameter
Description
How to Obtain
BROKERS_ADDRESS
Kafka endpoint
For details, see Preparing the Environment.
TOPIC_NAME
Kafka topic ID
sasl.project.id
Project ID
sasl.access.key
Tenant AK
security.key
Tenant SK
Running Example
Run the following command to produce messages:
luajit example_dms.lua
After this command is run, 10 messages are automatically sent to the Kafka queue.
Code Example
Producer parameters
for i = 0,10 do producer:produce(topic, KAFKA_PARTITION_UA, "this is test message"..tostring(i)) end while producer:outq_len() ~= 0 do producer:poll(10) end
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot