commit | aa291ea2e785f133807e6e6940df0d5726ee44a2 | [log] [tgz] |
---|---|---|
author | wangkai <wangkai@zhongan.com> | Mon Jun 05 11:02:39 2023 +0800 |
committer | shenlin <2011shenlin@gmail.com> | Thu Jun 15 10:40:49 2023 +0800 |
tree | 400727ad11a6d6e5bf279af1ce8202a3a8feef69 | |
parent | 1b6c079017aecf88f3ce2df80b0d5af7630828ae [diff] |
1.add h2 db migration file directory
RocketMQ EventBridge is a subproject of rocketmq to make it easier to build event-driven applications. In addition, rocketmq-eventbridge can route events between many services and applications based on the standard CloudEvents 1.0 specification. Users can use rocketmq-eventbridge to build loosely coupled and distributed event-driven architectures.
Events are sent to the event bus in two ways: 1) Push events through the SDK or Webhook actively; 2) Pulled events by eventbridge passively. Events obtained in both ways will be stored on the event bus. EventBus is the core concept in EventBridge, which allows you to subscribe to the events, filter the events, and push to the specified target by creating the event rule. The event on the event bus is stored by rocketmq. Through rocketmq-connect, we can pull the event from the register source to the event bus, or push the events from the event bus to the registered target.
The code architecture of EventBridge include 4 core modules:
adapter
Adapt to different operating environmentspersistence
Implement the repository API in the domain layer and persist the model data.api
The open API provided by EventBridge.rpc
Implement the rpc API in the domain layer to adapter the run environment.common
The common code of all modules.domain
The core code of EventBridge.start
RocketMQ EventBridge rely on a message service to store the event, and needs one connect service to collect or forward events.Here, we choose the Apache RocketMQ as our message serviceļ¼ and choose the Apache RocketMQ Connect as our connect service.Of course, you can also choose other alternative services. Eventbridge do not limit it. You only need to provide the relevant adapter API implementation.
Apache RocketMQ is a great messaging service,and we choose it as our message service.You can deploy the apache rocketmq according to the manual: RocketMQ Quick Start
Apache RocketMQ Connect can connect the external upstream and downstream services,and You can deploy it according to the manual: RocketMQ Connect Quick Start . Before deploy the Apache RocketMQ Connect, you should download the plugins below and put it to the “pluginPaths” which defined on rocketmq-connect.
Before run the project,configure the following properties which :
# The config of mysql databse. spring.datasource.url=jdbc:mysql://xxxx:3306/xxxx?characterEncoding=utf8 spring.datasource.username=xxx spring.datasource.password=xxxx # The endpoint of rocketmq nameserver. rocketmq.namesrvAddr=xxxxx:9876 # The cluster name of rocketmq. rocketmq.cluster.name=DefaultCluster # The endpoint of rocketmq-connect. rocketmq.connect.endpoint=xxxxxx:8082
POST /bus/createEventBus HTTP/1.1 Host: demo.eventbridge.com Content-Type: application/json; charset=utf-8 { "eventBusName":"demo-bus", "description":"a demo bus." }
POST /source/createEventSource HTTP/1.1 Host: demo.eventbridge.com Content-Type: application/json; charset=utf-8 { "eventBusName":"demo-bus", "eventSourceName":"demo-source", "description":"A demo source." }
POST /rule/createEventRule HTTP/1.1 Host: demo.eventbridge.com Content-Type: application/json; charset=utf-8 { "eventBusName":"demo-bus", "eventRuleName":"demo-rule", "description":"A demo rule.", "filterPattern":"{}" }
This is a sample with EventBridge target:
POST /target/createEventTargets HTTP/1.1 Host: demo.eventbridge.com Content-Type: application/json; charset=utf-8 { "eventBusName":"demo-bus", "eventRuleName":"demo-rule", "eventTargets":[ { "eventTargetName":"eventbridge-target", "className":"acs.eventbridge", "config":{ "RegionId":"cn-hangzhou", "AliyunEventBus":"rocketmq-eventbridge" } } ] }
This is a sample with DingTalk target:
POST /target/createEventTargets HTTP/1.1 Host: demo.eventbridge.com Content-Type: application/json; charset=utf-8 { "eventBusName":"demo-bus", "eventRuleName":"demo-rule", "eventTargets":[ { "eventTargetName":"dingtalk-target", "className":"acs.dingtalk", "config":{ "WebHook":"https://oapi.dingtalk.com/robot/send?access_token=b43a54b702314415c2acdae97eda1e092528b7a9dddb31510a5b4430be2ef867", "SecretKey":"SEC53483bf496b8f9e0b4ab0ab669d422208e6ccfaedfd5120ea6b8426b9ecd47aa", "Body":"{\"template\":\"{\\\"text\\\":{\\\"content\\\":\\\"${content}\\\"},\\\"msgtype\\\":\\\"text\\\"}\",\"form\":\"TEMPLATE\",\"value\":\"{\\\"content\\\":\\\"$.data.body\\\"}\"}" } } ] }
POST /putEvents HTTP/1.1 Host: demo.eventbridge.com Content-Type:"application/cloudevents+json; charset=UTF-8" { "specversion" : "1.0", "type" : "com.github.pull_request.opened", "source" : "https://github.com/cloudevents/spec/pull", "subject" : "123", "id" : "A234-1234-1234", "time" : "2018-04-05T17:31:00Z", "datacontenttype" : "application/json", "data" : { "body":"demo" }, "aliyuneventbusname":"demo-bus" }
EventBridge HttpSource allows you to put events to eventbus in the form of webhook.
Here is an example explaining how to put events using EventBridge HttpSource.
Create an EventBridge HttpSource
A webhook will be generated after the creation of HttpSource.
POST /source/createEventSource HTTP/1.1 Host: demo.eventbridge.com Content-Type: application/json; charset=utf-8 { "eventSourceName": "httpEventSourceDemo", "eventBusName": "demo", "description": "http source demo", "className": "HttpEvent", "config": { "Type": "HTTP&HTTPS", "Method": ["GET", "POST"], "SecurityConfig": "ip", "Ip": ["10.0.0.0/8"], "Referer":[] } }
Http request to access this webhook will be converted into a CloudEvent and delivered to eventbus.
curl -d '{"username": "testUser", "testData": "testData"}' -H 'Content-Type: application/json' -H 'Accept-Language: en-US' http://127.0.0.1:7001/webhook/putEvents?token=43146d108b224eb2adc581aedd28f272007320d14b9d
generated CloudEvent demo
{ "datacontenttype": "application/json", "data": { "body": { "username": "testUser", "testData": "testData" }, "headers": { "Accept": "*/*", "User-Agent": "curl/7.64.1", "Host": "127.0.0.1:7001", "Accept-Language": "en-US", "Content-Length": "48", "Content-Type": "application/json" }, "httpMethod": "POST", "path": "/webhook/putEvents", "queryString": {} }, "subject": "DemoBus/httpEventSourceDemo", "source": "httpEventSourceDemo", "type": "eventbridge:Events:HTTPEvent", "specversion": "1.0", "id": "75bc099b-130a-45a8-82e1-3f9a7f0d10f3", "time": "2022-05-12T17:20:30.264+08:00" }