From 612798a953cf97fff0f6bb053255f0e431812224 Mon Sep 17 00:00:00 2001 From: kaxiya1021 Date: Fri, 31 May 2024 18:19:30 +0800 Subject: [PATCH] Added the quickstart directory and fixed the rendering issue. --- .../01whychoose.md | 0 .../02whatis.md} | 0 .../_category_.json | 0 .../01quickstart.md} | 0 .../02quickstartWithDocker.md} | 454 +++++++++--------- .../03quickstartWithDockercompose.md} | 0 .../01whychoose.md | 0 .../02whatis.md} | 0 .../01quickstart.md} | 0 .../02quickstartWithDocker.md} | 436 ++++++++--------- .../03quickstartWithDockercompose.md} | 0 .../03quickstartWithDockercompose.md | 8 +- .../03quickstartWithDockercompose.md | 8 +- 13 files changed, 457 insertions(+), 449 deletions(-) rename docs/{01-introduction => 00-introduction}/01whychoose.md (100%) rename docs/{01-introduction/03whatis.md => 00-introduction/02whatis.md} (100%) rename docs/{01-introduction => 00-introduction}/_category_.json (100%) rename docs/{01-introduction/02quickstart.md => 01-quickstart/01quickstart.md} (100%) rename docs/{01-introduction/02quickstartWithDocker4.x.md => 01-quickstart/02quickstartWithDocker.md} (96%) rename docs/{01-introduction/02quickstartWithDockercompose.md => 01-quickstart/03quickstartWithDockercompose.md} (100%) rename i18n/en/docusaurus-plugin-content-docs/current/{01-introduction => 00-introduction}/01whychoose.md (100%) rename i18n/en/docusaurus-plugin-content-docs/current/{01-introduction/03whatis.md => 00-introduction/02whatis.md} (100%) rename i18n/en/docusaurus-plugin-content-docs/current/{01-introduction/02quickstart.md => 01-quickstart/01quickstart.md} (100%) rename i18n/en/docusaurus-plugin-content-docs/current/{01-introduction/02quickstartWithDocker4.x.md => 01-quickstart/02quickstartWithDocker.md} (93%) rename i18n/en/docusaurus-plugin-content-docs/current/{01-introduction/02quickstartWithDockercompose.md => 01-quickstart/03quickstartWithDockercompose.md} (100%) diff --git a/docs/01-introduction/01whychoose.md b/docs/00-introduction/01whychoose.md similarity index 100% rename from docs/01-introduction/01whychoose.md rename to docs/00-introduction/01whychoose.md diff --git a/docs/01-introduction/03whatis.md b/docs/00-introduction/02whatis.md similarity index 100% rename from docs/01-introduction/03whatis.md rename to docs/00-introduction/02whatis.md diff --git a/docs/01-introduction/_category_.json b/docs/00-introduction/_category_.json similarity index 100% rename from docs/01-introduction/_category_.json rename to docs/00-introduction/_category_.json diff --git a/docs/01-introduction/02quickstart.md b/docs/01-quickstart/01quickstart.md similarity index 100% rename from docs/01-introduction/02quickstart.md rename to docs/01-quickstart/01quickstart.md diff --git a/docs/01-introduction/02quickstartWithDocker4.x.md b/docs/01-quickstart/02quickstartWithDocker.md similarity index 96% rename from docs/01-introduction/02quickstartWithDocker4.x.md rename to docs/01-quickstart/02quickstartWithDocker.md index 85d70a80ce..dd09eda8bb 100644 --- a/docs/01-introduction/02quickstartWithDocker4.x.md +++ b/docs/01-quickstart/02quickstartWithDocker.md @@ -1,227 +1,227 @@ -# Docker 部署 RocketMQ 4.X - -这一节介绍如何使用Docker快速部署一个单节点单副本 RocketMQ 服务,并完成简单的消息收发。 - -:::tip 系统要求 - -1. 64位操作系统 -2. 64位 JDK 1.8+ - -::: - - - -## 1.拉取RocketMQ镜像 - -这里以[dockerhub](https://hub.docker.com/r/apache/rocketmq/tags)上 RocketMQ 4.9.6 版本的镜像为例,介绍部署过程。 - -```shell -docker pull apache/rocketmq:4.9.6 -``` - -## 2.创建容器共享网络 - -RocketMQ中有多个服务,需要创建多个容器,创建 docker 网络便于容器间相互通信。 - -```shell -docker network create rocketmq -``` - -## 3.启动NameServer - -```shell -# 启动NameServer -docker run -d --name rmqnamesrv -p 9876:9876 --net rocketmq apache/rocketmq:4.9.6 sh mqnamesrv - -# 验证NameServer是否启动成功 -docker logs -f rmqnamesrv -``` - -:::info - -我们可以看到 **'The Name Server boot success..',** 表示NameServer 已成功启动。 - -::: - -## 4.启动Broker - -NameServer成功启动后,我们启动Broker。 - - -import Tabs from '@theme/Tabs'; -import TabItem from '@theme/TabItem'; - - - - -```code -# 配置 Broker 的 IP 地址 -echo "brokerIP1=127.0.0.1" >broker.conf - -# 启动 Broker -docker run -d \ ---name rmqbroker \ ---net rocketmq \ --p 10912:10912 -p 10911:10911 -p 10909:10909 \ --e "NAMESRV_ADDR=rmqnamesrv:9876" \ --v ./broker.conf:/home/rocketmq/rocketmq-4.9.6/conf/broker.conf \ -apache/rocketmq:4.9.6 sh mqbroker \ --c /home/rocketmq/rocketmq-4.9.6/conf/broker.conf - -# 验证 Broker 是否启动成功 -docker logs rmqbroker -``` - - - -```code -# 配置 Broker 的 IP 地址 -echo "brokerIP1=127.0.0.1" >broker.conf - -# 启动 Broker -docker run -d ^ ---name rmqbroker ^ ---net rocketmq ^ --p 10912:10912 -p 10911:10911 -p 10909:10909 ^ --e "NAMESRV_ADDR=rmqnamesrv:9876" ^ --v %cd%\broker.conf:/home/rocketmq/rocketmq-4.9.6/conf/broker.conf ^ -apache/rocketmq:4.9.6 sh mqbroker ^ --c /home/rocketmq/rocketmq-4.9.6/conf/broker.conf - -# 验证 Broker 是否启动成功 -docker logs rmqbroker -``` - - - - - - - - -:::info - -我们可以看到 **'The broker boot success..',** 表示 Broker 已成功启动。 - -::: - -:::note - -至此,一个单节点副本的 RocketMQ 集群已经部署起来了,我们可以利用脚本进行简单的消息收发。 - -::: - -## 5.工具测试消息收发 - -```shell -# 进入broker容器 -$ docker exec -it rmqbroker bash - -$ sh tools.sh org.apache.rocketmq.example.quickstart.Producer - SendResult [sendStatus=SEND_OK, msgId= ... - -$ sh tools.sh org.apache.rocketmq.example.quickstart.Consumer - ConsumeMessageThread_%d Receive New Messages: [MessageExt... -``` - - - -## 6.SDK测试消息收发 - -工具测试完成后,我们可以尝试使用 SDK 收发消息,这里以 Java SDK 为例介绍一下消息收发过程。 - -1. 在IDEA中创建一个Java工程。 - -2. 在 *pom.xml* 文件中添加以下依赖引入Java依赖库 - - ``` - - org.apache.rocketmq - rocketmq-client - 4.9.6 - - ``` - -3. 在已创建的Java工程中,创建发送普通消息程序并运行,Apache RocketMQ可用于以三种方式发送消息:**同步、异步和单向传输**,这里以同步模式为示例: - - ```java - import org.apache.rocketmq.client.producer.DefaultMQProducer; - import org.apache.rocketmq.client.producer.SendResult; - import org.apache.rocketmq.common.message.Message; - - public class ProducerExample { - public static void main(String[] args) throws Exception { - // 创建生产者实例,并设置生产者组名 - DefaultMQProducer producer = new DefaultMQProducer("please_rename_unique_group_name"); - // 设置 Name Server 地址,此处为示例,实际使用时请替换为真实的 Name Server 地址 - producer.setNamesrvAddr("localhost:9876"); - producer.start(); - - try { - // 创建消息实例,指定 topic、Tag和消息体 - Message msg = new Message("TestTopic", "TagA", ("Hello RocketMQ").getBytes()); - // 发送消息并获取发送结果 - SendResult sendResult = producer.send(msg); - System.out.println("Message sent: " + new String(msg.getBody())); - System.out.println("Send result: " + sendResult); - } catch (Exception e) { - e.printStackTrace(); - System.out.println("Message sending failed."); - } finally { - // 关闭生产者 - producer.shutdown(); - } - } - } - ``` - -4. 在已创建的Java工程中,创建订阅普通消息程序并运行。Apache RocketMQ 有两种消费模式:**Push和Pull**,这里以Push消费为示例。 - - ```java - import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; - import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; - import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; - import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; - import org.apache.rocketmq.common.message.MessageExt; - - import java.util.List; - - public class ConsumerExample { - public static void main(String[] args) throws Exception { - // 创建消费者实例,并设置消费者组名 - DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("please_rename_unique_group_name"); - // 设置 Name Server 地址,此处为示例,实际使用时请替换为真实的 Name Server 地址 - consumer.setNamesrvAddr("localhost:9876"); - // 订阅指定的主题和标签(* 表示所有标签) - consumer.subscribe("TestTopic", "*"); - - // 注册消息监听器 - consumer.registerMessageListener(new MessageListenerConcurrently() { - @Override - public ConsumeConcurrentlyStatus consumeMessage(List msgs, ConsumeConcurrentlyContext context) { - for (MessageExt msg : msgs) { - System.out.println("Received message: " + new String(msg.getBody())); - } - return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; - } - }); - - // 启动消费者 - consumer.start(); - System.out.println("Consumer started."); - } - } - ``` - - -## 7. 停止容器 -完成实验后,我们可以通过以下方式停止容器 -```shell -# 停止 NameServer 容器 -docker stop rmqnamesrv - -# 停止 Broker 容器 -docker stop rmqbroker -``` - - +# Docker 部署 RocketMQ + +这一节介绍如何使用Docker快速部署一个单节点单副本 RocketMQ 服务,并完成简单的消息收发。 + +:::tip 系统要求 + +1. 64位操作系统 +2. 64位 JDK 1.8+ + +::: + + + +## 1.拉取RocketMQ镜像 + +这里以[dockerhub](https://hub.docker.com/r/apache/rocketmq/tags)上 RocketMQ 4.9.6 版本的镜像为例,介绍部署过程。 + +```shell +docker pull apache/rocketmq:4.9.6 +``` + +## 2.创建容器共享网络 + +RocketMQ中有多个服务,需要创建多个容器,创建 docker 网络便于容器间相互通信。 + +```shell +docker network create rocketmq +``` + +## 3.启动NameServer + +```shell +# 启动NameServer +docker run -d --name rmqnamesrv -p 9876:9876 --net rocketmq apache/rocketmq:4.9.6 sh mqnamesrv + +# 验证NameServer是否启动成功 +docker logs -f rmqnamesrv +``` + +:::info + +我们可以看到 **'The Name Server boot success..',** 表示NameServer 已成功启动。 + +::: + +## 4.启动Broker + +NameServer成功启动后,我们启动Broker。 + + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + + + + +```code +# 配置 Broker 的 IP 地址 +echo "brokerIP1=127.0.0.1" >broker.conf + +# 启动 Broker +docker run -d \ +--name rmqbroker \ +--net rocketmq \ +-p 10912:10912 -p 10911:10911 -p 10909:10909 \ +-e "NAMESRV_ADDR=rmqnamesrv:9876" \ +-v ./broker.conf:/home/rocketmq/rocketmq-4.9.6/conf/broker.conf \ +apache/rocketmq:4.9.6 sh mqbroker \ +-c /home/rocketmq/rocketmq-4.9.6/conf/broker.conf + +# 验证 Broker 是否启动成功 +docker logs rmqbroker +``` + + + +```code +# 配置 Broker 的 IP 地址 +echo "brokerIP1=127.0.0.1" >broker.conf + +# 启动 Broker +docker run -d ^ +--name rmqbroker ^ +--net rocketmq ^ +-p 10912:10912 -p 10911:10911 -p 10909:10909 ^ +-e "NAMESRV_ADDR=rmqnamesrv:9876" ^ +-v %cd%\broker.conf:/home/rocketmq/rocketmq-4.9.6/conf/broker.conf ^ +apache/rocketmq:4.9.6 sh mqbroker ^ +-c /home/rocketmq/rocketmq-4.9.6/conf/broker.conf + +# 验证 Broker 是否启动成功 +docker logs rmqbroker +``` + + + + + + + + +:::info + +我们可以看到 **'The broker boot success..',** 表示 Broker 已成功启动。 + +::: + +:::note + +至此,一个单节点副本的 RocketMQ 集群已经部署起来了,我们可以利用脚本进行简单的消息收发。 + +::: + +## 5.工具测试消息收发 + +```shell +# 进入broker容器 +$ docker exec -it rmqbroker bash + +$ sh tools.sh org.apache.rocketmq.example.quickstart.Producer + SendResult [sendStatus=SEND_OK, msgId= ... + +$ sh tools.sh org.apache.rocketmq.example.quickstart.Consumer + ConsumeMessageThread_%d Receive New Messages: [MessageExt... +``` + + + +## 6.SDK测试消息收发 + +工具测试完成后,我们可以尝试使用 SDK 收发消息,这里以 Java SDK 为例介绍一下消息收发过程。 + +1. 在IDEA中创建一个Java工程。 + +2. 在 *pom.xml* 文件中添加以下依赖引入Java依赖库 + + ``` + + org.apache.rocketmq + rocketmq-client + 4.9.6 + + ``` + +3. 在已创建的Java工程中,创建发送普通消息程序并运行,Apache RocketMQ可用于以三种方式发送消息:**同步、异步和单向传输**,这里以同步模式为示例: + + ```java + import org.apache.rocketmq.client.producer.DefaultMQProducer; + import org.apache.rocketmq.client.producer.SendResult; + import org.apache.rocketmq.common.message.Message; + + public class ProducerExample { + public static void main(String[] args) throws Exception { + // 创建生产者实例,并设置生产者组名 + DefaultMQProducer producer = new DefaultMQProducer("please_rename_unique_group_name"); + // 设置 Name Server 地址,此处为示例,实际使用时请替换为真实的 Name Server 地址 + producer.setNamesrvAddr("localhost:9876"); + producer.start(); + + try { + // 创建消息实例,指定 topic、Tag和消息体 + Message msg = new Message("TestTopic", "TagA", ("Hello RocketMQ").getBytes()); + // 发送消息并获取发送结果 + SendResult sendResult = producer.send(msg); + System.out.println("Message sent: " + new String(msg.getBody())); + System.out.println("Send result: " + sendResult); + } catch (Exception e) { + e.printStackTrace(); + System.out.println("Message sending failed."); + } finally { + // 关闭生产者 + producer.shutdown(); + } + } + } + ``` + +4. 在已创建的Java工程中,创建订阅普通消息程序并运行。Apache RocketMQ 有两种消费模式:**Push和Pull**,这里以Push消费为示例。 + + ```java + import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; + import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; + import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; + import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; + import org.apache.rocketmq.common.message.MessageExt; + + import java.util.List; + + public class ConsumerExample { + public static void main(String[] args) throws Exception { + // 创建消费者实例,并设置消费者组名 + DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("please_rename_unique_group_name"); + // 设置 Name Server 地址,此处为示例,实际使用时请替换为真实的 Name Server 地址 + consumer.setNamesrvAddr("localhost:9876"); + // 订阅指定的主题和标签(* 表示所有标签) + consumer.subscribe("TestTopic", "*"); + + // 注册消息监听器 + consumer.registerMessageListener(new MessageListenerConcurrently() { + @Override + public ConsumeConcurrentlyStatus consumeMessage(List msgs, ConsumeConcurrentlyContext context) { + for (MessageExt msg : msgs) { + System.out.println("Received message: " + new String(msg.getBody())); + } + return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; + } + }); + + // 启动消费者 + consumer.start(); + System.out.println("Consumer started."); + } + } + ``` + + +## 7. 停止容器 +完成实验后,我们可以通过以下方式停止容器 +```shell +# 停止 NameServer 容器 +docker stop rmqnamesrv + +# 停止 Broker 容器 +docker stop rmqbroker +``` + + diff --git a/docs/01-introduction/02quickstartWithDockercompose.md b/docs/01-quickstart/03quickstartWithDockercompose.md similarity index 100% rename from docs/01-introduction/02quickstartWithDockercompose.md rename to docs/01-quickstart/03quickstartWithDockercompose.md diff --git a/i18n/en/docusaurus-plugin-content-docs/current/01-introduction/01whychoose.md b/i18n/en/docusaurus-plugin-content-docs/current/00-introduction/01whychoose.md similarity index 100% rename from i18n/en/docusaurus-plugin-content-docs/current/01-introduction/01whychoose.md rename to i18n/en/docusaurus-plugin-content-docs/current/00-introduction/01whychoose.md diff --git a/i18n/en/docusaurus-plugin-content-docs/current/01-introduction/03whatis.md b/i18n/en/docusaurus-plugin-content-docs/current/00-introduction/02whatis.md similarity index 100% rename from i18n/en/docusaurus-plugin-content-docs/current/01-introduction/03whatis.md rename to i18n/en/docusaurus-plugin-content-docs/current/00-introduction/02whatis.md diff --git a/i18n/en/docusaurus-plugin-content-docs/current/01-introduction/02quickstart.md b/i18n/en/docusaurus-plugin-content-docs/current/01-quickstart/01quickstart.md similarity index 100% rename from i18n/en/docusaurus-plugin-content-docs/current/01-introduction/02quickstart.md rename to i18n/en/docusaurus-plugin-content-docs/current/01-quickstart/01quickstart.md diff --git a/i18n/en/docusaurus-plugin-content-docs/current/01-introduction/02quickstartWithDocker4.x.md b/i18n/en/docusaurus-plugin-content-docs/current/01-quickstart/02quickstartWithDocker.md similarity index 93% rename from i18n/en/docusaurus-plugin-content-docs/current/01-introduction/02quickstartWithDocker4.x.md rename to i18n/en/docusaurus-plugin-content-docs/current/01-quickstart/02quickstartWithDocker.md index 832716e59f..3848e81ff9 100644 --- a/i18n/en/docusaurus-plugin-content-docs/current/01-introduction/02quickstartWithDocker4.x.md +++ b/i18n/en/docusaurus-plugin-content-docs/current/01-quickstart/02quickstartWithDocker.md @@ -1,219 +1,219 @@ -# Docker Deployment of RocketMQ 4.X - -This section introduces how to quickly deploy a single-node, single-replica RocketMQ service using Docker and complete simple message sending and receiving. - -:::tip System Requirements - -1. 64-bit operating system -2. 64-bit JDK 1.8+ - -::: - -## 1. Pull RocketMQ Image - -Here, we take the RocketMQ 4.9.6 version image from [dockerhub](https://hub.docker.com/r/apache/rocketmq/tags) as an example to introduce the deployment process. - -```shell -docker pull apache/rocketmq:4.9.6 -``` - -## 2. Create a Shared Network for Containers - -RocketMQ involves multiple services and requires multiple containers. Creating a Docker network facilitates communication between containers. - -```shell -docker network create rocketmq -``` - -## 3. Start NameServer - -```shell -# Start NameServer -docker run -d --name rmqnamesrv -p 9876:9876 --net rocketmq apache/rocketmq:4.9.6 sh mqnamesrv - -# Verify if NameServer started successfully -docker logs -f rmqnamesrv -``` - -:::info - -We can see **'The Name Server boot success..',** indicating that the NameServer has started successfully. - -::: - -## 4. Start Broker - -After the NameServer starts successfully, we start the Broker. - - -import Tabs from '@theme/Tabs'; -import TabItem from '@theme/TabItem'; - - - - -```code -# Configure the broker's IP address -echo "brokerIP1=127.0.0.1" >broker.conf - -# Start Broker -docker run -d \ ---name rmqbroker \ ---net rocketmq \ --p 10912:10912 -p 10911:10911 -p 10909:10909 \ --e "NAMESRV_ADDR=rmqnamesrv:9876" \ --v ./broker.conf:/home/rocketmq/rocketmq-4.9.6/conf/broker.conf \ -apache/rocketmq:4.9.6 sh mqbroker \ --c /home/rocketmq/rocketmq-4.9.6/conf/broker.conf - -# Verify if Broker started successfully -docker logs rmqbroker -``` - - - -```code -# Configure the broker's IP address -echo "brokerIP1=127.0.0.1" >broker.conf - -# Start Broker -docker run -d ^ ---name rmqbroker ^ ---net rocketmq ^ --p 10912:10912 -p 10911:10911 -p 10909:10909 ^ --e "NAMESRV_ADDR=rmqnamesrv:9876" ^ --v %cd%\broker.conf:/home/rocketmq/rocketmq-4.9.6/conf/broker.conf ^ -apache/rocketmq:4.9.6 sh mqbroker ^ --c /home/rocketmq/rocketmq-4.9.6/conf/broker.conf - -# Verify if Broker started successfully -docker logs rmqbroker -``` - - - - - - -:::info - -We can see **'The broker boot success..',** indicating that the Broker has started successfully. - -::: - -:::note - -At this point, a single-node replica RocketMQ cluster has been deployed. We can use scripts for simple message sending and receiving. - -::: - -## 5. Test Message Sending and Receiving with Tools - -```shell -# Enter the broker container -$ docker exec -it rmqbroker bash - -$ sh tools.sh org.apache.rocketmq.example.quickstart.Producer - SendResult [sendStatus=SEND_OK, msgId= ... - -$ sh tools.sh org.apache.rocketmq.example.quickstart.Consumer - ConsumeMessageThread_%d Receive New Messages: [MessageExt... -``` - -## 6. Test Message Sending and Receiving with SDK - -After testing with tools, we can try sending and receiving messages using the SDK. Here, we use the Java SDK as an example to introduce the process. - -1. Create a Java project in IDEA. - -2. Add the following dependencies to the *pom.xml* file to introduce the Java library. - - ``` - - org.apache.rocketmq - rocketmq-client - 4.9.6 - - ``` - -3. In the created Java project, create and run a program to send a simple message. Apache RocketMQ can send messages in three ways: **synchronous, asynchronous, and one-way transmission**. Here we use the synchronous mode as an example: - - ```java - import org.apache.rocketmq.client.producer.DefaultMQProducer; - import org.apache.rocketmq.client.producer.SendResult; - import org.apache.rocketmq.common.message.Message; - - public class ProducerExample { - public static void main(String[] args) throws Exception { - // Create producer instance and set the producer group name - DefaultMQProducer producer = new DefaultMQProducer("please_rename_unique_group_name"); - // Set the Name Server address (replace with actual Name Server address) - producer.setNamesrvAddr("localhost:9876"); - producer.start(); - - try { - // Create a message instance, specifying the topic, tag, and message body - Message msg = new Message("TestTopic", "TagA", ("Hello RocketMQ").getBytes()); - // Send the message and get the send result - SendResult sendResult = producer.send(msg); - System.out.println("Message sent: " + new String(msg.getBody())); - System.out.println("Send result: " + sendResult); - } catch (Exception e) { - e.printStackTrace(); - System.out.println("Message sending failed."); - } finally { - // Shutdown the producer - producer.shutdown(); - } - } - } - ``` - -4. In the created Java project, create and run a program to subscribe to simple messages. Apache RocketMQ has two consumption modes: **Push and Pull**. Here we use the Push mode as an example. - - ```java - import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; - import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; - import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; - import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; - import org.apache.rocketmq.common.message.MessageExt; - - import java.util.List; - - public class ConsumerExample { - public static void main(String[] args) throws Exception { - // Create consumer instance and set the consumer group name - DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("please_rename_unique_group_name"); - // Set the Name Server address (replace with actual Name Server address) - consumer.setNamesrvAddr("localhost:9876"); - // Subscribe to the specified topic and tag (* means all tags) - consumer.subscribe("TestTopic", "*"); - - // Register message listener - consumer.registerMessageListener(new MessageListenerConcurrently() { - @Override - public ConsumeConcurrentlyStatus consumeMessage(List msgs, ConsumeConcurrentlyContext context) { - for (MessageExt msg : msgs) { - System.out.println("Received message: " + new String(msg.getBody())); - } - return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; - } - }); - - // Start the consumer - consumer.start(); - System.out.println("Consumer started."); - } - } - ``` - - -## 7. Stop the Containers -After completing the experiment, we can stop the containers as follows: -```shell -# Stop the NameServer container -docker stop rmqnamesrv - -# Stop the Broker container -docker stop rmqbroker +# Docker Deployment of RocketMQ + +This section introduces how to quickly deploy a single-node, single-replica RocketMQ service using Docker and complete simple message sending and receiving. + +:::tip System Requirements + +1. 64-bit operating system +2. 64-bit JDK 1.8+ + +::: + +## 1.Pull RocketMQ Image + +Here, we take the RocketMQ 4.9.6 version image from [dockerhub](https://hub.docker.com/r/apache/rocketmq/tags) as an example to introduce the deployment process. + +```shell +docker pull apache/rocketmq:4.9.6 +``` + +## 2.Create a Shared Network for Containers + +RocketMQ involves multiple services and requires multiple containers. Creating a Docker network facilitates communication between containers. + +```shell +docker network create rocketmq +``` + +## 3.Start NameServer + +```shell +# Start NameServer +docker run -d --name rmqnamesrv -p 9876:9876 --net rocketmq apache/rocketmq:4.9.6 sh mqnamesrv + +# Verify if NameServer started successfully +docker logs -f rmqnamesrv +``` + +:::info + +We can see **'The Name Server boot success..',** indicating that the NameServer has started successfully. + +::: + +## 4.Start Broker + +After the NameServer starts successfully, we start the Broker. + + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + + + + +```code +# Configure the broker's IP address +echo "brokerIP1=127.0.0.1" >broker.conf + +# Start Broker +docker run -d \ +--name rmqbroker \ +--net rocketmq \ +-p 10912:10912 -p 10911:10911 -p 10909:10909 \ +-e "NAMESRV_ADDR=rmqnamesrv:9876" \ +-v ./broker.conf:/home/rocketmq/rocketmq-4.9.6/conf/broker.conf \ +apache/rocketmq:4.9.6 sh mqbroker \ +-c /home/rocketmq/rocketmq-4.9.6/conf/broker.conf + +# Verify if Broker started successfully +docker logs rmqbroker +``` + + + +```code +# Configure the broker's IP address +echo "brokerIP1=127.0.0.1" >broker.conf + +# Start Broker +docker run -d ^ +--name rmqbroker ^ +--net rocketmq ^ +-p 10912:10912 -p 10911:10911 -p 10909:10909 ^ +-e "NAMESRV_ADDR=rmqnamesrv:9876" ^ +-v %cd%\broker.conf:/home/rocketmq/rocketmq-4.9.6/conf/broker.conf ^ +apache/rocketmq:4.9.6 sh mqbroker ^ +-c /home/rocketmq/rocketmq-4.9.6/conf/broker.conf + +# Verify if Broker started successfully +docker logs rmqbroker +``` + + + + + + +:::info + +We can see **'The broker boot success..',** indicating that the Broker has started successfully. + +::: + +:::note + +At this point, a single-node replica RocketMQ cluster has been deployed. We can use scripts for simple message sending and receiving. + +::: + +## 5.Send and Receive Messages with Tools + +```shell +# Enter the broker container +$ docker exec -it rmqbroker bash + +$ sh tools.sh org.apache.rocketmq.example.quickstart.Producer + SendResult [sendStatus=SEND_OK, msgId= ... + +$ sh tools.sh org.apache.rocketmq.example.quickstart.Consumer + ConsumeMessageThread_%d Receive New Messages: [MessageExt... +``` + +## 6.Send and Receive Messages with SDK + +After testing with tools, we can try sending and receiving messages using the SDK. Here, we use the Java SDK as an example to introduce the process. + +1. Create a Java project in IDEA. + +2. Add the following dependencies to the *pom.xml* file to introduce the Java library. + + ``` + + org.apache.rocketmq + rocketmq-client + 4.9.6 + + ``` + +3. In the created Java project, create and run a program to send a simple message. Apache RocketMQ can send messages in three ways: **synchronous, asynchronous, and one-way transmission**. Here we use the synchronous mode as an example: + + ```java + import org.apache.rocketmq.client.producer.DefaultMQProducer; + import org.apache.rocketmq.client.producer.SendResult; + import org.apache.rocketmq.common.message.Message; + + public class ProducerExample { + public static void main(String[] args) throws Exception { + // Create producer instance and set the producer group name + DefaultMQProducer producer = new DefaultMQProducer("please_rename_unique_group_name"); + // Set the Name Server address (replace with actual Name Server address) + producer.setNamesrvAddr("localhost:9876"); + producer.start(); + + try { + // Create a message instance, specifying the topic, tag, and message body + Message msg = new Message("TestTopic", "TagA", ("Hello RocketMQ").getBytes()); + // Send the message and get the send result + SendResult sendResult = producer.send(msg); + System.out.println("Message sent: " + new String(msg.getBody())); + System.out.println("Send result: " + sendResult); + } catch (Exception e) { + e.printStackTrace(); + System.out.println("Message sending failed."); + } finally { + // Shutdown the producer + producer.shutdown(); + } + } + } + ``` + +4. In the created Java project, create and run a program to subscribe to simple messages. Apache RocketMQ has two consumption modes: **Push and Pull**. Here we use the Push mode as an example. + + ```java + import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; + import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; + import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; + import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; + import org.apache.rocketmq.common.message.MessageExt; + + import java.util.List; + + public class ConsumerExample { + public static void main(String[] args) throws Exception { + // Create consumer instance and set the consumer group name + DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("please_rename_unique_group_name"); + // Set the Name Server address (replace with actual Name Server address) + consumer.setNamesrvAddr("localhost:9876"); + // Subscribe to the specified topic and tag (* means all tags) + consumer.subscribe("TestTopic", "*"); + + // Register message listener + consumer.registerMessageListener(new MessageListenerConcurrently() { + @Override + public ConsumeConcurrentlyStatus consumeMessage(List msgs, ConsumeConcurrentlyContext context) { + for (MessageExt msg : msgs) { + System.out.println("Received message: " + new String(msg.getBody())); + } + return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; + } + }); + + // Start the consumer + consumer.start(); + System.out.println("Consumer started."); + } + } + ``` + + +## 7.Stop the Containers +After completing the experiment, we can stop the containers as follows: +```shell +# Stop the NameServer container +docker stop rmqnamesrv + +# Stop the Broker container +docker stop rmqbroker ``` \ No newline at end of file diff --git a/i18n/en/docusaurus-plugin-content-docs/current/01-introduction/02quickstartWithDockercompose.md b/i18n/en/docusaurus-plugin-content-docs/current/01-quickstart/03quickstartWithDockercompose.md similarity index 100% rename from i18n/en/docusaurus-plugin-content-docs/current/01-introduction/02quickstartWithDockercompose.md rename to i18n/en/docusaurus-plugin-content-docs/current/01-quickstart/03quickstartWithDockercompose.md diff --git a/i18n/en/docusaurus-plugin-content-docs/version-5.0/02-quickStart/03quickstartWithDockercompose.md b/i18n/en/docusaurus-plugin-content-docs/version-5.0/02-quickStart/03quickstartWithDockercompose.md index e1c1c9b82e..2eb74c72a5 100644 --- a/i18n/en/docusaurus-plugin-content-docs/version-5.0/02-quickStart/03quickstartWithDockercompose.md +++ b/i18n/en/docusaurus-plugin-content-docs/version-5.0/02-quickStart/03quickstartWithDockercompose.md @@ -66,14 +66,18 @@ import TabItem from '@theme/TabItem'; -```shell + +```code docker-compose up -d ``` + -```shell + +```code docker-compose -p rockermq_project up -d ``` + diff --git a/versioned_docs/version-5.0/02-quickStart/03quickstartWithDockercompose.md b/versioned_docs/version-5.0/02-quickStart/03quickstartWithDockercompose.md index d2c96ab810..bd815a4e52 100644 --- a/versioned_docs/version-5.0/02-quickStart/03quickstartWithDockercompose.md +++ b/versioned_docs/version-5.0/02-quickStart/03quickstartWithDockercompose.md @@ -66,14 +66,18 @@ import TabItem from '@theme/TabItem'; -```shell + +```code docker-compose up -d ``` + -```shell + +```code docker-compose -p rockermq_project up -d ``` +