Skip to content

Commit

Permalink
feat:add error handler to runtime.
Browse files Browse the repository at this point in the history
  • Loading branch information
2011shenlin committed Jun 15, 2023
1 parent 02cb142 commit 44c3b6b
Show file tree
Hide file tree
Showing 20 changed files with 349 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import org.apache.rocketmq.eventbridge.adapter.api.dto.target.DeadLetterQueueDTO;
import org.apache.rocketmq.eventbridge.adapter.api.dto.target.EventTargetDTO;
import org.apache.rocketmq.eventbridge.adapter.api.dto.target.RetryStrategyDTO;
import org.apache.rocketmq.eventbridge.domain.common.enums.ErrorToleranceEnum;
import org.apache.rocketmq.eventbridge.domain.common.enums.PushRetryStrategyEnum;
import org.apache.rocketmq.eventbridge.enums.ErrorToleranceEnum;
import org.apache.rocketmq.eventbridge.enums.PushRetryStrategyEnum;
import org.apache.rocketmq.eventbridge.domain.model.run.DeadLetterQueue;
import org.apache.rocketmq.eventbridge.domain.model.run.RetryStrategy;
import org.apache.rocketmq.eventbridge.domain.model.run.RunOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.rocketmq.eventbridge.adapter.api.dto.target.EventTargetDTO;
import org.apache.rocketmq.eventbridge.adapter.api.dto.target.RetryStrategyDTO;
import org.apache.rocketmq.eventbridge.adapter.api.dto.target.RunOptionsDTO;
import org.apache.rocketmq.eventbridge.domain.common.enums.ErrorToleranceEnum;
import org.apache.rocketmq.eventbridge.enums.ErrorToleranceEnum;
import org.apache.rocketmq.eventbridge.domain.model.run.DeadLetterQueue;
import org.apache.rocketmq.eventbridge.domain.model.run.RetryStrategy;
import org.apache.rocketmq.eventbridge.domain.model.run.RunOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import org.apache.rocketmq.eventbridge.adapter.api.dto.target.EventTargetDTO;
import org.apache.rocketmq.eventbridge.adapter.api.dto.target.RetryStrategyDTO;
import org.apache.rocketmq.eventbridge.adapter.api.dto.target.RunOptionsDTO;
import org.apache.rocketmq.eventbridge.domain.common.enums.ErrorToleranceEnum;
import org.apache.rocketmq.eventbridge.domain.common.enums.PushRetryStrategyEnum;
import org.apache.rocketmq.eventbridge.enums.ErrorToleranceEnum;
import org.apache.rocketmq.eventbridge.enums.PushRetryStrategyEnum;
import org.apache.rocketmq.eventbridge.domain.model.run.DeadLetterQueue;
import org.apache.rocketmq.eventbridge.domain.model.run.RetryStrategy;
import org.apache.rocketmq.eventbridge.domain.model.target.EventTarget;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import java.util.Collections;
import org.apache.rocketmq.eventbridge.adapter.api.dto.target.EventTargetDTO;
import org.apache.rocketmq.eventbridge.domain.common.enums.ErrorToleranceEnum;
import org.apache.rocketmq.eventbridge.domain.common.enums.PushRetryStrategyEnum;
import org.apache.rocketmq.eventbridge.enums.ErrorToleranceEnum;
import org.apache.rocketmq.eventbridge.enums.PushRetryStrategyEnum;
import org.apache.rocketmq.eventbridge.domain.model.run.DeadLetterQueue;
import org.apache.rocketmq.eventbridge.domain.model.run.RetryStrategy;
import org.apache.rocketmq.eventbridge.domain.model.run.RunOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@
*/
package org.apache.rocketmq.eventbridge.adapter.persistence.data.rocketmq.repository;

import com.google.common.collect.Maps;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.common.protocol.body.ClusterInfo;
import org.apache.rocketmq.common.protocol.route.BrokerData;
import org.apache.rocketmq.eventbridge.exception.EventBridgeException;
import org.apache.rocketmq.eventbridge.exception.code.DefaultErrorCode;
import org.apache.rocketmq.remoting.exception.RemotingConnectException;
import org.apache.rocketmq.remoting.exception.RemotingSendRequestException;
import org.apache.rocketmq.remoting.exception.RemotingTimeoutException;
import org.apache.rocketmq.remoting.protocol.body.ClusterInfo;
import org.apache.rocketmq.remoting.protocol.route.BrokerData;
import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
import org.springframework.stereotype.Service;

Expand All @@ -47,7 +48,7 @@ public RocketMQMetaService(DefaultMQAdminExt defaultMQAdminExt) {

public boolean createTopic(String clusterName, String topicName) {
try {
defaultMQAdminExt.createTopic(clusterName, topicName, DEFAULT_QUEUE_NUM);
defaultMQAdminExt.createTopic(clusterName, topicName, DEFAULT_QUEUE_NUM, Maps.newHashMap());
} catch (MQClientException e) {
log.error("Create topic failed.", e);
throw new EventBridgeException(DefaultErrorCode.InternalError, e);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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.rocketmq.eventbridge.adapter.runtimer.boot.listener;

import com.google.common.collect.Maps;
import java.util.Map;
import org.apache.rocketmq.eventbridge.adapter.runtimer.common.entity.TargetRunnerConfig;

public class TargetRunnerContext implements TargetRunnerListener {

public static Map<String, TargetRunnerConfig> targetRunnerConfigMap = Maps.newHashMap();

@Override
public void onAddTargetRunner(TargetRunnerConfig targetRunnerConfig) {

}

@Override
public void onUpdateTargetRunner(TargetRunnerConfig targetRunnerConfig) {

}

@Override
public void onDeleteTargetRunner(TargetRunnerConfig targetRunnerConfig) {

}

public static TargetRunnerConfig getTargetRunnerConfig(String targetRunnerName) {
return targetRunnerConfigMap.get(targetRunnerName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.rocketmq.eventbridge.adapter.runtimer.boot.pusher;

import com.google.common.collect.Lists;
import io.openmessaging.connector.api.data.ConnectRecord;
import java.util.List;
import org.apache.rocketmq.eventbridge.adapter.runtimer.boot.listener.EventSubscriber;
import org.springframework.beans.factory.annotation.Autowired;

public class PushCallback {

@Autowired
EventSubscriber eventSubscriber;

public void completed(ConnectRecord connectRecord) {
eventSubscriber.commit(Lists.newArrayList(connectRecord));
}

public void completed(List<ConnectRecord> connectRecords) {
eventSubscriber.commit(connectRecords);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.rocketmq.eventbridge.adapter.runtimer.boot.pusher;

import io.openmessaging.connector.api.data.ConnectRecord;
import java.util.List;
import lombok.Data;

@Data
public class PushRequest {

private String targetRunnerName;

private String targetClass;

private List<ConnectRecord> connectRecords;

private PushCallback pushCallback;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.openmessaging.connector.api.component.Transform;
import io.openmessaging.connector.api.data.ConnectRecord;
import io.openmessaging.internal.DefaultKeyValue;
import java.util.Map;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.eventbridge.adapter.runtimer.common.LoggerName;
Expand All @@ -43,6 +44,8 @@ public class TransformEngine<R extends ConnectRecord> implements AutoCloseable {

private final List<Transform> transformList;

private Map<String,List<Transform>> transformListMap;

private final KeyValue config;

private final Plugin plugin;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.rocketmq.eventbridge.adapter.runtimer.common.entity;

import lombok.Data;

@Data
public class RunOptions {

private String errorsTolerance;

private String retryStrategy;

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.util.Objects;
import lombok.Data;

import static org.apache.rocketmq.eventbridge.adapter.runtimer.config.RuntimerConfigDefine.TARGET_RUNNER_KEY;

/**
* pusher target key config
*/
Expand All @@ -36,6 +38,8 @@ public class TargetRunnerConfig implements Serializable {
*/
private List<Map<String, String>> components;

private RunOptions runOptions = new RunOptions();

@Override
public boolean equals(Object o) {
if (this == o)
Expand Down Expand Up @@ -99,4 +103,8 @@ private boolean isEqualsComponents(List<Map<String, String>> source, List<Map<St
}
return true;
}

public String getEventBusName() {
return components.get(0).get(TARGET_RUNNER_KEY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.apache.rocketmq.eventbridge.adapter.runtimer.config;

import io.openmessaging.connector.api.data.ConnectRecord;

import java.util.HashSet;
import java.util.Set;

Expand Down Expand Up @@ -98,6 +97,10 @@ public class RuntimerConfigDefine {

public static final String TRANSFORMS = "transforms";

public static final String CONNECT_RECORDS_KEY = "SYSTEM_RETRY_TIMES";

public static final String TARGET_RUNNER_KEY = "eventBusName";

/**
* The required key for all configurations.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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.rocketmq.eventbridge.adapter.runtimer.retry;

public class DeadLetterQueueService {

}
Loading

0 comments on commit 44c3b6b

Please sign in to comment.