forked from apache/eventmesh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature apache#562] Implement EventMeshMessage protocol adaptor (apa…
…che#597) * [Feature apache#564] Support CloudEvents protocols for pub/sub in EventMesh-feature design * support cloudevents api in eventmesh-connector-api module * fix checkStyle * fix checkStyle * fix checkStyle * 1.support LifeCycle.java 2.update Consumer and Producer * fix remove the extra blank line * support cloudEvents * Add files via upload * Update README.md * support cloudEvents * support cloudEvents * [ISSUE apache#580] Add checkstyle gradle plugin (apache#581) * Add checkstyle gradle plugin, change plugin package * skip check in ci * support cloudEvents * support cloudevents * update wechat-official qr code * update mesh-helper qr code * Add files via upload * update README.md * update README.md * Update .asf.yaml * support cloudEvents * support cloudEvents * [ISSUE apache#588] Fix typo in README.md (apache#589) close apache#588 * support cloudEvents * [Bug apache#590] Consumer subscription topic is invalid (apache#590) (apache#592) * [Bug apache#590] Consumer subscription topic is invalid (apache#590) * [Bug apache#590] Consumer subscription topic is invalid (apache#590) close apache#590 * support cloudEvents adaptor * [Feature apache#562] Implement CloudEvents adaptor * [Feature apache#562] Implement EventMeshMessage protocol adaptor * supplement apache header Co-authored-by: Eason Chen <qqeasonchen@gmail.com> Co-authored-by: Wenjun Ruan <wenjun@apache.org> Co-authored-by: Nicholas Zhan <zhan_nicholas@outlook.com> Co-authored-by: hagsyn <44764414+hagsyn@users.noreply.github.com>
- Loading branch information
1 parent
6c2a85a
commit 3fec9e1
Showing
12 changed files
with
568 additions
and
49 deletions.
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
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
102 changes: 102 additions & 0 deletions
102
.../java/org/apache/eventmesh/protocol/eventmeshmessage/EventMeshMessageProtocolAdaptor.java
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,102 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.eventmesh.protocol.eventmeshmessage; | ||
|
||
import io.cloudevents.CloudEvent; | ||
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.EventMeshMessage; | ||
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.eventmeshmessage.resolver.http.SendMessageBatchProtocolResolver; | ||
import org.apache.eventmesh.protocol.eventmeshmessage.resolver.http.SendMessageBatchV2ProtocolResolver; | ||
import org.apache.eventmesh.protocol.eventmeshmessage.resolver.http.SendMessageRequestProtocolResolver; | ||
import org.apache.eventmesh.protocol.eventmeshmessage.resolver.tcp.TcpMessageProtocolResolver; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.List; | ||
|
||
public class EventMeshMessageProtocolAdaptor<T> implements ProtocolAdaptor<T> { | ||
|
||
@Override | ||
public CloudEvent toCloudEvent(T protocol) throws ProtocolHandleException { | ||
if (protocol instanceof Package) { | ||
Header header = ((Package) protocol).getHeader(); | ||
Object body = ((Package) protocol).getBody(); | ||
|
||
return deserializeTcpProtocol(header, body); | ||
|
||
} else if (protocol instanceof HttpCommand) { | ||
org.apache.eventmesh.common.protocol.http.header.Header header = ((HttpCommand) protocol).getHeader(); | ||
Body body = ((HttpCommand) protocol).getBody(); | ||
String requestCode = ((HttpCommand) protocol).getRequestCode(); | ||
|
||
return deserializeHttpProtocol(requestCode, header, body); | ||
} else { | ||
throw new ProtocolHandleException(String.format("protocol class: %s", protocol.getClass())); | ||
} | ||
} | ||
|
||
private CloudEvent deserializeTcpProtocol(Header header, Object body) throws ProtocolHandleException { | ||
return TcpMessageProtocolResolver.buildEvent(header, body); | ||
} | ||
|
||
private CloudEvent deserializeHttpProtocol(String requestCode, org.apache.eventmesh.common.protocol.http.header.Header header, Body body) throws ProtocolHandleException { | ||
|
||
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(String.format("unsupported requestCode: %s", requestCode)); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public List<CloudEvent> toBatchCloudEvent(T protocol) throws ProtocolHandleException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Object fromCloudEvent(CloudEvent cloudEvent) throws ProtocolHandleException { | ||
String protocolDesc = cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString(); | ||
|
||
if (StringUtils.equals("http", protocolDesc)) { | ||
return new String(cloudEvent.getData().toBytes(), StandardCharsets.UTF_8); | ||
} else if (StringUtils.equals("tcp", protocolDesc)) { | ||
return TcpMessageProtocolResolver.buildEventMeshMessage(cloudEvent); | ||
} else { | ||
throw new ProtocolHandleException(String.format("Unsupported protocolDesc: %s", protocolDesc)); | ||
} | ||
} | ||
|
||
@Override | ||
public String getProtocolType() { | ||
return EventMeshMessageProtocolConstant.PROTOCOL_NAME; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...java/org/apache/eventmesh/protocol/eventmeshmessage/EventMeshMessageProtocolConstant.java
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,23 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.eventmesh.protocol.eventmeshmessage; | ||
|
||
public enum EventMeshMessageProtocolConstant { | ||
; | ||
public static final String PROTOCOL_NAME = "eventmeshmessage"; | ||
} |
28 changes: 28 additions & 0 deletions
28
...e/eventmesh/protocol/eventmeshmessage/resolver/http/SendMessageBatchProtocolResolver.java
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,28 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.eventmesh.protocol.eventmeshmessage.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; | ||
} | ||
} |
Oops, something went wrong.