# 快速开始

## 下载 & 构建 <a href="#download--build-from-release" id="download--build-from-release"></a>

点击 [here](https://www.apache.org/dyn/closer.cgi?path=rocketmq/4.2.0/rocketmq-all-4.2.0-source-release.zip) 下载 4.2.0 版本的源码，之后执行以下命令：

```bash
  $ unzip rocketmq-all-4.2.0-source-release.zip
  $ cd rocketmq-all-4.2.0/
  $ mvn -Prelease-all -DskipTests clean install -U
  $ cd distribution/target/apache-rocketmq
```

## 启动名称服务（Name Server） <a href="#start-name-server" id="start-name-server"></a>

```bash
 $ nohup sh bin/mqnamesrv &
 $ tail -f ~/logs/rocketmqlogs/namesrv.log
  The Name Server boot success...
```

## 启动Broker <a href="#start-broker" id="start-broker"></a>

```bash
  $ nohup sh bin/mqbroker -n localhost:9876 &
  $ tail -f ~/logs/rocketmqlogs/broker.log 
  The broker[%s, 172.30.30.233:10911] boot success...
```

## 发送 & 接收消息 <a href="#send--receive-messages" id="send--receive-messages"></a>

在发送/接收消息之前，我们需要告诉客户端名称服务的地址。RocketMQ 提供了多种配置方式。简单起见，我们使用设置环境变量 `NAMESRV_ADDR`的方式：

```bash
 $ export NAMESRV_ADDR=localhost:9876
 $ sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
 SendResult [sendStatus=SEND_OK, msgId= ...

 $ sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
 ConsumeMessageThread_%d Receive New Messages: [MessageExt...
```

## 关闭所有服务 <a href="#shutdown-servers" id="shutdown-servers"></a>

```bash
$ sh bin/mqshutdown broker
The mqbroker(36695) is running...
Send shutdown request to mqbroker(36695) OK

$ sh bin/mqshutdown namesrv
The mqnamesrv(36664) is running...
Send shutdown request to mqnamesrv(36664) OK
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://maxwell.gitbook.io/way-to-architect/zhong-jian-jian/xiao-xi-dui-lie/robbitmq/ke-hu-duan-shi-yong/kuai-su-kai-shi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
