### Start RocketMQ Producer and Consumer Examples Source: https://github.com/apache/rocketmq-site/blob/new-official-website/i18n/en/docusaurus-plugin-content-docs/version-5.0/10-connect/07RocketMQ Connect In Action4.md These commands demonstrate how to start the RocketMQ producer and consumer example tools to test message sending and receiving. Ensure the NAMESRV_ADDR environment variable is set to your RocketMQ NameServer address. ```shell #$ cd distribution/target/rocketmq-4.9.7/rocketmq-4.9.7 $ cd distribution/target/rocketmq-5.1.4/rocketmq-5.1.4 $ 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... ``` -------------------------------- ### MQTT Client Examples Source: https://github.com/apache/rocketmq-site/blob/new-official-website/versioned_docs/version-5.0/08-mqtt/02RocketMQMQTTQuickStart.md Java code examples demonstrating how to implement MQTT clients for publishing and subscribing to messages using RocketMQ MQTT. ```java MqttConsumer.java // MQTT客户端启动订阅消息 MqttProducer.java // MQTT客户端启动发布消息 ``` -------------------------------- ### PushConsumer Example C++ Source: https://github.com/apache/rocketmq-site/blob/new-official-website/i18n/en/docusaurus-plugin-content-docs/version-5.0/13-sdk/03cplusplus.md Example demonstrating message consumption using the PushConsumer with the C++ gRPC SDK. Refer to the rocketmq-clients repository for full project details and runtime environment setup. ```cpp #include "../src/Producer.h" #include "../src/Message.h" #include "../src/MQAdminExt.h" #include "../src/MQClient.h" #include "../src/MQProducer.h" #include "../src/MQConsumer.h" #include "../src/DefaultMQProducer.h" #include "../src/DefaultMQPushConsumer.h" #include "../src/DefaultMQSimpleConsumer.h" #include "../src/MessageQueue.h" #include "../src/SendResult.h" #include "../src/TransactionResolution.h" #include "../src/MQAdminExtImpl.h" #include "../src/MQClientImpl.h" #include "../src/MQProducerImpl.h" #include "../src/MQConsumerImpl.h" #include "../src/DefaultMQProducerImpl.h" #include "../src/DefaultMQPushConsumerImpl.h" #include "../src/DefaultMQSimpleConsumerImpl.h" #include "../src/MessageQueueImpl.h" #include "../src/SendResultImpl.h" #include "../src/TransactionResolutionImpl.h" #include "../src/MQAdminExt.h" #include "../src/MQClient.h" #include "../src/MQProducer.h" #include "../src/MQConsumer.h" #include "../src/DefaultMQProducer.h" #include "../src/DefaultMQPushConsumer.h" #include "../src/DefaultMQSimpleConsumer.h" #include "../src/MessageQueue.h" #include "../src/SendResult.h" #include "../src/TransactionResolution.h" #include "../src/MQAdminExtImpl.h" #include "../src/MQClientImpl.h" #include "../src/MQProducerImpl.h" #include "../src/MQConsumerImpl.h" #include "../src/DefaultMQProducerImpl.h" #include "../src/DefaultMQPushConsumerImpl.h" #include "../src/DefaultMQSimpleConsumerImpl.h" #include "../src/MessageQueueImpl.h" #include "../src/SendResultImpl.h" #include "../src/TransactionResolutionImpl.h" #include #include #include #include #include using namespace std; using namespace rocketmq; int main() { // Please refer to https://github.com/apache/rocketmq-clients/blob/master/cpp/examples/ExamplePushConsumer.cpp return 0; } ``` -------------------------------- ### SimpleConsumer Example C++ Source: https://github.com/apache/rocketmq-site/blob/new-official-website/i18n/en/docusaurus-plugin-content-docs/version-5.0/13-sdk/03cplusplus.md Example demonstrating message consumption using the SimpleConsumer with the C++ gRPC SDK. Refer to the rocketmq-clients repository for full project details and runtime environment setup. ```cpp #include "../src/Producer.h" #include "../src/Message.h" #include "../src/MQAdminExt.h" #include "../src/MQClient.h" #include "../src/MQProducer.h" #include "../src/MQConsumer.h" #include "../src/DefaultMQProducer.h" #include "../src/DefaultMQPushConsumer.h" #include "../src/DefaultMQSimpleConsumer.h" #include "../src/MessageQueue.h" #include "../src/SendResult.h" #include "../src/TransactionResolution.h" #include "../src/MQAdminExtImpl.h" #include "../src/MQClientImpl.h" #include "../src/MQProducerImpl.h" #include "../src/MQConsumerImpl.h" #include "../src/DefaultMQProducerImpl.h" #include "../src/DefaultMQPushConsumerImpl.h" #include "../src/DefaultMQSimpleConsumerImpl.h" #include "../src/MessageQueueImpl.h" #include "../src/SendResultImpl.h" #include "../src/TransactionResolutionImpl.h" #include "../src/MQAdminExt.h" #include "../src/MQClient.h" #include "../src/MQProducer.h" #include "../src/MQConsumer.h" #include "../src/DefaultMQProducer.h" #include "../src/DefaultMQPushConsumer.h" #include "../src/DefaultMQSimpleConsumer.h" #include "../src/MessageQueue.h" #include "../src/SendResult.h" #include "../src/TransactionResolution.h" #include "../src/MQAdminExtImpl.h" #include "../src/MQClientImpl.h" #include "../src/MQProducerImpl.h" #include "../src/MQConsumerImpl.h" #include "../src/DefaultMQProducerImpl.h" #include "../src/DefaultMQPushConsumerImpl.h" #include "../src/DefaultMQSimpleConsumerImpl.h" #include "../src/MessageQueueImpl.h" #include "../src/SendResultImpl.h" #include "../src/TransactionResolutionImpl.h" #include #include #include #include #include using namespace std; using namespace rocketmq; int main() { // Please refer to https://github.com/apache/rocketmq-clients/blob/master/cpp/examples/ExampleSimpleConsumer.cpp return 0; } ``` -------------------------------- ### Start RocketMQ Broker (Single Node, Single Replica) Source: https://github.com/apache/rocketmq-site/blob/new-official-website/i18n/en/docusaurus-plugin-content-docs/version-5.0/05-deploymentOperations/01deploy.md Starts a single RocketMQ broker in a single-node, single-replica mode. This setup is not recommended for production due to its high risk of service unavailability if the broker restarts or goes down. It is primarily intended for local testing purposes. ```bash nohup sh bin/mqbroker -n 192.168.1.1:9876 & ``` -------------------------------- ### Start RocketMQ Components Source: https://github.com/apache/rocketmq-site/blob/new-official-website/versioned_docs/version-5.0/05-deploymentOperations/03autofailover.md Shell commands to start NameServer, Controller, and Broker components using configuration files. ```shell $ nohup sh bin/mqnamesrv -c namesrv.conf & $ nohup sh bin/mqcontroller -c controller.conf & $ nohup sh bin/mqbroker -c broker.conf & ``` -------------------------------- ### RocketMQ Client Examples Source: https://github.com/apache/rocketmq-site/blob/new-official-website/versioned_docs/version-5.0/08-mqtt/02RocketMQMQTTQuickStart.md Java code examples showing how to implement RocketMQ clients for publishing and subscribing to messages directly via RocketMQ. ```java RocketMQConsumer.java //RocketMQ客户端启动订阅消息 RocketMQProducer.java // RocketMQ客户端启动发布消息 ``` -------------------------------- ### Sync Send Example Producer C++ Source: https://github.com/apache/rocketmq-site/blob/new-official-website/i18n/en/docusaurus-plugin-content-docs/version-5.0/13-sdk/03cplusplus.md Example demonstrating synchronous message sending using the C++ gRPC SDK. Refer to the rocketmq-clients repository for full project details and runtime environment setup. ```cpp #include "../src/Producer.h" #include "../src/Message.h" #include "../src/MQAdminExt.h" #include "../src/MQClient.h" #include "../src/MQProducer.h" #include "../src/MQConsumer.h" #include "../src/DefaultMQProducer.h" #include "../src/DefaultMQPushConsumer.h" #include "../src/DefaultMQSimpleConsumer.h" #include "../src/MessageQueue.h" #include "../src/SendResult.h" #include "../src/TransactionResolution.h" #include "../src/MQAdminExtImpl.h" #include "../src/MQClientImpl.h" #include "../src/MQProducerImpl.h" #include "../src/MQConsumerImpl.h" #include "../src/DefaultMQProducerImpl.h" #include "../src/DefaultMQPushConsumerImpl.h" #include "../src/DefaultMQSimpleConsumerImpl.h" #include "../src/MessageQueueImpl.h" #include "../src/SendResultImpl.h" #include "../src/TransactionResolutionImpl.h" #include "../src/MQAdminExt.h" #include "../src/MQClient.h" #include "../src/MQProducer.h" #include "../src/MQConsumer.h" #include "../src/DefaultMQProducer.h" #include "../src/DefaultMQPushConsumer.h" #include "../src/DefaultMQSimpleConsumer.h" #include "../src/MessageQueue.h" #include "../src/SendResult.h" #include "../src/TransactionResolution.h" #include "../src/MQAdminExtImpl.h" #include "../src/MQClientImpl.h" #include "../src/MQProducerImpl.h" #include "../src/MQConsumerImpl.h" #include "../src/DefaultMQProducerImpl.h" #include "../src/DefaultMQPushConsumerImpl.h" #include "../src/DefaultMQSimpleConsumerImpl.h" #include "../src/MessageQueueImpl.h" #include "../src/SendResultImpl.h" #include "../src/TransactionResolutionImpl.h" #include #include #include #include #include using namespace std; using namespace rocketmq; int main() { // Please refer to https://github.com/apache/rocketmq-clients/blob/master/cpp/examples/ExampleProducer.cpp return 0; } ``` -------------------------------- ### Start MySQL Docker Container Source: https://github.com/apache/rocketmq-site/blob/new-official-website/i18n/en/docusaurus-plugin-content-docs/version-5.0/10-connect/05RocketMQ Connect In Action2.md Start a MySQL instance using Docker. This container will serve as the sink for the data. ```bash docker run -it --rm --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=debezium -e MYSQL_USER=mysqluser -e MYSQL_PASSWORD=mysqlpw quay.io/debezium/example-mysql:1.9 ``` -------------------------------- ### Start RocketMQ Broker (Single Master) Source: https://github.com/apache/rocketmq-site/blob/new-official-website/versioned_docs/version-5.0/05-deploymentOperations/01deploy.md This command starts a single RocketMQ broker instance. It requires the NameServer address and a configuration file path. Ensure the ROCKETMQ_HOME environment variable is set. ```bash nohup sh bin/mqbroker -n 192.168.1.1:9876 -c $ROCKETMQ_HOME/conf/2m-noslave/broker-a.properties & ``` ```bash nohup sh bin/mqbroker -n 192.168.1.1:9876 -c $ROCKETMQ_HOME/conf/2m-noslave/broker-b.properties & ``` -------------------------------- ### Producer with FIFO Message Example C++ Source: https://github.com/apache/rocketmq-site/blob/new-official-website/i18n/en/docusaurus-plugin-content-docs/version-5.0/13-sdk/03cplusplus.md Example demonstrating sending FIFO (First-In, First-Out) messages using the C++ gRPC SDK. Refer to the rocketmq-clients repository for full project details and runtime environment setup. ```cpp #include "../src/Producer.h" #include "../src/Message.h" #include "../src/MQAdminExt.h" #include "../src/MQClient.h" #include "../src/MQProducer.h" #include "../src/MQConsumer.h" #include "../src/DefaultMQProducer.h" #include "../src/DefaultMQPushConsumer.h" #include "../src/DefaultMQSimpleConsumer.h" #include "../src/MessageQueue.h" #include "../src/SendResult.h" #include "../src/TransactionResolution.h" #include "../src/MQAdminExtImpl.h" #include "../src/MQClientImpl.h" #include "../src/MQProducerImpl.h" #include "../src/MQConsumerImpl.h" #include "../src/DefaultMQProducerImpl.h" #include "../src/DefaultMQPushConsumerImpl.h" #include "../src/DefaultMQSimpleConsumerImpl.h" #include "../src/MessageQueueImpl.h" #include "../src/SendResultImpl.h" #include "../src/TransactionResolutionImpl.h" #include "../src/MQAdminExt.h" #include "../src/MQClient.h" #include "../src/MQProducer.h" #include "../src/MQConsumer.h" #include "../src/DefaultMQProducer.h" #include "../src/DefaultMQPushConsumer.h" #include "../src/DefaultMQSimpleConsumer.h" #include "../src/MessageQueue.h" #include "../src/SendResult.h" #include "../src/TransactionResolution.h" #include "../src/MQAdminExtImpl.h" #include "../src/MQClientImpl.h" #include "../src/MQProducerImpl.h" #include "../src/MQConsumerImpl.h" #include "../src/DefaultMQProducerImpl.h" #include "../src/DefaultMQPushConsumerImpl.h" #include "../src/DefaultMQSimpleConsumerImpl.h" #include "../src/MessageQueueImpl.h" #include "../src/SendResultImpl.h" #include "../src/TransactionResolutionImpl.h" #include #include #include #include #include using namespace std; using namespace rocketmq; int main() { // Please refer to https://github.com/apache/rocketmq-clients/blob/master/cpp/examples/ExampleProducerWithFifoMessage.cpp return 0; } ``` -------------------------------- ### Start RocketMQ MQTT Services Source: https://github.com/apache/rocketmq-site/blob/new-official-website/versioned_docs/version-5.0/08-mqtt/02RocketMQMQTTQuickStart.md Commands to start the meta service (metadata center) and the MQTT broker. These services are crucial for the MQTT functionality. ```bash sh meta.sh start sh mqtt.sh start ``` -------------------------------- ### Start RocketMQ Proxy Source: https://github.com/apache/rocketmq-site/blob/new-official-website/versioned_docs/version-5.0/05-deploymentOperations/01deploy.md This command starts a RocketMQ proxy instance. It requires the NameServer address. Multiple proxy instances can be started on different machines for scalability. ```shell nohup sh bin/mqproxy -n 192.168.1.1:9876 & ``` ```shell nohup sh bin/mqproxy -n 192.168.1.1:9876 & ``` ```shell nohup sh bin/mqproxy -n 192.168.1.1:9876 & ``` -------------------------------- ### Start RocketMQ Cluster on Windows Source: https://github.com/apache/rocketmq-site/blob/new-official-website/i18n/en/docusaurus-plugin-content-docs/version-5.0/02-quickStart/03quickstartWithDockercompose.md Use this command to start all services defined in your docker-compose.yml file with a project name on a Windows system. ```bash docker-compose -p rocketmq_project up -d ``` -------------------------------- ### Start SFTP Source Connector Source: https://github.com/apache/rocketmq-site/blob/new-official-website/i18n/en/docusaurus-plugin-content-docs/version-5.0/10-connect/07RocketMQ Connect In Action4.md Use this command to start the SFTP source connector. It reads data from a specified file and sends it to a RocketMQ topic. Ensure the connector class and connection details are correctly configured. ```shell curl -X POST --location "http://localhost:8082/connectors/SftpSourceConnector" --http1.1 \ -H "Host: localhost:8082" \ -H "Content-Type: application/json" \ -d '{ "connector.class": "org.apache.rocketmq.connect.http.sink.SftpSourceConnector", "host": "127.0.0.1", "port": 22, "username": "YourUsername", "password": "yourPassword", "filePath": "/Users/YourUsername/rocketmqconnect/sftp-test/source.txt", "connect.topicname": "sftpTopic", "fieldSeparator": "|", "fieldSchema": "username|idCardNo|orderNo|orderAmount|trxDate|trxTime|profit" }' ``` -------------------------------- ### Start RocketMQ Broker (Multi-Master Sync Dual-Write) Source: https://github.com/apache/rocketmq-site/blob/new-official-website/versioned_docs/version-5.0/05-deploymentOperations/01deploy.md This command starts RocketMQ brokers in a multi-master cluster using synchronous dual-write for HA. Each master has a slave, and a successful write requires confirmation from both. The NameServer address and configuration files are specified. ```bash nohup sh bin/mqbroker -n 192.168.1.1:9876 -c $ROCKETMQ_HOME/conf/2m-2s-sync/broker-a.properties & ``` ```bash nohup sh bin/mqbroker -n 192.168.1.1:9876 -c $ROCKETMQ_HOME/conf/2m-2s-sync/broker-b.properties & ``` ```bash nohup sh bin/mqbroker -n 192.168.1.1:9876 -c $ROCKETMQ_HOME/conf/2m-2s-sync/broker-a-s.properties & ``` ```bash nohup sh bin/mqbroker -n 192.168.1.1:9876 -c $ROCKETMQ_HOME/conf/2m-2s-sync/broker-b-s.properties & ``` -------------------------------- ### Start RocketMQ Broker (Multi-Master Async Replication) Source: https://github.com/apache/rocketmq-site/blob/new-official-website/versioned_docs/version-5.0/05-deploymentOperations/01deploy.md This command starts RocketMQ brokers in a multi-master cluster with asynchronous replication. Each master is paired with a slave. The NameServer address is provided, along with specific configuration files for master and slave instances. ```bash nohup sh bin/mqbroker -n 192.168.1.1:9876 -c $ROCKETMQ_HOME/conf/2m-2s-async/broker-a.properties & ``` ```bash nohup sh bin/mqbroker -n 192.168.1.1:9876 -c $ROCKETMQ_HOME/conf/2m-2s-async/broker-b.properties & ``` ```bash nohup sh bin/mqbroker -n 192.168.1.1:9876 -c $ROCKETMQ_HOME/conf/2m-2s-async/broker-a-s.properties & ``` ```bash nohup sh bin/mqbroker -n 192.168.1.1:9876 -c $ROCKETMQ_HOME/conf/2m-2s-async/broker-b-s.properties & ``` -------------------------------- ### Start RocketMQ NameServer Source: https://github.com/apache/rocketmq-site/blob/new-official-website/i18n/en/docusaurus-plugin-content-docs/version-5.0/05-deploymentOperations/01deploy.md Starts the RocketMQ NameServer, which is the entry point for all brokers and clients. It manages the metadata of the cluster. The command uses 'nohup' to run in the background and redirects output to a log file for verification. ```bash nohup sh mqnamesrv & tail -f ~/logs/rocketmqlogs/namesrv.log ``` -------------------------------- ### Start SFTP Sink Connector Source: https://github.com/apache/rocketmq-site/blob/new-official-website/i18n/en/docusaurus-plugin-content-docs/version-5.0/10-connect/07RocketMQ Connect In Action4.md Use this command to start the SFTP sink connector. It subscribes to a RocketMQ topic, consumes messages, and writes them to a destination file via SFTP. Configure the connector class and connection details appropriately. ```shell curl -X POST --location "http://localhost:8082/connectors/SftpSinkConnector" --http1.1 \ -H "Host: localhost:8082" \ -H "Content-Type: application/json" \ -d '{ "connector.class": "org.apache.rocketmq.connect.http.sink.SftpSinkConnector", "host": "127.0.0.1", "port": 22, "username": "YourUsername", "password": "yourPassword", "filePath": "/Users/YourUsername/rocketmqconnect/sftp-test/sink.txt", "connect.topicnames": "sftpTopic", "fieldSeparator": "|", "fieldSchema": "username|idCardNo|orderNo|orderAmount|trxDate|trxTime|profit" }' ``` -------------------------------- ### Start and verify NameServer Source: https://github.com/apache/rocketmq-site/blob/new-official-website/i18n/en/docusaurus-plugin-content-docs/version-5.0/02-quickStart/01quickstart.md Launch the NameServer process and monitor the logs to confirm successful startup. ```shell ### start namesrv $ nohup sh bin/mqnamesrv & ### verify namesrv $ tail -f ~/logs/rocketmqlogs/namesrv.log The Name Server boot success... ``` -------------------------------- ### Producer with Transactional Message Example C++ Source: https://github.com/apache/rocketmq-site/blob/new-official-website/i18n/en/docusaurus-plugin-content-docs/version-5.0/13-sdk/03cplusplus.md Example demonstrating sending transactional messages using the C++ gRPC SDK. Refer to the rocketmq-clients repository for full project details and runtime environment setup. ```cpp #include "../src/Producer.h" #include "../src/Message.h" #include "../src/MQAdminExt.h" #include "../src/MQClient.h" #include "../src/MQProducer.h" #include "../src/MQConsumer.h" #include "../src/DefaultMQProducer.h" #include "../src/DefaultMQPushConsumer.h" #include "../src/DefaultMQSimpleConsumer.h" #include "../src/MessageQueue.h" #include "../src/SendResult.h" #include "../src/TransactionResolution.h" #include "../src/MQAdminExtImpl.h" #include "../src/MQClientImpl.h" #include "../src/MQProducerImpl.h" #include "../src/MQConsumerImpl.h" #include "../src/DefaultMQProducerImpl.h" #include "../src/DefaultMQPushConsumerImpl.h" #include "../src/DefaultMQSimpleConsumerImpl.h" #include "../src/MessageQueueImpl.h" #include "../src/SendResultImpl.h" #include "../src/TransactionResolutionImpl.h" #include "../src/MQAdminExt.h" #include "../src/MQClient.h" #include "../src/MQProducer.h" #include "../src/MQConsumer.h" #include "../src/DefaultMQProducer.h" #include "../src/DefaultMQPushConsumer.h" #include "../src/DefaultMQSimpleConsumer.h" #include "../src/MessageQueue.h" #include "../src/SendResult.h" #include "../src/TransactionResolution.h" #include "../src/MQAdminExtImpl.h" #include "../src/MQClientImpl.h" #include "../src/MQProducerImpl.h" #include "../src/MQConsumerImpl.h" #include "../src/DefaultMQProducerImpl.h" #include "../src/DefaultMQPushConsumerImpl.h" #include "../src/DefaultMQSimpleConsumerImpl.h" #include "../src/MessageQueueImpl.h" #include "../src/SendResultImpl.h" #include "../src/TransactionResolutionImpl.h" #include #include #include #include #include using namespace std; using namespace rocketmq; int main() { // Please refer to https://github.com/apache/rocketmq-clients/blob/master/cpp/examples/ExampleProducerWithTransactionalMessage.cpp return 0; } ``` -------------------------------- ### Configure and Start RocketMQ Connect Runtime Source: https://github.com/apache/rocketmq-site/blob/new-official-website/versioned_docs/version-5.0/10-connect/06RocketMQ Connect In Action3.md Steps to build the runtime, configure the standalone properties, and launch the service. ```bash cd rocketmq-connect mvn -Prelease-connect -DskipTests clean install -U # Edit conf/connect-standalone.conf # Set pluginPaths=/usr/local/connector-plugins cd distribution/target/rocketmq-connect-0.0.1-SNAPSHOT/rocketmq-connect-0.0.1-SNAPSHOT sh bin/connect-standalone.sh -c conf/connect-standalone.conf & ``` -------------------------------- ### Start and verify Broker and Proxy Source: https://github.com/apache/rocketmq-site/blob/new-official-website/i18n/en/docusaurus-plugin-content-docs/version-5.0/02-quickStart/01quickstart.md Launch the Broker and Proxy in local mode and verify the startup via proxy logs. ```shell ### start broker $ nohup sh bin/mqbroker -n localhost:9876 --enable-proxy & ### verify broker $ tail -f ~/logs/rocketmqlogs/proxy.log The broker[broker-a,192.169.1.2:10911] boot success... ``` -------------------------------- ### Producer with Delay Message Example C++ Source: https://github.com/apache/rocketmq-site/blob/new-official-website/i18n/en/docusaurus-plugin-content-docs/version-5.0/13-sdk/03cplusplus.md Example demonstrating sending delay messages using the C++ gRPC SDK. Refer to the rocketmq-clients repository for full project details and runtime environment setup. ```cpp #include "../src/Producer.h" #include "../src/Message.h" #include "../src/MQAdminExt.h" #include "../src/MQClient.h" #include "../src/MQProducer.h" #include "../src/MQConsumer.h" #include "../src/DefaultMQProducer.h" #include "../src/DefaultMQPushConsumer.h" #include "../src/DefaultMQSimpleConsumer.h" #include "../src/MessageQueue.h" #include "../src/SendResult.h" #include "../src/TransactionResolution.h" #include "../src/MQAdminExtImpl.h" #include "../src/MQClientImpl.h" #include "../src/MQProducerImpl.h" #include "../src/MQConsumerImpl.h" #include "../src/DefaultMQProducerImpl.h" #include "../src/DefaultMQPushConsumerImpl.h" #include "../src/DefaultMQSimpleConsumerImpl.h" #include "../src/MessageQueueImpl.h" #include "../src/SendResultImpl.h" #include "../src/TransactionResolutionImpl.h" #include "../src/MQAdminExt.h" #include "../src/MQClient.h" #include "../src/MQProducer.h" #include "../src/MQConsumer.h" #include "../src/DefaultMQProducer.h" #include "../src/DefaultMQPushConsumer.h" #include "../src/DefaultMQSimpleConsumer.h" #include "../src/MessageQueue.h" #include "../src/SendResult.h" #include "../src/TransactionResolution.h" #include "../src/MQAdminExtImpl.h" #include "../src/MQClientImpl.h" #include "../src/MQProducerImpl.h" #include "../src/MQConsumerImpl.h" #include "../src/DefaultMQProducerImpl.h" #include "../src/DefaultMQPushConsumerImpl.h" #include "../src/DefaultMQSimpleConsumerImpl.h" #include "../src/MessageQueueImpl.h" #include "../src/SendResultImpl.h" #include "../src/TransactionResolutionImpl.h" #include #include #include #include #include using namespace std; using namespace rocketmq; int main() { // Please refer to https://github.com/apache/rocketmq-clients/blob/master/cpp/examples/ExampleProducerWithTimedMessage.cpp return 0; } ``` -------------------------------- ### Async Send Example Producer C++ Source: https://github.com/apache/rocketmq-site/blob/new-official-website/i18n/en/docusaurus-plugin-content-docs/version-5.0/13-sdk/03cplusplus.md Example demonstrating asynchronous message sending using the C++ gRPC SDK. Refer to the rocketmq-clients repository for full project details and runtime environment setup. ```cpp #include "../src/Producer.h" #include "../src/Message.h" #include "../src/MQAdminExt.h" #include "../src/MQClient.h" #include "../src/MQProducer.h" #include "../src/MQConsumer.h" #include "../src/DefaultMQProducer.h" #include "../src/DefaultMQPushConsumer.h" #include "../src/DefaultMQSimpleConsumer.h" #include "../src/MessageQueue.h" #include "../src/SendResult.h" #include "../src/TransactionResolution.h" #include "../src/MQAdminExtImpl.h" #include "../src/MQClientImpl.h" #include "../src/MQProducerImpl.h" #include "../src/MQConsumerImpl.h" #include "../src/DefaultMQProducerImpl.h" #include "../src/DefaultMQPushConsumerImpl.h" #include "../src/DefaultMQSimpleConsumerImpl.h" #include "../src/MessageQueueImpl.h" #include "../src/SendResultImpl.h" #include "../src/TransactionResolutionImpl.h" #include "../src/MQAdminExt.h" #include "../src/MQClient.h" #include "../src/MQProducer.h" #include "../src/MQConsumer.h" #include "../src/DefaultMQProducer.h" #include "../src/DefaultMQPushConsumer.h" #include "../src/DefaultMQSimpleConsumer.h" #include "../src/MessageQueue.h" #include "../src/SendResult.h" #include "../src/TransactionResolution.h" #include "../src/MQAdminExtImpl.h" #include "../src/MQClientImpl.h" #include "../src/MQProducerImpl.h" #include "../src/MQConsumerImpl.h" #include "../src/DefaultMQProducerImpl.h" #include "../src/DefaultMQPushConsumerImpl.h" #include "../src/DefaultMQSimpleConsumerImpl.h" #include "../src/MessageQueueImpl.h" #include "../src/SendResultImpl.h" #include "../src/TransactionResolutionImpl.h" #include #include #include #include #include using namespace std; using namespace rocketmq; int main() { // Please refer to https://github.com/apache/rocketmq-clients/blob/master/cpp/examples/ExampleProducerWithAsync.cpp return 0; } ``` -------------------------------- ### Initialize Database Environments with Docker Source: https://github.com/apache/rocketmq-site/blob/new-official-website/versioned_docs/version-5.0/10-connect/06RocketMQ Connect In Action3.md Commands to spin up PostgreSQL and MySQL instances using Docker containers for testing. ```bash docker run -d --name postgres -p 5432:5432 -e POSTGRES_USER=start_data_engineer -e POSTGRES_PASSWORD=password debezium/postgres:14 docker run -it --rm --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=debezium -e MYSQL_USER=mysqluser -e MYSQL_PASSWORD=mysqlpw quay.io/debezium/example-mysql:1.9 ``` -------------------------------- ### Configure and Start RocketMQ Connect Runtime Source: https://github.com/apache/rocketmq-site/blob/new-official-website/versioned_docs/version-5.0/10-connect/04RocketMQ Connect In Action1.md Steps to build the runtime, configure the standalone worker, and launch the service. ```bash cd rocketmq-connect mvn -Prelease-connect -DskipTests clean install -U # After editing conf/connect-standalone.conf sh bin/connect-standalone.sh -c conf/connect-standalone.conf & ``` -------------------------------- ### Start JDBC Sink Connector Source: https://github.com/apache/rocketmq-site/blob/new-official-website/i18n/en/docusaurus-plugin-content-docs/version-5.0/10-connect/06RocketMQ Connect In Action3.md This endpoint allows you to start a JDBC sink connector. It consumes data from a specified RocketMQ topic and writes it to a target table via JDBC. The example configures a MySQL sink connector. ```APIDOC ## POST /connectors/ ### Description Starts a JDBC sink connector to synchronize data from a RocketMQ topic to a target database table. ### Method POST ### Endpoint /connectors/ ### Parameters #### Path Parameters - **connector_name** (string) - Required - The name of the connector to be created. #### Request Body - **connector.class** (string) - Required - The connector class, e.g., `org.apache.rocketmq.connect.jdbc.connector.JdbcSinkConnector`. - **max.task** (integer) - Optional - The maximum number of tasks for the connector. - **connect.topicnames** (string) - Required - The name of the RocketMQ topic to consume data from. - **connection.url** (string) - Required - The JDBC connection URL for the target database. - **connection.user** (string) - Required - The username for the database connection. - **connection.password** (string) - Required - The password for the database connection. - **pk.fields** (string) - Optional - Specifies the primary key fields. - **table.name.from.header** (boolean) - Optional - If true, the table name is derived from the message header. - **pk.mode** (string) - Optional - Defines the primary key mode (e.g., `record_key`). - **insert.mode** (string) - Optional - Defines the insert mode (e.g., `UPSERT`). - **db.timezone** (string) - Optional - The database timezone. - **table.types** (string) - Optional - The types of tables to include (e.g., `TABLE`). - **errors.deadletterqueue.topic.name** (string) - Optional - The name of the dead-letter queue topic. - **errors.log.enable** (boolean) - Optional - If true, errors will be logged. - **errors.tolerance** (string) - Optional - Error tolerance strategy (e.g., `ALL`). - **delete.enabled** (boolean) - Optional - If true, delete operations are enabled. - **key.converter** (string) - Optional - The converter class for keys (e.g., `org.apache.rocketmq.connect.runtime.converter.record.json.JsonConverter`). - **value.converter** (string) - Optional - The converter class for values (e.g., `org.apache.rocketmq.connect.runtime.converter.record.json.JsonConverter`). ### Request Example ```json { "connector.class": "org.apache.rocketmq.connect.jdbc.connector.JdbcSinkConnector", "max.task": "2", "connect.topicnames": "debezium-source-topic1000", "connection.url": "jdbc:mysql://database ip:3306/bank1", "connection.user": "root", "connection.password": "debezium", "pk.fields": "id", "table.name.from.header": "true", "pk.mode": "record_key", "insert.mode": "UPSERT", "db.timezone": "UTC", "table.types": "TABLE", "errors.deadletterqueue.topic.name": "dlq-topic", "errors.log.enable": "true", "errors.tolerance": "ALL", "delete.enabled": "true", "key.converter": "org.apache.rocketmq.connect.runtime.converter.record.json.JsonConverter", "value.converter": "org.apache.rocketmq.connect.runtime.converter.record.json.JsonConverter" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the status of the connector creation. #### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### RocketMQ Startup Sequence for Separated Architecture Source: https://github.com/apache/rocketmq-site/blob/new-official-website/i18n/en/docusaurus-plugin-content-docs/version-5.0/06-bestPractice/06access.md Sequence of commands to start NameServer, Broker, and Proxy in a separated storage-compute architecture with ACL enabled. ```bash # 1. Start NameServer nohup sh bin/mqnamesrv & # 2. Start Broker (storage node) nohup sh bin/mqbroker -n localhost:9876 -c conf/broker.conf & # 3. Start Proxy (compute node) nohup sh bin/mqproxy -n localhost:9876 -pc conf/rmq-proxy.json & ``` -------------------------------- ### Start RocketMQ Broker and Proxy (Windows) Source: https://github.com/apache/rocketmq-site/blob/new-official-website/i18n/en/docusaurus-plugin-content-docs/version-5.0/02-quickStart/02quickstartWithDocker.md Starts the RocketMQ Broker and Proxy within a Docker container on a Windows system. This command is similar to the Linux version but uses Windows-specific syntax for paths and line continuation. It configures the broker's IP, maps ports, sets the NameServer address, and mounts a local configuration file. Includes a command to verify the Broker's startup. ```shell # Configure the broker's IP address echo "brokerIP1=127.0.0.1" > broker.conf # Start the Broker and Proxy docker run -d ^ --name rmqbroker ^ --net rocketmq ^ -p 10912:10912 -p 10911:10911 -p 10909:10909 ^ -p 8080:8080 -p 8081:8081 \ -e "NAMESRV_ADDR=rmqnamesrv:9876" ^ -v %cd%\broker.conf:/home/rocketmq/rocketmq-5.3.2/conf/broker.conf ^ apache/rocketmq:5.3.2 sh mqbroker --enable-proxy \ -c /home/rocketmq/rocketmq-5.3.2/conf/broker.conf # Verify if Broker started successfully docker exec -it rmqbroker bash -c "tail -n 10 /home/rocketmq/logs/rocketmqlogs/proxy.log" ``` -------------------------------- ### Start RocketMQ Broker and Proxy (Linux) Source: https://github.com/apache/rocketmq-site/blob/new-official-website/i18n/en/docusaurus-plugin-content-docs/version-5.0/02-quickStart/02quickstartWithDocker.md Starts the RocketMQ Broker and Proxy within a Docker container on a Linux system. This command configures the broker's IP, maps necessary ports, sets the NameServer address, and mounts a local configuration file. It also includes a command to verify the Broker's startup by checking its logs. ```shell # Configure the broker's IP address echo "brokerIP1=127.0.0.1" > broker.conf # Start the Broker and Proxy docker run -d \ --name rmqbroker \ --network rocketmq \ -p 10912:10912 -p 10911:10911 -p 10909:10909 \ -p 8080:8080 -p 8081:8081 \ -e "NAMESRV_ADDR=rmqnamesrv:9876" \ # In PowerShell, replace %cd% with $pwd -v ./broker.conf:/home/rocketmq/rocketmq-5.3.2/conf/broker.conf \ apache/rocketmq:5.3.2 sh mqbroker --enable-proxy \ -c /home/rocketmq/rocketmq-5.3.2/conf/broker.conf # Verify if Broker started successfully docker exec -it rmqbroker bash -c "tail -n 10 /home/rocketmq/logs/rocketmqlogs/proxy.log" ``` -------------------------------- ### Install Helm Source: https://github.com/apache/rocketmq-site/blob/new-official-website/versioned_docs/version-5.0/02-quickStart/04quickstartWithHelmInKubernetes.md Installs Helm version 3.7.0+ on the system. This is a prerequisite for using Helm charts to deploy applications. ```bash helm version curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash ``` -------------------------------- ### Start PostgreSQL Docker Container Source: https://github.com/apache/rocketmq-site/blob/new-official-website/i18n/en/docusaurus-plugin-content-docs/version-5.0/10-connect/05RocketMQ Connect In Action2.md Start a PostgreSQL instance using Docker. This container is configured for Debezium's CDC capabilities. ```bash # starting a pg instance docker run -d --name postgres -p 5432:5432 -e POSTGRES_USER=start_data_engineer -e POSTGRES_PASSWORD=password debezium/postgres:14 # bash into postgres instance docker exec -ti postgres /bin/bash ``` -------------------------------- ### Send and receive messages with tools Source: https://github.com/apache/rocketmq-site/blob/new-official-website/i18n/en/docusaurus-plugin-content-docs/version-5.0/02-quickStart/01quickstart.md Set the NAMESRV_ADDR environment variable and run the built-in producer and consumer examples. ```shell $ 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... ``` -------------------------------- ### 启动 Broker+Proxy (Local模式单副本) Source: https://github.com/apache/rocketmq-site/blob/new-official-website/versioned_docs/version-5.0/05-deploymentOperations/01deploy.md 在 Local 模式下,启动同时包含 Broker 和 Proxy 的单副本节点。此配置风险较高,不建议在线上环境使用,仅适用于本地测试。命令中启用了 Proxy 功能。 ```bash nohup sh bin/mqbroker -n localhost:9876 --enable-proxy & tail -f ~/logs/rocketmqlogs/broker_default.log ``` -------------------------------- ### Start File Sink Connector Source: https://github.com/apache/rocketmq-site/blob/new-official-website/i18n/en/docusaurus-plugin-content-docs/version-5.0/10-connect/03RocketMQ Connect Quick Start.md This endpoint starts a file sink connector. It requires a JSON payload with connector configuration details. ```APIDOC ## POST /connectors/fileSinkConnector ### Description Starts a file sink connector with the provided configuration. ### Method POST ### Endpoint http://127.0.0.1:8082/connectors/fileSinkConnector ### Parameters #### Request Body - **connector.class** (string) - Required - The class name of the connector. - **filename** (string) - Required - The name of the file to write data to. - **connect.topicnames** (string) - Required - The topic to consume data from. ### Request Example ```json { "connector.class": "org.apache.rocketmq.connect.file.FileSinkConnector", "filename": "/Users/YourUsername/rocketmqconnect/test-sink-file.txt", "connect.topicnames": "fileTopic" } ``` ### Response #### Success Response (200) - **status** (integer) - The status code of the operation. - **body** (object) - The details of the created connector. #### Response Example ```json { "status": 200, "body": { "connector.class": "org.apache.rocketmq.connect.file.FileSinkConnector", "filename": "/Users/YourUsername/rocketmqconnect/test-sink-file.txt", "connect.topicnames": "fileTopic" } } ``` ``` -------------------------------- ### Configure and Start File Source Connector Source: https://github.com/apache/rocketmq-site/blob/new-official-website/versioned_docs/version-5.0/10-connect/03RocketMQ Connect Quick Start.md Create a source file and use the REST API to register a FileSourceConnector, which reads data from a local file and publishes it to a RocketMQ topic. ```shell mkdir -p /Users/YourUsername/rocketmqconnect/ touch /Users/YourUsername/rocketmqconnect/test-source-file.txt echo "Hello \r\nRocketMQ\r\n Connect" >> /Users/YourUsername/rocketmqconnect/test-source-file.txt curl -X POST -H "Content-Type: application/json" http://127.0.0.1:8082/connectors/fileSourceConnector -d '{ "connector.class": "org.apache.rocketmq.connect.file.FileSourceConnector", "filename": "/Users/YourUsername/rocketmqconnect/test-source-file.txt", "connect.topicname": "fileTopic" }' ``` -------------------------------- ### Start RocketMQ Cluster on Linux Source: https://github.com/apache/rocketmq-site/blob/new-official-website/i18n/en/docusaurus-plugin-content-docs/version-5.0/02-quickStart/03quickstartWithDockercompose.md Use this command to start all services defined in your docker-compose.yml file in detached mode on a Linux system. ```bash docker-compose up -d ``` -------------------------------- ### Example RocketMQ Prometheus Metric Source: https://github.com/apache/rocketmq-site/blob/new-official-website/i18n/en/docusaurus-plugin-content-docs/version-5.0/05-deploymentOperations/05Exporter.md A concrete example of a metric exposed by the RocketMQ exporter, showing the 'rocketmq_group_diff' metric with specific labels and a value. ```plaintext rocketmq_group_diff{group="rmq_group_test_20220114",topic="fusion_console_tst",countOfOnlineConsumers="0",msgModel="1",} 23.0 ``` -------------------------------- ### Prometheus Metric Format Example Source: https://github.com/apache/rocketmq-site/blob/new-official-website/i18n/en/docusaurus-plugin-content-docs/version-5.0/05-deploymentOperations/05Exporter.md An example of the metric format exposed by the RocketMQ exporter, compatible with Prometheus. It includes the metric name, labels, and the metric value. ```plaintext {