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
support cloudEvents
  • Loading branch information
xwm1992 committed Nov 8, 2021
commit f0f31086329cfcbe517e8210020e1e5c5ea2da85
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package org.apache.eventmesh.api;

import io.openmessaging.api.Action;
import io.openmessaging.api.AsyncConsumeContext;

public abstract class EventMeshAsyncConsumeContext extends AsyncConsumeContext {

Expand All @@ -34,8 +32,4 @@ public void setAbstractContext(AbstractContext abstractContext) {

public abstract void commit(EventMeshAction action);

@Override
public void commit(Action action) {
throw new UnsupportedOperationException("not support yet");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.apache.eventmesh.api;

import io.cloudevents.CloudEvent;

public interface RequestReplyCallback {

void onSuccess(CloudEvent event);

void onException(Throwable e);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@

package org.apache.eventmesh.api.producer;

import org.apache.eventmesh.api.LifeCycle;
import org.apache.eventmesh.api.RRCallback;
import org.apache.eventmesh.api.SendCallback;
import org.apache.eventmesh.api.SendResult;
import org.apache.eventmesh.api.*;
import org.apache.eventmesh.spi.EventMeshExtensionType;
import org.apache.eventmesh.spi.EventMeshSPI;

Expand All @@ -44,7 +41,7 @@ public interface Producer extends LifeCycle {

void sendAsync(final CloudEvent cloudEvent, final SendCallback sendCallback);

void request(CloudEvent cloudEvent, RRCallback rrCallback, long timeout) throws Exception;
void request(CloudEvent cloudEvent, RequestReplyCallback rrCallback, long timeout) throws Exception;

boolean reply(final CloudEvent cloudEvent, final SendCallback sendCallback) throws Exception;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@
import java.util.Collections;
import java.util.Properties;

import io.openmessaging.api.AsyncConsumeContext;
import io.openmessaging.api.AsyncMessageListener;
import io.openmessaging.api.Consumer;
import io.openmessaging.api.Message;
import io.openmessaging.api.MessagingAccessPoint;
import io.openmessaging.api.OMS;
import io.openmessaging.api.OMSBuiltinKeys;
import io.openmessaging.api.*;

import org.apache.eventmesh.api.EventMeshAction;
import org.apache.eventmesh.api.EventMeshAsyncConsumeContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

dependencies {
implementation project(":eventmesh-spi")
implementation project(":eventmesh-common")
api project(":eventmesh-common")

implementation "io.cloudevents:cloudevents-core"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.eventmesh.protocol.api;

import org.apache.eventmesh.common.protocol.tcp.Package;
import org.apache.eventmesh.protocol.api.exception.ProtocolHandleException;
import org.apache.eventmesh.spi.EventMeshExtensionType;
import org.apache.eventmesh.spi.EventMeshSPI;
Expand All @@ -32,15 +33,15 @@
* @since 1.3.0
*/
@EventMeshSPI(isSingleton = true, eventMeshExtensionType = EventMeshExtensionType.PROTOCOL)
public interface ProtocolAdaptor {
public interface ProtocolAdaptor<T> {

/**
* transform protocol to {@link CloudEvent}.
*
* @param protocol input protocol
* @return cloud event
*/
CloudEventV1 toCloudEventV1(Package protocol) throws ProtocolHandleException;
CloudEventV1 toCloudEventV1(T protocol) throws ProtocolHandleException;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.eventmesh.protocol.cloudevents;

import org.apache.eventmesh.common.command.HttpCommand;
import org.apache.eventmesh.common.protocol.tcp.Package;
import org.apache.eventmesh.protocol.api.ProtocolAdaptor;

import io.cloudevents.core.v1.CloudEventV1;
Expand All @@ -26,10 +28,16 @@
*
* @since 1.3.0
*/
public class CloudEventsProtocolAdaptor implements ProtocolAdaptor {
public class CloudEventsProtocolAdaptor<T> implements ProtocolAdaptor<T> {

@Override
public CloudEventV1 toCloudEventV1(Package cloudEvent) {
public CloudEventV1 toCloudEventV1(T cloudEvent) {

if (cloudEvent instanceof Package){
//todo:convert package to cloudevents
}else if (cloudEvent instanceof HttpCommand){
//todo:convert httpCommand to cloudevents
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.eventmesh.protocol.openmessage;

import org.apache.eventmesh.common.protocol.tcp.Package;
import org.apache.eventmesh.protocol.api.ProtocolAdaptor;

import io.cloudevents.CloudEvent;
Expand All @@ -29,10 +30,10 @@
*
* @since 1.3.0
*/
public class OpenMessageProtocolAdaptor implements ProtocolAdaptor {
public class OpenMessageProtocolAdaptor<T> implements ProtocolAdaptor<T> {

@Override
public CloudEventV1 toCloudEventV1(Package message) {
public CloudEventV1 toCloudEventV1(T message) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Properties;

import org.apache.eventmesh.api.RRCallback;
import org.apache.eventmesh.api.RequestReplyCallback;
import org.apache.eventmesh.api.SendCallback;
import org.apache.eventmesh.api.factory.ConnectorPluginFactory;
import org.apache.eventmesh.api.producer.Producer;
Expand Down Expand Up @@ -80,7 +81,7 @@ public void send(CloudEvent cloudEvent, SendCallback sendCallback) throws Except
meshMQProducer.publish(cloudEvent, sendCallback);
}

public void request(CloudEvent cloudEvent, RRCallback rrCallback, long timeout)
public void request(CloudEvent cloudEvent, RequestReplyCallback rrCallback, long timeout)
throws Exception {
meshMQProducer.request(cloudEvent, rrCallback, timeout);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import io.cloudevents.CloudEvent;

import io.cloudevents.core.v1.CloudEventBuilder;
import org.apache.commons.collections4.MapUtils;
import org.apache.eventmesh.api.*;
import org.apache.eventmesh.api.exception.OnExceptionContext;
Expand Down Expand Up @@ -109,14 +110,17 @@ public void subscribe(String topic, SubscriptionItem subscriptionItem) throws Ex
listener = new EventListener() {
@Override
public void consume(CloudEvent event, AsyncConsumeContext context) {
String topic = event.getExtension(Constants.PROPERTY_MESSAGE_DESTINATION);
String topic = event.getSubject();
// String topic = message.getSystemProperties(Constants.PROPERTY_MESSAGE_DESTINATION);
String bizSeqNo = message.getSystemProperties(Constants.PROPERTY_MESSAGE_SEARCH_KEYS);
String uniqueId = message.getUserProperties(Constants.RMB_UNIQ_ID);
String bizSeqNo = (String) event.getExtension(Constants.PROPERTY_MESSAGE_SEARCH_KEYS);
String uniqueId = (String) event.getExtension(Constants.RMB_UNIQ_ID);

message.getUserProperties().put(EventMeshConstants.REQ_MQ2EVENTMESH_TIMESTAMP, String.valueOf(System.currentTimeMillis()));
event = new CloudEventBuilder(event)
.withExtension(EventMeshConstants.REQ_MQ2EVENTMESH_TIMESTAMP, String.valueOf(System.currentTimeMillis()))
.build();
// message.getUserProperties().put(EventMeshConstants.REQ_MQ2EVENTMESH_TIMESTAMP, String.valueOf(System.currentTimeMillis()));
if (messageLogger.isDebugEnabled()) {
messageLogger.debug("message|mq2eventMesh|topic={}|msg={}", topic, message);
messageLogger.debug("message|mq2eventMesh|topic={}|event={}", topic, event);
} else {
messageLogger.info("message|mq2eventMesh|topic={}|bizSeqNo={}|uniqueId={}", topic, bizSeqNo, uniqueId);
}
Expand All @@ -127,7 +131,7 @@ public void consume(CloudEvent event, AsyncConsumeContext context) {
if (currentTopicConfig == null) {
logger.error("no topicConfig found, consumerGroup:{} topic:{}", consumerGroupConf.getConsumerGroup(), topic);
try {
sendMessageBack(message, uniqueId, bizSeqNo);
sendMessageBack(event, uniqueId, bizSeqNo);
// context.attributes().put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.CONSUME_SUCCESS.name());
// context.ack();
eventMeshAsyncConsumeContext.commit(EventMeshAction.CommitMessage);
Expand All @@ -136,15 +140,15 @@ public void consume(CloudEvent event, AsyncConsumeContext context) {
}
}
HandleMsgContext handleMsgContext = new HandleMsgContext(EventMeshUtil.buildPushMsgSeqNo(), consumerGroupConf.getConsumerGroup(), EventMeshConsumer.this,
topic, message, subscriptionItem, eventMeshAsyncConsumeContext.getAbstractContext(), consumerGroupConf, eventMeshHTTPServer, bizSeqNo, uniqueId, currentTopicConfig);
topic, event, subscriptionItem, eventMeshAsyncConsumeContext.getAbstractContext(), consumerGroupConf, eventMeshHTTPServer, bizSeqNo, uniqueId, currentTopicConfig);

if (httpMessageHandler.handle(handleMsgContext)) {
// context.attributes().put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.CONSUME_FINISH.name());
// context.ack();
eventMeshAsyncConsumeContext.commit(EventMeshAction.ManualAck);
} else {
try {
sendMessageBack(message, uniqueId, bizSeqNo);
sendMessageBack(event, uniqueId, bizSeqNo);
} catch (Exception e) {

}
Expand Down Expand Up @@ -177,7 +181,7 @@ public void consume(CloudEvent event, AsyncConsumeContext context) {
if (currentTopicConfig == null) {
logger.error("no topicConfig found, consumerGroup:{} topic:{}", consumerGroupConf.getConsumerGroup(), topic);
try {
sendMessageBack(message, uniqueId, bizSeqNo);
sendMessageBack(event, uniqueId, bizSeqNo);
// context.attributes().put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.CONSUME_SUCCESS.name());
// context.ack();
eventMeshAsyncConsumeContext.commit(EventMeshAction.CommitMessage);
Expand All @@ -186,15 +190,15 @@ public void consume(CloudEvent event, AsyncConsumeContext context) {
}
}
HandleMsgContext handleMsgContext = new HandleMsgContext(EventMeshUtil.buildPushMsgSeqNo(), consumerGroupConf.getConsumerGroup(), EventMeshConsumer.this,
topic, message, subscriptionItem, eventMeshAsyncConsumeContext.getAbstractContext(), consumerGroupConf, eventMeshHTTPServer, bizSeqNo, uniqueId, currentTopicConfig);
topic, event, subscriptionItem, eventMeshAsyncConsumeContext.getAbstractContext(), consumerGroupConf, eventMeshHTTPServer, bizSeqNo, uniqueId, currentTopicConfig);

if (httpMessageHandler.handle(handleMsgContext)) {
// context.attributes().put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.CONSUME_FINISH.name());
// context.ack();
eventMeshAsyncConsumeContext.commit(EventMeshAction.ManualAck);
} else {
try {
sendMessageBack(message, uniqueId, bizSeqNo);
sendMessageBack(event, uniqueId, bizSeqNo);
} catch (Exception e) {

}
Expand Down Expand Up @@ -248,7 +252,7 @@ public EventMeshHTTPServer getEventMeshHTTPServer() {
return eventMeshHTTPServer;
}

public void sendMessageBack(final Message msgBack, final String uniqueId, String bizSeqNo) throws Exception {
public void sendMessageBack(final CloudEvent event, final String uniqueId, String bizSeqNo) throws Exception {

EventMeshProducer sendMessageBack
= eventMeshHTTPServer.getProducerManager().getEventMeshProducer(consumerGroupConf.getConsumerGroup());
Expand All @@ -258,7 +262,7 @@ public void sendMessageBack(final Message msgBack, final String uniqueId, String
return;
}

final SendMessageContext sendMessageBackContext = new SendMessageContext(bizSeqNo, msgBack, sendMessageBack, eventMeshHTTPServer);
final SendMessageContext sendMessageBackContext = new SendMessageContext(bizSeqNo, event, sendMessageBack, eventMeshHTTPServer);

sendMessageBack.send(sendMessageBackContext, new SendCallback() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
import java.util.HashMap;
import java.util.Map;

import io.openmessaging.api.Message;

import io.cloudevents.CloudEvent;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.eventmesh.api.AbstractContext;
Expand Down Expand Up @@ -53,7 +52,7 @@ public class HandleMsgContext {

private SubscriptionItem subscriptionItem;

private Message msg;
private CloudEvent event;

private int ttl;

Expand All @@ -70,22 +69,23 @@ public class HandleMsgContext {
private Map<String, String> props;

public HandleMsgContext(String msgRandomNo, String consumerGroup, EventMeshConsumer eventMeshConsumer,
String topic, Message msg, SubscriptionItem subscriptionItem,
String topic, CloudEvent event, SubscriptionItem subscriptionItem,
AbstractContext context, ConsumerGroupConf consumerGroupConfig,
EventMeshHTTPServer eventMeshHTTPServer, String bizSeqNo, String uniqueId, ConsumerGroupTopicConf consumeTopicConfig) {
this.msgRandomNo = msgRandomNo;
this.consumerGroup = consumerGroup;
this.eventMeshConsumer = eventMeshConsumer;
this.topic = topic;
this.msg = msg;
this.event = event;
this.subscriptionItem = subscriptionItem;
this.context = context;
this.consumerGroupConfig = consumerGroupConfig;
this.eventMeshHTTPServer = eventMeshHTTPServer;
this.bizSeqNo = bizSeqNo;
this.uniqueId = uniqueId;
this.consumeTopicConfig = consumeTopicConfig;
String ttlStr = msg.getUserProperties(Constants.PROPERTY_MESSAGE_TIMEOUT);

String ttlStr = (String) event.getExtension(Constants.PROPERTY_MESSAGE_TIMEOUT);
this.ttl = StringUtils.isNumeric(ttlStr)? Integer.parseInt(ttlStr): EventMeshConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS;
}

Expand Down Expand Up @@ -148,12 +148,12 @@ public void setTopic(String topic) {
this.topic = topic;
}

public Message getMsg() {
return msg;
public CloudEvent getEvent() {
return event;
}

public void setMsg(Message msg) {
this.msg = msg;
public void setEvent(CloudEvent event) {
this.event = event;
}

public SubscriptionItem getSubscriptionItem() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ public void onResponse(HttpCommand httpCommand) {
// replyMessageRequestBody.getContent());

try {
CloudEvent clone = new CloudEventBuilder(sendMessageContext.getEvent()).withExtension(EventMeshConstants.REQ_EVENTMESH2MQ_TIMESTAMP, String.valueOf(System.currentTimeMillis());
CloudEvent clone = new CloudEventBuilder(sendMessageContext.getEvent())
.withExtension(EventMeshConstants.REQ_EVENTMESH2MQ_TIMESTAMP, String.valueOf(System.currentTimeMillis()))
.build();
sendMessageContext.setEvent(clone);
eventMeshProducer.reply(sendMessageContext, new SendCallback() {
@Override
Expand Down
Loading