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

update Eventmeshmessage plugin #599

Merged
merged 40 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
fb84d90
[Feature #564] Support CloudEvents protocols for pub/sub in EventMesh…
xwm1992 Oct 28, 2021
4e55912
support cloudevents api in eventmesh-connector-api module
xwm1992 Nov 1, 2021
e602004
Merge branch 'develop' of https://github.com/apache/incubator-eventme…
xwm1992 Nov 1, 2021
9adb5e9
Merge branch 'develop' of https://github.com/apache/incubator-eventme…
xwm1992 Nov 1, 2021
670c2f2
fix checkStyle
xwm1992 Nov 1, 2021
691bcb3
fix checkStyle
xwm1992 Nov 1, 2021
b6a4613
fix checkStyle
xwm1992 Nov 1, 2021
0ac6d4f
1.support LifeCycle.java
xwm1992 Nov 1, 2021
2239a65
fix remove the extra blank line
xwm1992 Nov 1, 2021
086f4e6
Merge branch 'cloudevents' of https://github.com/apache/incubator-eve…
xwm1992 Nov 2, 2021
308dfd7
support cloudEvents
xwm1992 Nov 2, 2021
f288ae2
Add files via upload
qqeasonchen Nov 3, 2021
09b9a22
Update README.md
qqeasonchen Nov 3, 2021
f0f3108
support cloudEvents
xwm1992 Nov 8, 2021
0290837
support cloudEvents
xwm1992 Nov 9, 2021
90a28cc
[ISSUE #580] Add checkstyle gradle plugin (#581)
ruanwenjun Nov 10, 2021
4425aaf
support cloudEvents
xwm1992 Nov 10, 2021
0dce0ca
support cloudevents
xwm1992 Nov 10, 2021
9251e07
update wechat-official qr code
xwm1992 Nov 11, 2021
ff1c247
update mesh-helper qr code
xwm1992 Nov 11, 2021
00994c3
Add files via upload
qqeasonchen Nov 11, 2021
bcf0337
update README.md
xwm1992 Nov 11, 2021
4938cd7
update README.md
xwm1992 Nov 11, 2021
61d0410
Update .asf.yaml
qqeasonchen Nov 11, 2021
3166325
support cloudEvents
xwm1992 Nov 11, 2021
bbd3535
support cloudEvents
xwm1992 Nov 12, 2021
de99c54
Merge branch 'cloudevents' of https://github.com/apache/incubator-eve…
xwm1992 Nov 12, 2021
ceaf33b
[ISSUE #588] Fix typo in README.md (#589)
nichozhan Nov 15, 2021
468386c
Merge branch 'cloudevents' of https://github.com/apache/incubator-eve…
xwm1992 Nov 16, 2021
d2d2b7d
support cloudEvents
xwm1992 Nov 16, 2021
46f973d
[Bug #590] Consumer subscription topic is invalid (#590) (#592)
hagsyn Nov 16, 2021
cf8433a
support cloudEvents adaptor
xwm1992 Nov 16, 2021
18310a1
[Feature #562] Implement CloudEvents adaptor
xwm1992 Nov 17, 2021
3149552
Merge branch 'develop' of https://github.com/apache/incubator-eventme…
xwm1992 Nov 17, 2021
d7ddac8
Merge branch 'cloudevents' of https://github.com/apache/incubator-eve…
xwm1992 Nov 17, 2021
c534985
[Feature #562] Implement EventMeshMessage protocol adaptor
xwm1992 Nov 18, 2021
024e462
Merge branch 'cloudevents' of https://github.com/apache/incubator-eve…
xwm1992 Nov 18, 2021
f096294
supplement apache header
xwm1992 Nov 18, 2021
46d8a51
Merge branch 'cloudevents' of https://github.com/apache/incubator-eve…
xwm1992 Nov 19, 2021
0f34e98
1.update package name
xwm1992 Nov 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Feature #562] Implement CloudEvents adaptor
  • Loading branch information
xwm1992 committed Nov 17, 2021
commit 18310a1ef3761810e04d2a502fc43168ff10789d
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public class ProtocolKey {
public static final String LANGUAGE = "Language";
public static final String VERSION = "Version";

public static final String PROTOCOL_TYPE = "protocol_type";

public static final String PROTOCOL_VERSION = "protocol_version";

public static final String PROTOCOL_DESC = "protocol_desc";

public static class ClientInstanceKey {
////////////////////////////////////Protocol layer requester description///////////
public static final String ENV = "Env";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ public class ReplyMessageRequestHeader extends Header {
//protocol version adopted by requester, default:1.0
private ProtocolVersion version;

//protocol type, cloudevents or eventmeshMessage
private String protocolType;

//protocol version, cloudevents:1.0 or 0.3
private String protocolVersion;

//protocol desc
private String protocolDesc;

//the environment number of the requester
private String env;

Expand Down Expand Up @@ -139,10 +148,37 @@ public void setIp(String ip) {
this.ip = ip;
}

public String getProtocolType() {
return protocolType;
}

public void setProtocolType(String protocolType) {
this.protocolType = protocolType;
}

public String getProtocolVersion() {
return protocolVersion;
}

public void setProtocolVersion(String protocolVersion) {
this.protocolVersion = protocolVersion;
}

public String getProtocolDesc() {
return protocolDesc;
}

public void setProtocolDesc(String protocolDesc) {
this.protocolDesc = protocolDesc;
}

public static ReplyMessageRequestHeader buildHeader(Map<String, Object> headerParam) {
ReplyMessageRequestHeader header = new ReplyMessageRequestHeader();
header.setCode(MapUtils.getString(headerParam, ProtocolKey.REQUEST_CODE));
header.setVersion(ProtocolVersion.get(MapUtils.getString(headerParam, ProtocolKey.VERSION)));
header.setProtocolType(MapUtils.getString(headerParam, ProtocolKey.PROTOCOL_TYPE));
header.setProtocolVersion(MapUtils.getString(headerParam, ProtocolKey.PROTOCOL_VERSION));
header.setProtocolDesc(MapUtils.getString(headerParam, ProtocolKey.PROTOCOL_DESC));
String lan = StringUtils.isBlank(MapUtils.getString(headerParam, ProtocolKey.LANGUAGE))
? Constants.LANGUAGE_JAVA : MapUtils.getString(headerParam, ProtocolKey.LANGUAGE);
header.setLanguage(lan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ public class SendMessageBatchRequestHeader extends Header {
//protocol version adopted by requester, default:1.0
private ProtocolVersion version;

//protocol type, cloudevents or eventmeshMessage
private String protocolType;

//protocol version, cloudevents:1.0 or 0.3
private String protocolVersion;

//protocol desc
private String protocolDesc;

//the environment number of the requester
private String env;

Expand Down Expand Up @@ -140,10 +149,37 @@ public void setIp(String ip) {
this.ip = ip;
}

public String getProtocolType() {
return protocolType;
}

public void setProtocolType(String protocolType) {
this.protocolType = protocolType;
}

public String getProtocolVersion() {
return protocolVersion;
}

public void setProtocolVersion(String protocolVersion) {
this.protocolVersion = protocolVersion;
}

public String getProtocolDesc() {
return protocolDesc;
}

public void setProtocolDesc(String protocolDesc) {
this.protocolDesc = protocolDesc;
}

public static SendMessageBatchRequestHeader buildHeader(final Map<String, Object> headerParam) {
SendMessageBatchRequestHeader header = new SendMessageBatchRequestHeader();
header.setCode(MapUtils.getString(headerParam, ProtocolKey.REQUEST_CODE));
header.setVersion(ProtocolVersion.get(MapUtils.getString(headerParam, ProtocolKey.VERSION)));
header.setProtocolType(MapUtils.getString(headerParam, ProtocolKey.PROTOCOL_TYPE));
header.setProtocolVersion(MapUtils.getString(headerParam, ProtocolKey.PROTOCOL_VERSION));
header.setProtocolDesc(MapUtils.getString(headerParam, ProtocolKey.PROTOCOL_DESC));
String lan = StringUtils.isBlank(MapUtils.getString(headerParam, ProtocolKey.LANGUAGE))
? Constants.LANGUAGE_JAVA : MapUtils.getString(headerParam, ProtocolKey.LANGUAGE);
header.setLanguage(lan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ public class SendMessageBatchV2RequestHeader extends Header {
//protocol version adopted by requester, default:1.0
private ProtocolVersion version;

//protocol type, cloudevents or eventmeshMessage
private String protocolType;

//protocol version, cloudevents:1.0 or 0.3
private String protocolVersion;

//protocol desc
private String protocolDesc;

//the environment number of the requester
private String env;

Expand Down Expand Up @@ -139,10 +148,38 @@ public void setIp(String ip) {
this.ip = ip;
}

public String getProtocolType() {
return protocolType;
}

public void setProtocolType(String protocolType) {
this.protocolType = protocolType;
}

public String getProtocolVersion() {
return protocolVersion;
}

public void setProtocolVersion(String protocolVersion) {
this.protocolVersion = protocolVersion;
}

public String getProtocolDesc() {
return protocolDesc;
}

public void setProtocolDesc(String protocolDesc) {
this.protocolDesc = protocolDesc;
}

public static SendMessageBatchV2RequestHeader buildHeader(final Map<String, Object> headerParam) {
SendMessageBatchV2RequestHeader header = new SendMessageBatchV2RequestHeader();
header.setCode(MapUtils.getString(headerParam, ProtocolKey.REQUEST_CODE));
header.setVersion(ProtocolVersion.get(MapUtils.getString(headerParam, ProtocolKey.VERSION)));
header.setProtocolType(MapUtils.getString(headerParam, ProtocolKey.PROTOCOL_TYPE));
header.setProtocolVersion(MapUtils.getString(headerParam, ProtocolKey.PROTOCOL_VERSION));
header.setProtocolDesc(MapUtils.getString(headerParam, ProtocolKey.PROTOCOL_DESC));

String lan = StringUtils.isBlank(MapUtils.getString(headerParam, ProtocolKey.LANGUAGE))
? Constants.LANGUAGE_JAVA : MapUtils.getString(headerParam, ProtocolKey.LANGUAGE);
header.setLanguage(lan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ public class SendMessageRequestHeader extends Header {
//protocol version adopted by requester, default:1.0
private ProtocolVersion version;

//protocol type, cloudevents or eventmeshMessage
private String protocolType;

//protocol version, cloudevents:1.0 or 0.3
private String protocolVersion;

//protocol desc
private String protocolDesc;

//the environment number of the requester
private String env;

Expand Down Expand Up @@ -139,10 +148,38 @@ public void setIp(String ip) {
this.ip = ip;
}

public String getProtocolType() {
return protocolType;
}

public void setProtocolType(String protocolType) {
this.protocolType = protocolType;
}

public String getProtocolVersion() {
return protocolVersion;
}

public void setProtocolVersion(String protocolVersion) {
this.protocolVersion = protocolVersion;
}

public String getProtocolDesc() {
return protocolDesc;
}

public void setProtocolDesc(String protocolDesc) {
this.protocolDesc = protocolDesc;
}

public static SendMessageRequestHeader buildHeader(Map<String, Object> headerParam) {
SendMessageRequestHeader header = new SendMessageRequestHeader();
header.setCode(MapUtils.getString(headerParam, ProtocolKey.REQUEST_CODE));
header.setVersion(ProtocolVersion.get(MapUtils.getString(headerParam, ProtocolKey.VERSION)));
header.setProtocolType(MapUtils.getString(headerParam, ProtocolKey.PROTOCOL_TYPE));
header.setProtocolVersion(MapUtils.getString(headerParam, ProtocolKey.PROTOCOL_VERSION));
header.setProtocolDesc(MapUtils.getString(headerParam, ProtocolKey.PROTOCOL_DESC));

String lan = StringUtils.isBlank(MapUtils.getString(headerParam, ProtocolKey.LANGUAGE))
? Constants.LANGUAGE_JAVA : MapUtils.getString(headerParam, ProtocolKey.LANGUAGE);
header.setLanguage(lan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@
package org.apache.eventmesh.protocol.cloudevents;

import io.cloudevents.CloudEvent;
import io.cloudevents.core.builder.CloudEventBuilder;
import org.apache.commons.lang3.StringUtils;
import org.apache.eventmesh.common.Constants;
import org.apache.eventmesh.common.command.HttpCommand;
import org.apache.eventmesh.common.protocol.http.body.Body;
import org.apache.eventmesh.common.protocol.http.common.RequestCode;
import org.apache.eventmesh.common.protocol.tcp.Header;
import org.apache.eventmesh.common.protocol.tcp.Package;
import org.apache.eventmesh.protocol.api.ProtocolAdaptor;

import org.apache.eventmesh.protocol.api.exception.ProtocolHandleException;
import org.apache.eventmesh.protocol.cloudevents.resolver.http.SendMessageBatchProtocolResolver;
import org.apache.eventmesh.protocol.cloudevents.resolver.http.SendMessageBatchV2ProtocolResolver;
import org.apache.eventmesh.protocol.cloudevents.resolver.http.SendMessageRequestProtocolResolver;
import org.apache.eventmesh.protocol.cloudevents.resolver.tcp.TcpMessageProtocolResolver;

import java.nio.charset.StandardCharsets;
import java.util.List;
Expand All @@ -42,55 +46,41 @@ public class CloudEventsProtocolAdaptor<T> implements ProtocolAdaptor<T> {
@Override
public CloudEvent toCloudEvent(T cloudEvent) throws ProtocolHandleException {

CloudEventBuilder cloudEventBuilder;

if (cloudEvent instanceof Package) {

Header header = ((Package) cloudEvent).getHeader();
Object body = ((Package) cloudEvent).getBody();
String protocolType = header.getProperty(Constants.PROTOCOL_TYPE).toString();
String protocolVersion = header.getProperty(Constants.PROTOCOL_VERSION).toString();
String protocolDesc = header.getProperty(Constants.PROTOCOL_DESC).toString();

if (StringUtils.isBlank(protocolType)
|| StringUtils.isBlank(protocolVersion)
|| StringUtils.isBlank(protocolDesc)) {
throw new ProtocolHandleException(String.format("invalid protocol params protocolType %s|protocolVersion %s|protocolDesc %s",
protocolType, protocolVersion, protocolDesc));
}

if (!StringUtils.equals("cloudevents", protocolType)) {
throw new ProtocolHandleException(String.format("Unsupported protocolType: %s", protocolType));
}
if (StringUtils.equals("1.0", protocolVersion)) {
cloudEventBuilder = CloudEventBuilder.v1((CloudEvent) body);

for (String propKey : header.getProperties().keySet()) {
cloudEventBuilder.withExtension(propKey, header.getProperty(propKey).toString());
}
return deserializeTcpProtocol(header, body);

return cloudEventBuilder.build();
} else if (cloudEvent instanceof HttpCommand) {
org.apache.eventmesh.common.protocol.http.header.Header header = ((HttpCommand) cloudEvent).getHeader();
Body body = ((HttpCommand) cloudEvent).getBody();
String requestCode = ((HttpCommand) cloudEvent).getRequestCode();

} else if (StringUtils.equals("0.3", protocolVersion)) {
cloudEventBuilder = CloudEventBuilder.v03((CloudEvent) body);
return deserializeHttpProtocol(requestCode, header, body);
} else {
throw new ProtocolHandleException(String.format("protocol class: %s", cloudEvent.getClass()));
}
}

for (String propKey : header.getProperties().keySet()) {
cloudEventBuilder.withExtension(propKey, header.getProperty(propKey).toString());
}
private CloudEvent deserializeTcpProtocol(Header header, Object body) throws ProtocolHandleException {
return TcpMessageProtocolResolver.buildEvent(header, body);
}

return cloudEventBuilder.build();
private CloudEvent deserializeHttpProtocol(String requestCode, org.apache.eventmesh.common.protocol.http.header.Header header, Body body) throws ProtocolHandleException {

} else {
throw new ProtocolHandleException(String.format("Unsupported protocolVersion: %s", protocolVersion));
}
} else if (cloudEvent instanceof HttpCommand) {
org.apache.eventmesh.common.protocol.http.header.Header header = ((HttpCommand) cloudEvent).getHeader();
Body body = ((HttpCommand) cloudEvent).getBody();
//todo:convert httpCommand to cloudevents
if (String.valueOf(RequestCode.MSG_BATCH_SEND.getRequestCode()).equals(requestCode)) {
return SendMessageBatchProtocolResolver.buildEvent(header, body);
} else if (String.valueOf(RequestCode.MSG_BATCH_SEND_V2.getRequestCode()).equals(requestCode)) {
return SendMessageBatchV2ProtocolResolver.buildEvent(header, body);
} else if (String.valueOf(RequestCode.MSG_SEND_SYNC.getRequestCode()).equals(requestCode)) {
return SendMessageRequestProtocolResolver.buildEvent(header, body);
} else if (String.valueOf(RequestCode.MSG_SEND_ASYNC.getRequestCode()).equals(requestCode)) {
return SendMessageRequestProtocolResolver.buildEvent(header, body);
} else {
throw new ProtocolHandleException("protocol class: " + cloudEvent.getClass());
throw new ProtocolHandleException(String.format("unsupported requestCode: %s", requestCode));
}
return null;

}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.apache.eventmesh.protocol.cloudevents.resolver.http;

import io.cloudevents.CloudEvent;
import org.apache.eventmesh.common.protocol.http.body.Body;
import org.apache.eventmesh.common.protocol.http.header.Header;

public class SendMessageBatchProtocolResolver {
public static CloudEvent buildEvent(Header header, Body body) {
return null;
}
}
Loading