-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(events): add RocketMQEvent struct #25
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
# RocketMQ 触发器 | ||
|
||
### Event 格式 | ||
|
||
```json | ||
{ | ||
"id":"94ebc15f-f0db-4bbe-acce-56fb72fb****", | ||
"source":"RocketMQ-Function-rocketmq-trigger", | ||
"specversion":"1.0", | ||
"type":"mq:Topic:SendMessage", | ||
"datacontenttype":"application/json; charset=utf-8", | ||
"subject":"acs:mq:cn-hangzhou:164901546557****:MQ_INST_164901546557****_BXhFHryi%TopicName", | ||
"time":"2021-04-08T06:01:20.766Z", | ||
"aliyunaccountid":"164901546557****", | ||
"aliyunpublishtime":"2021-10-15T02:05:16.791Z", | ||
"aliyunoriginalaccountid":"164901546557****", | ||
"aliyuneventbusname":"RocketMQ-Function-rocketmq-trigger", | ||
"aliyunregionid":"cn-chengdu", | ||
"aliyunpublishaddr":"42.120.XX.XX", | ||
"data":{ | ||
"topic":"TopicName", | ||
"systemProperties":{ | ||
"MIN_OFFSET":"0", | ||
"TRACE_ON":"true", | ||
"MAX_OFFSET":"8", | ||
"MSG_REGION":"cn-hangzhou", | ||
"KEYS":"systemProperties.KEYS", | ||
"CONSUME_START_TIME":1628577790396, | ||
"TAGS":"systemProperties.TAGS", | ||
"INSTANCE_ID":"MQ_INST_164901546557****_BXhFHryi" | ||
}, | ||
"userProperties":{ | ||
|
||
}, | ||
"body":"TEST" | ||
} | ||
} | ||
``` | ||
|
||
### 事件流模型的 event 格式如下所示 | ||
|
||
```json | ||
[ | ||
{ | ||
"id":"94ebc15f-f0db-4bbe-acce-56fb72fb****", | ||
"source":"RocketMQ-Function-rocketmq-trigger", | ||
"specversion":"1.0", | ||
"type":"mq:Topic:SendMessage", | ||
"datacontenttype":"application/json; charset=utf-8", | ||
"subject":"acs:mq:cn-hangzhou:164901546557****:MQ_INST_164901546557****_BXhFHryi%TopicName", | ||
"time":"2021-04-08T06:01:20.766Z", | ||
"aliyunaccountid":"164901546557****", | ||
"aliyunpublishtime":"2021-10-15T02:05:16.791Z", | ||
"aliyunoriginalaccountid":"164901546557****", | ||
"aliyuneventbusname":"RocketMQ-Function-rocketmq-trigger", | ||
"aliyunregionid":"cn-chengdu", | ||
"aliyunpublishaddr":"42.120.XX.XX", | ||
"data":{ | ||
"topic":"TopicName", | ||
"systemProperties":{ | ||
"MIN_OFFSET":"0", | ||
"TRACE_ON":"true", | ||
"MAX_OFFSET":"8", | ||
"MSG_REGION":"cn-hangzhou", | ||
"KEYS":"systemProperties.KEYS", | ||
"CONSUME_START_TIME":1628577790396, | ||
"TAGS":"systemProperties.TAGS", | ||
"INSTANCE_ID":"MQ_INST_164901546557****_BXhFHryi" | ||
}, | ||
"userProperties":{ | ||
|
||
}, | ||
"body":"TEST" | ||
} | ||
}, | ||
{ | ||
"id":"94ebc15f-f0db-4bbe-acce-56fb72fb****", | ||
"source":"RocketMQ-Function-rocketmq-trigger", | ||
"specversion":"1.0", | ||
"type":"mq:Topic:SendMessage", | ||
"datacontenttype":"application/json; charset=utf-8", | ||
"subject":"acs:mq:cn-hangzhou:164901546557****:MQ_INST_164901546557****_BXhFHryi%TopicName", | ||
"time":"2021-04-08T06:01:20.766Z", | ||
"aliyunaccountid":"164901546557****", | ||
"aliyunpublishtime":"2021-10-15T02:05:16.791Z", | ||
"aliyunoriginalaccountid":"164901546557****", | ||
"aliyuneventbusname":"RocketMQ-Function-rocketmq-trigger", | ||
"aliyunregionid":"cn-chengdu", | ||
"aliyunpublishaddr":"42.120.XX.XX", | ||
"data":{ | ||
"topic":"TopicName", | ||
"systemProperties":{ | ||
"MIN_OFFSET":"0", | ||
"TRACE_ON":"true", | ||
"MAX_OFFSET":"8", | ||
"MSG_REGION":"cn-hangzhou", | ||
"KEYS":"systemProperties.KEYS", | ||
"CONSUME_START_TIME":1628577790396, | ||
"TAGS":"systemProperties.TAGS", | ||
"INSTANCE_ID":"MQ_INST_164901546557****_BXhFHryi" | ||
}, | ||
"userProperties":{ | ||
|
||
}, | ||
"body":"TEST" | ||
} | ||
} | ||
] | ||
``` | ||
|
||
### 使用示例 | ||
|
||
下面展示了一个简单的 FC demo,当你为该函数配置 RocketMQ 触发器之后,每当你向 RocketMQ 发送任意消息之后,就会触发该函数,并返回消息内容。 | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/aliyun/fc-runtime-go-sdk/events" | ||
"github.com/aliyun/fc-runtime-go-sdk/fc" | ||
"github.com/aliyun/fc-runtime-go-sdk/fccontext" | ||
) | ||
|
||
func HandleRequest(ctx context.Context, event events.RocketMQEvent) (string, error) { | ||
fcCtx, _ := fccontext.FromContext(ctx) | ||
flog := fcCtx.GetLogger() | ||
mes, _ := json.Marshal(event) | ||
flog.Info("event:", string(mes)) | ||
return fmt.Sprintf("Body:%s", event.Data.Body), nil | ||
} | ||
|
||
func main() { | ||
fc.Start(HandleRequest) | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package events | ||
|
||
import "time" | ||
|
||
type RocketMQEvent struct { | ||
ID *string `json:"id"` | ||
Source *string `json:"source"` | ||
SpecVersion *string `json:"specversion"` | ||
Type *string `json:"type"` | ||
DataContentType *string `json:"datacontenttype"` | ||
Subject *string `json:"subject"` | ||
Time *time.Time `json:"time"` | ||
AliyunAccountId *string `json:"aliyunaccountid"` | ||
AliyunPublishTime *time.Time `json:"aliyunpublishtime"` | ||
AliyunOriginalAccountId *string `json:"aliyunoriginalaccountid"` | ||
AliyunEventBusName *string `json:"aliyuneventbusname"` | ||
AliyunRegionId *string `json:"aliyunregionid"` | ||
AliyunPublishAddr *string `json:"aliyunpublishaddr"` | ||
Data *RocketMQData `json:"data"` | ||
} | ||
|
||
type RocketMQData struct { | ||
Topic string `json:"topic"` | ||
SystemProperties map[string]string `json:"systemProperties"` | ||
UserProperties map[string]string `json:"userProperties"` | ||
Body string `json:"body"` | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EventBridge的readme应该还没有吧?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有的,这是别人忘记加了我顺便一并加上的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的,看到了