Updated on 2024-09-20 GMT+08:00

Accessing RocketMQ on a Client (With SSL)

If SSL is enabled, data will be encrypted before transmission for enhanced security. This section describes how to use TCP to connect to a RocketMQ instance with SSL in CLI mode on Linux.

Prerequisites

  • A RocketMQ instance has been created and you have obtained the connection addresses for intra-VPC access or public network access. For private access, use port 8100. For public access, use port 8200.
  • The network between the client and the RocketMQ instance has been established. For details about network requirements, see RocketMQ Network Connection Conditions.
  • Security group rules have been configured.
  • A topic has been created.
  • JDK v1.8.111 or later has been installed on the client server, and related environment variables have been configured.

Accessing the Instance with CLI

  1. Log in to the client server.
  2. Download the rocketmq-tutorial software package.

    wget https://dms-demos.obs.cn-north-1.myhuaweicloud.com/rocketmq-tutorial.zip

  3. Decompress the rocketmq-tutorial package.

    unzip rocketmq-tutorial.zip

  4. (Optional) If ACL is enabled for the RocketMQ instance, authentication is required when you run the mqadmin command.

    Switch to the directory where the decompressed software package is stored and add the following content to the conf/tools.yml file:
    accessKey:*******
    secretKey:*******

    accessKey and secretKey are the username and secret key set on the Users page of the console. For details, see Creating a User.

  5. Go to the rocketmq-tutorial/bin directory.

    cd rocketmq-tutorial/bin

  6. Produce normal messages using the sample project.

    JAVA_OPT=-Dtls.enable=true sh mqadmin sendMessage -n "${Connection addresses}" -t ${Topic name} -p "hello rocketmq"

    Parameter description:

    • Connection addresses: the Instance Address for private network access or Instance Address (Public Network) for public network access.
    • Topic name: name of the topic created for the RocketMQ instance

    In the following example, 11.xxx.xxx.89:8200;11.xxx.xxx.144:8200 are the metadata connection addresses for public network access to the RocketMQ instance, and topic-test is the topic name.

    JAVA_OPT=-Dtls.enable=true sh mqadmin sendMessage -n "11.xxx.xxx.89:8200;11.xxx.xxx.144:8200" -t topic-test -p "hello rocketmq"

    Press Ctrl+C to exit.

  7. Consume normal messages using the sample project.

    JAVA_OPT=-Dtls.enable=true sh mqadmin consumeMessage -n "${Connection addresses}" -t ${Topic name}

    Parameter description:

    • Connection addresses: the Instance Address for private network access or Instance Address (Public Network) for public network access.
    • Topic name: name of the topic created for the RocketMQ instance

    In the following example, 11.xxx.xxx.89:8200;11.xxx.xxx.144:8200 are the metadata connection addresses for public network access to the RocketMQ instance, and topic-test is the topic name.

    JAVA_OPT=-Dtls.enable=true sh mqadmin consumeMessage -n "11.xxx.xxx.89:8200;11.xxx.xxx.144:8200" -t topic-test

    To stop consuming messages, press Ctrl+C to exit.

  8. Create messages with traces using the sample project.

    JAVA_OPT=-Dtls.enable=true sh mqadmin sendMessage -n "${Connection addresses}" -t ${Topic name} -p "hello rocketmq" -m true

    Parameter description:

    • Connection addresses: the Instance Address for private network access or Instance Address (Public Network) for public network access.
    • Topic name: name of the topic created for the RocketMQ instance

    In the following example, 11.xxx.xxx.89:8200;11.xxx.xxx.144:8200 are the metadata connection addresses for public network access to the RocketMQ instance, and topic-test is the topic name.

    JAVA_OPT=-Dtls.enable=true sh mqadmin sendMessage -n "11.xxx.xxx.89:8200;11.xxx.xxx.144:8200" -t topic-test -p "hello rocketmq" -m true

    Press Ctrl+C to exit.

  9. Retrieve messages and send the message traces using the sample project.

    JAVA_OPT=-Dtls.enable=true sh mqadmin consumeMessage -n "${Connection addresses}" -t ${Topic name} -m true

    Parameter description:

    • Connection addresses: the Instance Address for private network access or Instance Address (Public Network) for public network access.
    • Topic name: name of the topic created for the RocketMQ instance

    In the following example, 11.xxx.xxx.89:8200;11.xxx.xxx.144:8200 are the metadata connection addresses for public network access to the RocketMQ instance, and topic-test is the topic name.

    JAVA_OPT=-Dtls.enable=true sh mqadmin consumeMessage -n "11.xxx.xxx.89:8200;11.xxx.xxx.144:8200" -t topic-test -m true

    Press Ctrl+C to exit.