Skip to content
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

add darabonba sdk demo; #177

Merged
merged 1 commit into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ domain/target/
start/target/
common/target/
supports/*/target/
*libraries*
.vscode/
node_modules/
*.sln
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public class CloudEventBatchedConverter implements EventConverter {
@Override
public boolean hit(Map<String, String> headers) {
String contentType = headers.get(CONTENT_TYPE);
if(Strings.isNullOrEmpty(contentType)){
contentType = headers.get(CONTENT_TYPE.toLowerCase());
}
return !Strings.isNullOrEmpty(contentType) && contentType.startsWith(HTTP_BATCHED_PROTOCOL_BINDING);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Map;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedHashMap;

import org.springframework.stereotype.Service;

import static org.apache.http.protocol.HTTP.CONTENT_TYPE;
Expand All @@ -38,6 +39,9 @@ public class CloudEventBinaryConverter implements EventConverter {
@Override
public boolean hit(Map<String, String> headers) {
String contentType = headers.get(CONTENT_TYPE);
if(Strings.isNullOrEmpty(contentType)){
contentType = headers.get(CONTENT_TYPE.toLowerCase());
}
if (Strings.isNullOrEmpty(contentType) || !contentType.startsWith(HTTP_BINARY_PROTOCOL_BINDING)) {
return false;
}
Expand All @@ -61,6 +65,9 @@ public List<CloudEvent> toEventBridgeEvent(Map<String, String> headers, byte[] b
.stream()
.forEach(entry -> headerMap.add(entry.getKey(), entry.getValue()));
String mediaType = headers.get(CONTENT_TYPE);
if(Strings.isNullOrEmpty(mediaType)){
mediaType = headers.get(CONTENT_TYPE.toLowerCase());
}
CloudEvent cloudEvent = RestfulWSMessageFactory.create(MediaType.valueOf(mediaType), headerMap, body)
.toEvent();
return Lists.newArrayList(cloudEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class CloudEventStructuredConverter implements EventConverter {
@Override
public boolean hit(Map<String, String> headers) {
String contentType = headers.get(CONTENT_TYPE);
if(Strings.isNullOrEmpty(contentType)){
contentType = headers.get(CONTENT_TYPE.toLowerCase());
}
return !Strings.isNullOrEmpty(contentType) && contentType.startsWith(HTTP_STRUCTURED_PROTOCOL_BINDING);
}

Expand Down
87 changes: 87 additions & 0 deletions sdk/Darafile
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"scope": "SDKClient",
"name": "sdk-client",
"version": "1.0.0",
"main": "./main.dara",
"libraries": {
"Util": "darabonba:Util:*",
"OpenApi": "alibabacloud:OpenApi:*"
},
"releases": {
"java": "org.apache.rocketmq.eventbridge:sdk:0.0.0",
"go": "github.com/org-apache-rocketmq/eventbridge-sdk/client:v0.0.0",
"csharp": "RocketMQ.Eventbridge.SDK:1.0.0",
"ts": "@org.apache.rocketmq/eventbridge-sdk:0.0.0",
"php": "rocketmq/eventbridge-sdk:0.0.0",
"python": "rocketmq_eventbridge20240701:0.0.0"
},
"java": {
"className": "Client",
"package": "org.apache.rocketmq.eventbridge.sdk",
"enableMinimizeModelName": false,
"packageInfo": {
"groupId": "org.apache.rocketmq.eventbridge",
"artifactId": "sdk",
"version": "0.0.0",
"description": "Eventbridge (20240701) SDK for Java",
"url": "",
"licenseName": "The Apache License, Version 2.0",
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0.txt",
"developerId": "rocketmq",
"developerName": "rocketmq",
"developerEmail": "[email protected]"
}
},
"ts":{
"packageName": "SDKClient"
},
"csharp": {
"className": "SDKClient",
"namespace": "RocketMQ.Eventbridge.SDK",
"packageInfo": {
"name": "sdk",
"version": "0.0.0",
"title": "eventbridge-sdk",
"description": "open source eventbridge (20240701) SDK Library for .NET"
}
},
"php": {
"package": "RocketMQ.Eventbridge.SDK",
"clientName": "SDKClient",
"packageInfo": {
"name": "rocketmq/eventbridge-sdk",
"desc": "RocketMQ eventbridge (20240701) SDK Library for PHP",
"github": "unavailable",
"files": {
"LICENSE": "../LICENSE"
}
}
},
"python": {
"package": "rocketmq_eventbridge",
"clientName": "client",
"packageInfo": {
"name": "rocketmq_eventbridge",
"desc": "Alibaba Cloud eventbridge (20240701) SDK Library for Python",
"github": "https://github.com/aliyun/alibabacloud-python-sdk",
"author": "Alibaba Cloud SDK",
"email": "[email protected]"
}
},
"swift": {
"clientName": "Client",
"packageInfo": {
"name": "AlibabacloudEventbridge20240701",
"desc": "Alibaba Cloud eventbridge (20240701) SDK Library for Swift",
"github": "https://github.com/alibabacloud-sdk-swift/eventbridge-20240701",
"author": "Alibaba Cloud SDK",
"email": "[email protected]"
}
},
"go": {
"interface": true,
"clientName": "Client"
},
"productId": "eventbridge",
"apiVersions": "2024-07-01"
}
37 changes: 37 additions & 0 deletions sdk/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Daranbonba

通过 darabonba 生成的多语言 SDK 实现对 eventBridge 进行 RPC 管控

# 多语言 SDK 生成

## dara 安装

```
npm install @darabonba/cli -g
```

# 目录结构

- demo
- 包含了 sdk demo 的源码和生成样例,按 controller 分类
- doc
- 各语言的 sdk 生成使用文档
- generated
- 包含了 sdk client 的各语言生成样例
- Darafile
- dara 配置文件
- main.dara
- dara 源码

# 支持语言

- java
- golang
- csharp
- php
- python
- typescript

# 使用
各语言 sdk 使用方法请参考 doc 中的文档

66 changes: 66 additions & 0 deletions sdk/demo/ApiDestination/Darafile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"scope": "Demo",
"name": "demo",
"version": "0.0.0",
"main": "./demo.dara",
"libraries": {
"SDKClient" : "../../",
"Util": "darabonba:Util:*",
"OpenApi": "alibabacloud:OpenApi:*",
"OpenApiUtil": "alibabacloud:OpenApiUtil:*",
"Console": "darabonba:Console:*"
},
"java": {
"package": "org.apache.rocketmq.eventbridge.demo",
"className": "Demo",
"packageInfo": {
"groupId": "org.apache.rocketmq.eventbridge",
"artifactId": "demo",
"version": "0.0.0",
"description": "EventBridge SDK demo for Java",
"url": "",
"licenseName": "The Apache License, Version 2.0",
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0.txt",
"developerId": "ludi",
"developerName": "EventBridge SDK",
"developerEmail": "[email protected]",
"scmConnection": "",
"scmDeveloperConnection": "",
"scmUrl": ""
}
},
"go": {
"clientName": "DemoClient"
},
"csharp": {
"className": "Demo",
"namespace": "RocketMQ.Eventbridge.Demo",
"packageInfo": {
"name": "sdkDemo",
"version": "0.0.0",
"title": "eventbridge-sdk-demo",
"description": "open source eventbridge (20240701) SDK Demo Library for .NET"
}
},
"php": {
"package": "RocketMQ.Eventbridge.SDK.Demo",
"clientName": "Demo",
"packageInfo": {
"name": "rocketmq/eventbridge-sdk-demo",
"desc": "RocketMQ eventbridge (20240701) SDK Demo for PHP",
"github": "unavailable",
"files": {
"LICENSE": "../LICENSE"
}
}
},
"python": {
"package": "rocketmq_eventbridge_demo",
"clientName": "demo",
"packageInfo": {
"name": "rocketmq_eventbridge_demo",
"desc": "Alibaba Cloud eventbridge (20240701) SDK Library for Python",
"github": "unavailable"
}
}
}
117 changes: 117 additions & 0 deletions sdk/demo/ApiDestination/demo.dara
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import Util;
import OpenApi;
import SDKClient;
import Console;

type @sdkClient = SDKClient;
type @endpoint = string;

init(){
@endpoint = '127.0.0.1:7001';
var config = new OpenApi.Config{
endpoint = @endpoint
};
@sdkClient = new SDKClient(config);
}

/**
ApiDestination Controller apis:
* createApiDestination *
* updateApiDestination *
* getApiDestination *
* deleteApiDestination *
* listApiDestinations *
*/

async function testCreateApiDestination(): void {
var request = new SDKClient.CreateApiDestinationRequest{
apiDestinationName = "new-api-destination",
connectionName = "new-connection",
description = "demo api destination for test",
httpApiParameters = new SDKClient.CreateApiDestinationRequest.httpApiParameters{
endpoint = @endpoint,
method = "POST"
}
};

try {
var res = @sdkClient.createApiDestination(request);
Console.log(Util.toJSONString(res.body));
} catch(err) {
Console.log('err!');
Console.log(err.message);
} finally {
Console.log('test end!');
}

}

async function testUpdateApiDestination(): void {
var request = new SDKClient.UpdateApiDestinationRequest{
apiDestinationName = "new-api-destination",
connectionName = "new-connection",
description = "!updated! demo api destination for test",
httpApiParameters = new SDKClient.UpdateApiDestinationRequest.httpApiParameters{
endpoint = @endpoint,
method = "GET"
}
};

try {
var res = @sdkClient.updateApiDestination(request);
Console.log(Util.toJSONString(res.body));
} catch(err) {
Console.log('err!');
Console.log(err.message);
} finally {
Console.log('test end!');
}

}

async function testGetApiDestination(): void {
var request = new SDKClient.GetApiDestinationRequest{
apiDestinationName = "new-api-destination"
};
try {
var res = @sdkClient.getApiDestination(request);
Console.log(Util.toJSONString(res.body));
} catch(err) {
Console.log('err!');
Console.log(err.message);
} finally {
Console.log('test end!');
}
}

async function testDeleteApiDestination(): void {
var request = new SDKClient.DeleteApiDestinationRequest{
apiDestinationName = "new-api-destination"
};
try {
var res = @sdkClient.deleteApiDestination(request);
Console.log(Util.toJSONString(res.body));
} catch(err) {
Console.log('err!');
Console.log(err.message);
} finally {
Console.log('test end!');
}
}

async function testListApiDestinations(): void {
var request = new SDKClient.ListApiDestinationsRequest{
maxResults = 2
};

try {
var res = @sdkClient.listApiDestinations(request);
Console.log(Util.toJSONString(res.body));
} catch(err) {
Console.log('err!');
Console.log(err.message);
} finally {
Console.log('test end!');
}

}
Loading
Loading