# Bridge Data into RocketMQ

Set up RocketMQ, taking MacOS X for instance:

$ wget https://mirrors.bfsu.edu.cn/apache/rocketmq/4.8.0/rocketmq-all-4.8.0-bin-release.zip
$ unzip rocketmq-all-4.8.0-bin-release.zip
$ cd rocketmq-all-4.8.0-bin-release/

# Add 2 configuration items in conf/broker.conf
brokerIP1 = 127.0.0.1
autoCreateTopicEnable = true

# Start RocketMQ NameServer
$ ./bin/mqnamesrv

# Start RocketMQ Broker
$ ./bin/mqbroker -n localhost:9876 -c conf/broker.conf
Copied!
1
2
3
4
5
6
7
8
9
10
11
12
13

Create a rule:

Go to EMQX Dashboard (opens new window), and select Rule Engine -> Rule on the left navigation menu. Click Create.

Type the following SQL:

SELECT * FROM "t/#"
Copied!
1
image

Add action:

In the Action pane, click Add action. Select Data bridge to RocketMQ from the drop-down list.

rocketmq_action_type

You then need to specify the resource and topic that the rule applies :

  1. Use of resources. Click Create right to the Use of Resources text box to create a RocketMQ resource.

    Fill in the information according to the configurations in RocketMQ ACL. Consult the service provider for the ACL information. For local or private deployment, you can check the ACL information in the configuration file. Change the prefix of the configuration file path based on the way of your deployment.

    ${rocket_path}/conf/plain_acl.yml
    
    Copied!
    1

    Fill in the resource configuration:

    Fill in the actual RocketMQ server address. Use , to separate multiple addresses. Keep other values as default. Click Test to make sure the connection is successful.

    Then, click Confirm.

rocketmq_create_resource
  1. RocketMQ topic. Type TopicTest in RocketMQ Topic text box. Click Confirm.

    An action is added in the Action pane. Click Create.

rocketmq_action_added

A rule for ingesting data into RocketMQ is created. Now you can use the statement below to send a message:

Topic: "t/1"

QoS: 0

Payload: "hello"
Copied!
1
2
3
4
5

Use the RocketMQ command line to check if the message is sent successfully:

$ ./bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer TopicTest
Copied!
1

image

In the rule list, click the icon in Monitor column. In Metrics, you can see the number for matched has increased by 1:

rocketmq_rule_crreated
What’s on this page