RocketMQ EventBridge Quick Start

RocketMQ EventBridge requires a message service to store events and a runtime to subscribe and push events. In this case, we choose Apache RocketMQ as our message service and Apache RocketMQ Connect as our runtime for subscribing and pushing events. Of course, you can also choose other message services instead, EventBridge does not impose any restrictions on this. In the future, EventBridge also plans to implement its own runtime based on OpenMessaging Connect API in order to better provide event-driven services.

System requirements:

  • 64-bit operating system, Linux/Unix/macOS is recommended
  • 64-bit JDK 1.8+

Deploy Apache RocketMQ

Apache RocketMQ is a great message service and we choose it as the default storage for EventBus. You can quickly deploy it according to this manual: Apache RocketMQ Quick Start

Deploy Apache RocketMQ Connect

We use Apache RocketMQ Connect as our default runtime to connect to external upstream and downstream services. You can complete the deployment according to the manual: RocketMQ Connect Quick Start. Before deploying Apache RocketMQ Connect, you should download the following plugins and put them in the directory defined by the “pluginPaths” configuration parameter in rocketmq-connect.

Deploy RocketMQ EventBridge

  • Download EventBridge

    You can download the binary package of EventBridge from here : rocketmq-eventbridge-xxx-bin-release.zip. After downloading, unzip it and you will get a directory as follows:

    1. /rocketmq-eventbridge-xxx-bin-release/
    2. |——bin
    3. | |——runserver.sh
    4. | |——eventbridge.sh
    5. |——config
    6. | |——application.properties
    7. |——jar
    8. | |——rocketmq-eventbridge.jar
  • Configuring EventBridge

    Before running, we need to configure the runtime environment for EventBridge by modifying the config/application.properties file, as follows:

    1. # Mysql database address
    2. spring.datasource.url=jdbc:mysql://xxxx:3306/xxxx?characterEncoding=utf8
    3. spring.datasource.username=xxx
    4. spring.datasource.password=xxxx
    5. # RocketMQ nameserver address
    6. rocketmq.namesrvAddr=xxxxx:9876
    7. # RocketMQ cluster name
    8. rocketmq.cluster.name=DefaultCluster
    9. # RocketMQ Connect address
    10. rocketmq.connect.endpoint=xxxxxx:8082
    11. # log default configuration
    12. log.path=~
    13. log.level=INFO
    14. app.name=rocketmq-eventbridge
  • Start EventBridge

    1. sh bin/eventbridge.sh start

    The log directory by default is located at ~ /rocketmq-eventbridge/rocketmq-eventbridge.log, it can be modified by changing the log.path and app.name. The log can be used to check if the service has started properly.: img.png

  • Test EventBridge

Once the service is started, we can use the following demo cases to test and verify EventBridge.

Demo

  • Create Event Bus

    1. POST /bus/createEventBus HTTP/1.1
    2. Host: demo.eventbridge.com
    3. Content-Type: application/json; charset=utf-8
    4. {
    5. "eventBusName":"demo-bus",
    6. "description":"a demo bus."
    7. }
  • Create Source Event

    1. POST /source/createEventSource HTTP/1.1
    2. Host: demo.eventbridge.com
    3. Content-Type: application/json; charset=utf-8
    4. {
    5. "eventBusName":"demo-bus",
    6. "eventSourceName":"demo-source",
    7. "description":"A demo source."
    8. }
  • Create Event Rules

    1. POST /rule/createEventRule HTTP/1.1
    2. Host: demo.eventbridge.com
    3. Content-Type: application/json; charset=utf-8
    4. {
    5. "eventBusName":"demo-bus",
    6. "eventRuleName":"demo-rule",
    7. "description":"A demo rule.",
    8. "filterPattern":"{}"
    9. }
  • Create Event Target

    Create an event target that delivers to EventBridge in the cloud.

    1. POST /target/createEventTargets HTTP/1.1
    2. Host: demo.eventbridge.com
    3. Content-Type: application/json; charset=utf-8
    4. {
    5. "eventBusName":"demo-bus",
    6. "eventRuleName":"demo-rule",
    7. "eventTargets":[
    8. {
    9. "eventTargetName":"eventbridge-target",
    10. "className":"acs.eventbridge",
    11. "config":{
    12. "RegionId":"cn-hangzhou",
    13. "AliyunEventBus":"rocketmq-eventbridge"
    14. }
    15. }
    16. ]
    17. }

    Creating an event target that delivers notifications to a DingTalk robot:

    1. POST /target/createEventTargets HTTP/1.1
    2. Host: demo.eventbridge.com
    3. Content-Type: application/json; charset=utf-8
    4. {
    5. "eventBusName":"demo-bus",
    6. "eventRuleName":"demo-rule",
    7. "eventTargets":[
    8. {
    9. "eventTargetName":"dingtalk-target",
    10. "className":"acs.dingtalk",
    11. "config":{
    12. "WebHook":"https://oapi.dingtalk.com/robot/send?access_token=b43a54b702314415c2acdae97eda1e092528b7a9dddb31510a5b4430be2ef867",
    13. "SecretKey":"SEC53483bf496b8f9e0b4ab0ab669d422208e6ccfaedfd5120ea6b8426b9ecd47aa",
    14. "Body":"{\"template\":\"{\\\"text\\\":{\\\"content\\\":\\\"${content}\\\"},\\\"msgtype\\\":\\\"text\\\"}\",\"form\":\"TEMPLATE\",\"value\":\"{\\\"content\\\":\\\"$.data.body\\\"}\"}"
    15. }
    16. }
    17. ]
    18. }
  • Send Event to EventBus

    Finally, we will send an event through the API and verify if the Target endpoint receives the corresponding event as expected.

    1. POST /putEvents HTTP/1.1
    2. Host: demo.eventbridge.com
    3. Content-Type:"application/cloudevents+json; charset=UTF-8"
    4. {
    5. "specversion" : "1.0",
    6. "type" : "com.github.pull_request.opened",
    7. "source" : "https://github.com/cloudevents/spec/pull",
    8. "subject" : "123",
    9. "id" : "A234-1234-1234",
    10. "time" : "2018-04-05T17:31:00Z",
    11. "datacontenttype" : "application/json",
    12. "data" : {
    13. "body":"demo"
    14. },
    15. "aliyuneventbusname":"demo-bus"
    16. }