Rocketmq Name Server Implementation with Rust
Tags: rust, rocketmq, tutorial, opensource
Published: 2024-02-16 15:31:50

---
title: "Rocketmq Name Server Implementation with Rust"
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](https://github.com/mxsm/rocketmq-rust), follow me on [GitHub: mxsm](https://github.com/mxsm), and if there are any inaccuracies, please correct them by creating an [ISSUE or submitting a PR](https://github.com/mxsm/rocketmq-rust/issues)~ 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**](https://github.com/mxsm/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](https://raw.githubusercontent.com/mxsm/picture/main/rocketmq-rust/namesrvimage-20240128230341090.png)

  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](https://github.com/mxsm/rocketmq-rust/releases/download/v0.1.0/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](https://github.com/mxsm/rocketmq-rust/releases/download/v0.1.0/rocketmq-rust-all-bin-0.1.0.zip) from the [GitHub release page](https://github.com/mxsm/rocketmq-rust/releases/download/v0.1.0/rocketmq-rust-all-bin-0.1.0.zip).

![image-20240128233113192](https://raw.githubusercontent.com/mxsm/picture/main/rocketmq-rust/namesrvimage-20240128233113192.png)

![image-20240128233133244](https://raw.githubusercontent.com/mxsm/picture/main/rocketmq-rust/namesrvimage-20240128233133244.png)

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

![image-20240128231344495](https://raw.githubusercontent.com/mxsm/picture/main/rocketmq-rust/namesrvimage-20240128231344495.png)

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](https://raw.githubusercontent.com/mxsm/picture/main/rocketmq-rust/namesrvimage-20240128231641067.png)

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

![image-20240128231927444](https://raw.githubusercontent.com/mxsm/picture/main/rocketmq-rust/namesrvimage-20240128231927444.png)

You can view the usage by running the following command:

```powershell
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
```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](https://github.com/mxsm/rocketmq-rust), follow me on [GitHub: mxsm](https://github.com/mxsm), and if there are any inaccuracies, please correct them by creating an [ISSUE or submitting a PR](https://github.com/mxsm/rocketmq-rust/issues)~ 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**](https://github.com/mxsm/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](https://raw.githubusercontent.com/mxsm/picture/main/rocketmq-rust/namesrvimage-20240128230341090.png)

  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](https://github.com/mxsm/rocketmq-rust/releases/download/v0.1.0/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](https://github.com/mxsm/rocketmq-rust/releases/download/v0.1.0/rocketmq-rust-all-bin-0.1.0.zip) from the [GitHub release page](https://github.com/mxsm/rocketmq-rust/releases/download/v0.1.0/rocketmq-rust-all-bin-0.1.0.zip).

![image-20240128233113192](https://raw.githubusercontent.com/mxsm/picture/main/rocketmq-rust/namesrvimage-20240128233113192.png)

![image-20240128233133244](https://raw.githubusercontent.com/mxsm/picture/main/rocketmq-rust/namesrvimage-20240128233133244.png)

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

![image-20240128231344495](https://raw.githubusercontent.com/mxsm/picture/main/rocketmq-rust/namesrvimage-20240128231344495.png)

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](https://raw.githubusercontent.com/mxsm/picture/main/rocketmq-rust/namesrvimage-20240128231641067.png)

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

![image-20240128231927444](https://raw.githubusercontent.com/mxsm/picture/main/rocketmq-rust/namesrvimage-20240128231927444.png)

You can view the usage by running the following command:

```powershell
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
```

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](https://raw.githubusercontent.com/mxsm/picture/main/rocketmq-rust/namesrvimage-20240128232228666.png)

### 2.2 Installation via Cargo Command

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

```shell
cargo install rocketmq-namesrv
```

Wait for it to be installed locally.

![image-20240128232834062](https://raw.githubusercontent.com/mxsm/picture/main/rocketmq-rust/namesrvimage-20240128232834062.png)

Then run the command to verify:

```shell
rocketmq-namesrv-rust
```

![image-20240128232946771](https://raw.githubusercontent.com/mxsm/picture/main/rocketmq-rust/namesrvimage-20240128232946771.png)

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](https://github.com/mxsm/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
```

Then you can run the rocketmq name server.

## 3. Function Verification

How to verify the functionality? First, clone the code of **[rocketmq-dashboard](https://github.com/apache/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](https://raw.githubusercontent.com/mxsm/picture/main/rocketmq-rust/namesrvimage-20240128234422219.png)

**2. Start the rocketmq-dashboard**

![image-20240128234956398](https://raw.githubusercontent.com/mxsm/picture/main/rocketmq-rust/namesrvimage-20240128234956398.png)

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](https://raw.githubusercontent.com/mxsm/picture/main/rocketmq-rust/namesrvimage-20240128235058216.png)

**3 Start Broker registration**

![image-20240128235235695](https://raw.githubusercontent.com/mxsm/picture/main/rocketmq-rust/namesrvimage-20240128235235695.png)

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

![image-20240128235321539](https://raw.githubusercontent.com/mxsm/picture/main/rocketmq-rust/namesrvimage-20240128235321539.png)

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

## 4. Summary

The current [**rocketmq-rust**](https://github.com/mxsm/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](https://github.com/mxsm/rocketmq-rust/issues). Meanwhile, if you are interested in **Rust** and **RocketMQ**, you are welcome to participate in the project.

![image-20240129000040927](https://raw.githubusercontent.com/mxsm/picture/main/rocketmq-rust/namesrvimage-20240129000040927.png)