Kafka visualization tool KafkaTool sends kafka messages

Kafak is a commonly used message component in our work. Today, when we jointly debug with the partner, we were told that the upstream has not prepared the message data, and there is no way to get the message from the relying party, but we still want to test the message consumption code we wrote. How to do it? The conventional method is to extract the code of message consumption and package it into a public method, provide a Controller to directly construct the parameters and call it for verification. Or writing unit tests can achieve our goal.

But I always feel that I want to verify the code logic through Kafka. Is there a good way? The answer is definitely yes, which is to use KafkaTool to simulate the producer to send messages and consume them. I took some detours during the operation today and checked the relevant documents on the Internet. The results were not very good, so I recorded them for your reference.

Step 1: Install Kafka Tool

It's not right to describe here. I'll just post the picture of the installation.

Step 2: Configuration

Create a new connection, configure the cluster name, configure the dependent zk, and connect the producer. Among them, the name of the cluster can be whatever you can understand. ZK needs to be installed locally in advance. The cluster configuration of Kafka is the broker of the producer. As shown in the following sequence:

Step 3: Prepare and Send

After the configuration is complete, in the preparation stage, two items need to be prepared here.

First: Find the topic that the producer wants to send

Find the topic that the producer wants to send, and it doesn't matter if you choose a partition arbitrarily. Select the data column on the right, click the "+" sign, and two message types will appear. If you have a JSON type message, select the second one.

Second: Choose the way you want to send the message

We chose the second message type, pay attention to the part I framed in red, the message format is "key, value", here today except for some problems blocked for a while. Here I give a demo (note that the value is compressed by json):

key,{"eventName":"工变化","eventType":"completed","tenant":"BW","payloadData":{"projectOrderId":"","orderId":"5180218000008","cameraStatus":"0","statusName":"OFFLINE"},"sendTime":"2023-03-15 11:18:26"}

After filling out our message, click "add" to send the message. The result dialog box means whether to send it here, if you choose "Yes", it will stay in the original dialog box, and the content will not be cleared. If you choose "No", you will directly exit the message adding page, and you can choose according to the situation.

I hope it can help you avoid detours.

Guess you like

Origin blog.csdn.net/lly576403061/article/details/129570539
Recommended