DEV Community

mxsm
mxsm

Posted on • Updated on

Rocketmq Name Server Implementation with Rust

I am Ant carrying an elephant (Apache EventMesh PMC&Committer). If this article is helpful to you, give Rocketmq-rust a star, follow me on GitHub: mxsm, and if there are any inaccuracies, please correct them by creating an ISSUE or submitting a PR~ Thank you! Email: mxsm@apache.com

1. Overview of Rocketmq-rust Name Server

After more than a month of development, a Rust version of the RocketMQ name server component has finally been developed. This component is fully compatible with the RocketMQ Java version and provides the same functionality.

GitHub Project Link: Rocketmq-rust

The advantages of using Rust to develop the RocketMQ name server are as follows:

  • Greatly reduced startup time compared to the Java version

image-20240128230341090

It can be seen that the entire RocketMQ name server startup is completed in less than one second.

  • Cross-platform features (need to be compiled on different platforms)

  • Memory safety, due to the memory management characteristics of the Rust language

If you usually use RocketMQ and need to start the name server locally, you can consider using this Rust version, which is both convenient and fast. Download Link: rocketmq-rust-all-bin-0.1.0.zip

2. Quick Start with Rocketmq-rust Name Server

There are two ways to quickly use the RocketMQ name server:

  • Download the precompiled program
  • Install using the cargo command
  • Compile using the source code

2.1 Downloading Binary Files

First, download the binary file rocketmq-rust-all-bin-0.1.0.zip from the GitHub release page.

image-20240128233113192

image-20240128233133244

After downloading, unzip the file. You will see two folders as shown below:

image-20240128231344495

There are two folders for Windows and Linux platforms.

Mac version is not provided for now, but it will be provided in future versions.

Next, let's take Windows as an example (Linux users can also try it on their own). In the windows folder, there is an executable file named rocketmq-namesrv-rust.exe, which is the startup file for the RocketMQ name server.

image-20240128231641067

Double-click to start. As shown in the figure below:

image-20240128231927444

You can view the usage by running the following command:

rocketmq-namesrv-rust.exe --help

RocketMQ Name server (Rust)

Usage: rocketmq-namesrv-rust.exe [OPTIONS]

Options:
  -p, --port <PORT>    RocketMQ name server port [default: 9876]
  -i, --ip <IP>        RocketMQ name server IP [default: 127.0.0.1]
  -c, --config <FILE>  RocketMQ name server config file
  -h, --help           Print help
  -V, --version        Print version
Enter fullscreen mode Exit fullscreen mode

markdown

title: "Rocketmq-rust Name Server Implementation"
linkTitle: "Rocketmq-rust Name Server"
sidebar_label: "Rocketmq-rust Name Server"
weight: 202401282245

description: "Rust implementation of RocketMQ Name Server"

I am Ant carrying an elephant (Apache EventMesh PMC&Committer). If this article is helpful to you, give Rocketmq-rust a star, follow me on GitHub: mxsm, and if there are any inaccuracies, please correct them by creating an ISSUE or submitting a PR~ Thank you! Email: mxsm@apache.com

1. Overview of Rocketmq-rust Name Server

After more than a month of development, a Rust version of the RocketMQ name server component has finally been developed. This component is fully compatible with the RocketMQ Java version and provides the same functionality.

GitHub Project Link: Rocketmq-rust

The advantages of using Rust to develop the RocketMQ name server are as follows:

  • Greatly reduced startup time compared to the Java version

image-20240128230341090

It can be seen that the entire RocketMQ name server startup is completed in less than one second.

  • Cross-platform features (need to be compiled on different platforms)

  • Memory safety, due to the memory management characteristics of the Rust language

If you usually use RocketMQ and need to start the name server locally, you can consider using this Rust version, which is both convenient and fast. Download Link: rocketmq-rust-all-bin-0.1.0.zip

2. Quick Start with Rocketmq-rust Name Server

There are two ways to quickly use the RocketMQ name server:

  • Download the precompiled program
  • Install using the cargo command
  • Compile using the source code

2.1 Downloading Binary Files

First, download the binary file rocketmq-rust-all-bin-0.1.0.zip from the GitHub release page.

image-20240128233113192

image-20240128233133244

After downloading, unzip the file. You will see two folders as shown below:

image-20240128231344495

There are two folders for Windows and Linux platforms.

Mac version is not provided for now, but it will be provided in future versions.

Next, let's take Windows as an example (Linux users can also try it on their own). In the windows folder, there is an executable file named rocketmq-namesrv-rust.exe, which is the startup file for the RocketMQ name server.

image-20240128231641067

Double-click to start. As shown in the figure below:

image-20240128231927444

You can view the usage by running the following command:

rocketmq-namesrv-rust.exe --help

RocketMQ Name server (Rust)

Usage: rocketmq-namesrv-rust.exe [OPTIONS]

Options:
  -p, --port <PORT>    RocketMQ name server port [default: 9876]
  -i, --ip <IP>        RocketMQ name server IP [default: 127.0.0.1]
  -c, --config <FILE>  RocketMQ name server config file
  -h, --help           Print help
  -V

, --version        Print version
Enter fullscreen mode Exit fullscreen mode

Here, you can configure the IP address, port, and configuration file of the RocketMQ name server. Compared to the Java version, I have made some optimizations here.

image-20240128232228666

2.2 Installation via Cargo Command

Install using the rust cargo command. Here is an example using Linux (WSL). Use the following command:

cargo install rocketmq-namesrv
Enter fullscreen mode Exit fullscreen mode

Wait for it to be installed locally.

image-20240128232834062

Then run the command to verify:

rocketmq-namesrv-rust
Enter fullscreen mode Exit fullscreen mode

image-20240128232946771

It can be seen that it runs successfully.

2.3 Compilation from Source Code

Compiling from source code is the same as installing via the cargo command. First, install rust, with a minimum version of 1.75.0. Then clone the source code of rocketmq-rust from GitHub to your local machine, and enter the root directory of the code. Run the following command:

cargo run --bin rocketmq-namesrv-rust
Enter fullscreen mode Exit fullscreen mode

Then you can run the rocketmq name server.

3. Function Verification

How to verify the functionality? First, clone the code of rocketmq-dashboard locally, or if you have the corresponding one locally, you can also use it.

Verification is done using IDEA

1. Start the Rust version of the nameserver

image-20240128234422219

2. Start the rocketmq-dashboard

image-20240128234956398

It can be seen from the logs printed by the name server that it has been connected (at this point, the Broker has not been started yet). Log in to the web and find that there is no data.

image-20240128235058216

3 Start Broker registration

image-20240128235235695

The name server received the broker registration request. Next, let's take a look at the information on the web page.

image-20240128235321539

The data has been registered. From here, we can see that the basic functions have been implemented.

4. Summary

The current rocketmq-rust project basically implements the function of a RocketMQ name server using Rust. There may be some bugs in the functionality, and further testing and fixes will be performed in subsequent versions. If you encounter any problems during use, you can raise an ISSUE. Meanwhile, if you are interested in Rust and RocketMQ, you are welcome to participate in the project.

image-20240129000040927

Top comments (0)