From 467d6e8d0c8098819391bf636c7612480adab9a5 Mon Sep 17 00:00:00 2001 From: RongtongJin Date: Fri, 30 Aug 2024 10:48:55 +0800 Subject: [PATCH] Add English version of quick start --- ...md => 04quickstartWithHelmInKubernetes.md} | 4 +- .../04quickstartWithHelmInKubernetes.md | 95 ++++++++ .../04quickstartWithHelmInKubernetes.md | 204 ++++++++++++++++++ .../04quickstartWithHelmInKubernetes.md | 12 +- 4 files changed, 309 insertions(+), 6 deletions(-) rename docs/01-quickstart/{04quickstartWithHelmInKubernetes-4.x.md => 04quickstartWithHelmInKubernetes.md} (99%) create mode 100644 i18n/en/docusaurus-plugin-content-docs/current/01-quickstart/04quickstartWithHelmInKubernetes.md create mode 100644 i18n/en/docusaurus-plugin-content-docs/version-5.0/02-quickStart/04quickstartWithHelmInKubernetes.md diff --git a/docs/01-quickstart/04quickstartWithHelmInKubernetes-4.x.md b/docs/01-quickstart/04quickstartWithHelmInKubernetes.md similarity index 99% rename from docs/01-quickstart/04quickstartWithHelmInKubernetes-4.x.md rename to docs/01-quickstart/04quickstartWithHelmInKubernetes.md index 8c913674bd..749a4834e0 100644 --- a/docs/01-quickstart/04quickstartWithHelmInKubernetes-4.x.md +++ b/docs/01-quickstart/04quickstartWithHelmInKubernetes.md @@ -3,12 +3,14 @@ 这一节介绍如何在 Kubernetes 环境下,使⽤ Helm 快速部署⼀个单节点 RocketMQ-4.x 版本的服务,并完成简单的消息收发。 -## 系统要求 +:::tip 系统要求 - 一个运行中的 `Kubernetes` 集群 - 已安装的 `Helm 3.7.0+` - 64位 `JDK 1.8+` +::: + ## 1.安装 Helm diff --git a/i18n/en/docusaurus-plugin-content-docs/current/01-quickstart/04quickstartWithHelmInKubernetes.md b/i18n/en/docusaurus-plugin-content-docs/current/01-quickstart/04quickstartWithHelmInKubernetes.md new file mode 100644 index 0000000000..e801ad8267 --- /dev/null +++ b/i18n/en/docusaurus-plugin-content-docs/current/01-quickstart/04quickstartWithHelmInKubernetes.md @@ -0,0 +1,95 @@ +# Run RocketMQ with Kubernetes + +This section describes how to quickly deploy a single-node RocketMQ 4.x service in a Kubernetes and perform simple message sending and receiving. + + +:::tip SYSTEM REQUIREMENTS + +- A running Kubernetes cluster +- Installed Helm 3.7.0+ +- 64-bit JDK 1.8+ + +::: + + +## 1.Install Helm + +Make sure Helm is installed on your system: + +```bash +$ helm version +``` + +If Helm (version 3.7.0 or above) is not installed, you can install it using the following command: + +```bash +$ curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash +``` + + + +## 2.Download RocketMQ Helm Chart + +```bash +$ helm pull oci://registry-1.docker.io/apache/rocketmq --version 0.0.1 +$ tar -zxvf rocketmq-0.0.1.tgz +``` + + +## 3.Deploy RocketMQ + +Use the Helm chart to deploy RocketMQ. + +```yaml +# Modify the configuration in values.yaml (adjust relevant configuration information according to actual needs, such as image version, resource size, number of replicas, etc., while disabling proxy and controller features) +$ vim values.yaml +## In values.yaml, modify parameters such as limits and requests in broker's resources to suitable sizes, and change the image tag to 4.9.6 ## + resources: + limits: + cpu: 2 + memory: 10Gi + requests: + cpu: 2 + memory: 10Gi +##values.yaml## +``` + +```bash +$ helm install rocketmq-demo ./rocketmq +# Check pod status +# If the parameters are normal, it indicates successful deployment +$ kubectl get pods -o wide -n default +NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES +default rocketmq-demo-broker-0 0/1 Running 0 19s 192.168.58.228 k8s-node02 +default rocketmq-demo-nameserver-6678bb86f6-62s5d 0/1 Running 0 19s 192.168.85.229 k8s-node01 +``` + + +## 4.Validate Message Sending and Receiving + +Use tools to test and validate message sending and receiving. + +``` bash +# Log into the pod (requires management tools), or you can execute on the host +$ kubectl exec -ti rocketmq-demo-broker-0 -- /bin/bash + +# Create Topic via mqadmin +$ sh mqadmin updatetopic -t TopicTest -c DefaultCluster + +# Send message (execute within the pod) +$ sh tools.sh org.apache.rocketmq.example.quickstart.Producer +SendResult [sendStatus=SEND_OK, msgId=7F00000100E60F6F4D334B52982103E7, offsetMsgId=C0A83AE400002A9F000000000002ECD2, messageQueue=MessageQueue [topic=TopicTest, brokerName=rocketmq-demo-broker-0, queueId=2], queueOffset=124] + +# Receive message (execute within the pod) +$ sh tools.sh org.apache.rocketmq.example.quickstart.Consumer +ConsumeMessageThread_please_rename_unique_group_name_4_16 Receive New Messages: [MessageExt [brokerName=rocketmq-demo-broker-0, queueId=2, storeSize=192, queueOffset=124, sysFlag=0, bornTimestamp=1723734104097, bornHost=/192.168.58.228:40492, storeTimestamp=1723734104097, storeHost=/192.168.58.228:10911, msgId=C0A83AE400002A9F000000000002ECD2, commitLogOffset=191698, bodyCRC=638172955, reconsumeTimes=0, preparedTransactionOffset=0, toString()=Message{topic='TopicTest', flag=0, properties={MIN_OFFSET=0, MAX_OFFSET=125, CONSUME_START_TIME=1723734158990, UNIQ_KEY=7F00000100E60F6F4D334B52982103E7, CLUSTER=DefaultCluster, TAGS=TagA}, body=[72, 101, 108, 108, 111, 32, 82, 111, 99, 107, 101, 116, 77, 81, 32, 57, 57, 57], transactionId='null'}]] +``` + + +## 5.Release RocketMQ Resources + +```bash +#Release all RocketMQ resources +$ helm uninstall rocketmq-demo +``` + diff --git a/i18n/en/docusaurus-plugin-content-docs/version-5.0/02-quickStart/04quickstartWithHelmInKubernetes.md b/i18n/en/docusaurus-plugin-content-docs/version-5.0/02-quickStart/04quickstartWithHelmInKubernetes.md new file mode 100644 index 0000000000..1b3ecf4310 --- /dev/null +++ b/i18n/en/docusaurus-plugin-content-docs/version-5.0/02-quickStart/04quickstartWithHelmInKubernetes.md @@ -0,0 +1,204 @@ +# Run RocketMQ with Kubernetes + +This section describes how to quickly deploy a single-node RocketMQ 5.x service in a Kubernetes and perform simple message sending and receiving. + + +:::tip SYSTEM REQUIREMENTS + +- A running Kubernetes cluster +- Installed Helm 3.7.0+ +- 64-bit JDK 1.8+ + +::: + + +## 1.Install Helm + +Make sure Helm is installed on your system: + +```bash +$ helm version +``` + +If Helm (version 3.7.0 or above) is not installed, you can install it using the following command: + +```bash +$ curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash +``` + + + +## 2.Download RocketMQ Helm Chart + +```bash +$ helm pull oci://registry-1.docker.io/apache/rocketmq --version 0.0.1 +$ tar -zxvf rocketmq-0.0.1.tgz +``` + + +## 3.Deploy RocketMQ + +Use the Helm chart to deploy RocketMQ. + +```yaml +# Modify the configuration in values.yaml +$ vim values.yaml +## values.yaml, adjust memory requests and limits in broker resources according to available memory size ## + resources: + limits: + cpu: 2 + memory: 10Gi + requests: + cpu: 2 + memory: 10Gi +##values.yaml## +``` + +```bash +$ helm install rocketmq-demo ./rocketmq +# Check pod status +# If the parameters are normal, it indicates successful deployment +$ kubectl get pods -o wide -n default +NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES +rocketmq-demo-broker-0 1/1 Running 0 6h3m 192.168.58.225 k8s-node02 +rocketmq-demo-nameserver-757877747b-k669k 1/1 Running 0 6h3m 192.168.58.226 k8s-node02 +rocketmq-demo-proxy-6c569bd457-wcg6g 1/1 Running 0 6h3m 192.168.85.227 k8s-node01 +``` + + +## 4.Validate Message Sending and Receiving + +Use the JAVA SDK to test message sending and receiving (since the local network and the k8s network are not on the same internal network, you need to package the project locally and run it remotely. After packaging, copy the jar file from the target directory to the target server and execute java -jar jar file name). The specifics are as follows: + +1)Create a Java project in IDE. + +2)Add the following dependency to the pom.xml file to import the Java library: +```xml + ...... + + org.apache.rocketmq + rocketmq-client-java + 5.0.7 + + ..... +``` +3)Log into the pod (management tools are needed), or it can also be executed on the host +```bash +# Log into the pod +$ kubectl exec -ti rocketmq-demo-broker-0 -- /bin/bash + +# Create Topic using mqadmin tools +$ sh mqadmin updatetopic -t TestTopic -c DefaultCluster + +# Create subscription group using mqadmin tools +$ sh mqadmin updateSubGroup -c DefaultCluster -g TestGroup +``` +4)In the created Java project, create a program to send normal messages (ProducerDemo.java); the sample code is as follows: + +```java +package com.rocketmq.producer; + +import org.apache.rocketmq.client.apis.ClientConfiguration; +import org.apache.rocketmq.client.apis.ClientConfigurationBuilder; +import org.apache.rocketmq.client.apis.ClientException; +import org.apache.rocketmq.client.apis.ClientServiceProvider; +import org.apache.rocketmq.client.apis.message.Message; +import org.apache.rocketmq.client.apis.producer.Producer; +import org.apache.rocketmq.client.apis.producer.SendReceipt; + +public class ProducerDemo { + public static void main(String[] args) throws ClientException { + // The endpoint address, which needs to be set to the address and port list of the Proxy; the following is the proxy address in the k8s environment. + String endpoint = "192.168.85.227:8081"; + // The target Topic name for sending messages, which needs to be created in advance. + String topic = "TestTopic"; + ClientServiceProvider provider = ClientServiceProvider.loadService(); + ClientConfigurationBuilder builder = ClientConfiguration.newBuilder().setEndpoints(endpoint); + ClientConfiguration configuration = builder.build(); + // When initializing the Producer, communication configuration and pre-bound Topic need to be set. + Producer producer = provider.newProducerBuilder() + .setTopics(topic) + .setClientConfiguration(configuration) + .build(); + // Sending normal messages. + Message message = provider.newMessageBuilder() + .setTopic(topic) + // Set message index key for precise search of a specific message. + .setKeys("messageKey") + // Set message Tag for filtering messages based on specific tags on the consumer side. + .setTag("messageTag") + // Message body. + .setBody("messageBody".getBytes()) + .build(); + try { + // Send the message, you need to pay attention to the sending result and handle failures and other exceptions. + SendReceipt sendReceipt = producer.send(message); + System.out.println("Send message successfully, messageId=" + sendReceipt.getMessageId()); + } catch (ClientException e) { + } + // producer.close(); + } +} +``` + +5)In the created Java project, create a program to subscribe to normal messages (Consumer.java). Apache RocketMQ supports [SimpleConsumer](https://rocketmq.apache.org/zh/docs/featureBehavior/06consumertype) and [PushConsumer](https://rocketmq.apache.org/zh/docs/featureBehavior/06consumertype), here we use the PushConsumer. + +```java + +package com.rocketmq.consumer; + +import java.io.IOException; +import java.util.Collections; +import org.apache.rocketmq.client.apis.ClientConfiguration; +import org.apache.rocketmq.client.apis.ClientException; +import org.apache.rocketmq.client.apis.ClientServiceProvider; +import org.apache.rocketmq.client.apis.consumer.ConsumeResult; +import org.apache.rocketmq.client.apis.consumer.FilterExpression; +import org.apache.rocketmq.client.apis.consumer.FilterExpressionType; +import org.apache.rocketmq.client.apis.consumer.PushConsumer; +import java.util.List; + +public class Consumer { + public static void main(String[] args) throws ClientException, IOException, InterruptedException { + final ClientServiceProvider provider = ClientServiceProvider.loadService(); + // The endpoint address, which needs to be set to the address and port list of the Proxy; the following is the proxy address in the k8s environment. + String endpoints = "192.168.85.227:8081"; + ClientConfiguration clientConfiguration = ClientConfiguration.newBuilder() + .setEndpoints(endpoints) + .build(); + // The filter rule for subscribing to messages, indicating subscription to messages of all Tags. + String tag = "*"; + FilterExpression filterExpression = new FilterExpression(tag, FilterExpressionType.TAG); + // Specify the consumer group to which the consumer belongs; the Group needs to be created in advance. + String consumerGroup = "TestGroup"; + // Specify which target Topic needs to be subscribed to; the Topic needs to be created in advance. + String topic = "TestTopic"; + // Initialize PushConsumer, binding to the consumer group ConsumerGroup, communication parameters, and subscription relationship. + PushConsumer pushConsumer = provider.newPushConsumerBuilder() + .setClientConfiguration(clientConfiguration) + // Set consumer group. + .setConsumerGroup(consumerGroup) + // Set pre-bound subscription relationship. + .setSubscriptionExpressions(Collections.singletonMap(topic, filterExpression)) + // Set consumption listener. + .setMessageListener(messageView -> { + // Process the message and return the consumption result. + System.out.println("Consume message successfully, messageId=" + messageView.getMessageId()); + return ConsumeResult.SUCCESS; + }) + .build(); + Thread.sleep(Long.MAX_VALUE); + // If you don't need to use PushConsumer anymore, you can close this instance. + // pushConsumer.close(); + } +} + +``` + +## 5.Release RocketMQ Resources + +```bash +#Release all RocketMQ resources +$ helm uninstall rocketmq-demo +``` + diff --git a/versioned_docs/version-5.0/02-quickStart/04quickstartWithHelmInKubernetes.md b/versioned_docs/version-5.0/02-quickStart/04quickstartWithHelmInKubernetes.md index 82854d906d..54d1c955dd 100644 --- a/versioned_docs/version-5.0/02-quickStart/04quickstartWithHelmInKubernetes.md +++ b/versioned_docs/version-5.0/02-quickStart/04quickstartWithHelmInKubernetes.md @@ -1,12 +1,14 @@ # Kubernetes 部署 RocketMQ 本文介绍在 Kubernetes 环境下如何使用 Helm 快速部署一个单节点 RocketMQ-5.X 版本的服务,并完成简单的消息收发。 -## 前提条件 +:::tip 系统要求 - 一个运行中的 `Kubernetes` 集群 - 已安装的 `Helm 3.7.0+ ` - 64位 `JDK 1.8+` +::: + ## 1.安装 Helm 确保你的系统上已经安装了 Helm: @@ -71,15 +73,15 @@ rocketmq-demo-proxy-6c569bd457-wcg6g 1/1 Running 3 (6h2m ago) 6h3 ..... ``` -3)使用 mqadmin 创建 Topic和消费者。 +3)使用 mqadmin 工具创建 Topic和消费者。 ```bash -#登录pod内(需要管理工具),也可以在宿主机执行 +# 登录pod内行 $ kubectl exec -ti rocketmq-demo-broker-0 -- /bin/bash -#通过mqadmin创建Topic +# 通过 mqadmin 创建 Topic $ sh mqadmin updatetopic -t TestTopic -c DefaultCluster -#通过mqadmin创建消费者Group +# 通过 mqadmin 创建订阅组 $ sh mqadmin updateSubGroup -c DefaultCluster -g TestGroup ``` 4)在已创建的Java工程中,创建发送普通消息程序 (ProducerDemo.java),示例代码如下: