Jelajahi Sumber

因为 dynamic-datasource-spring-boot-starter 已经支持了 Seata 所以没有必须再保留 dts

hubin 5 tahun lalu
induk
melakukan
f3fb51d4a5

+ 0 - 15
mybatis-plus-dts/build.gradle

@@ -1,15 +0,0 @@
-dependencies {
-    api project(":mybatis-plus-core")
-    implementation(enforcedPlatform("org.springframework.boot:spring-boot-dependencies:${springBootVersion}" as String))
-    annotationProcessor "org.springframework.boot:spring-boot-configuration-processor:${springBootVersion}"
-    annotationProcessor "org.springframework.boot:spring-boot-autoconfigure-processor:${springBootVersion}"
-    api 'org.springframework.boot:spring-boot-autoconfigure'
-    implementation "${lib.aspectjrt}"
-    implementation 'org.springframework.boot:spring-boot-starter-web'
-    implementation 'org.springframework.boot:spring-boot-starter-amqp'
-    implementation 'org.springframework.boot:spring-boot-configuration-processor'
-    implementation 'org.springframework.boot:spring-boot-autoconfigure-processor'
-    testImplementation 'org.springframework.boot:spring-boot-starter-test'
-}
-
-compileJava.dependsOn(processResources)

+ 0 - 40
mybatis-plus-dts/src/main/java/com/baomidou/mybatisplus/dts/DtsConstants.java

@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
- * <p>
- * Licensed 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
- * <p>
- * https://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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 com.baomidou.mybatisplus.dts;
-
-/**
- * <p>
- * 常量类
- * </p>
- *
- * @author hubin
- * @since 2019-04-20
- */
-public interface DtsConstants {
-    /**
-     * 队列配置
-     */
-    String RABBIT_EXCHANGE = "dts-rmt-exchange";
-    String RABBIT_QUEUE = "dts-rmt-queue";
-    String RABBIT_ROUTINGKEY = "dts-rmt-routingkey";
-    /**
-     * 死信队列配置
-     */
-    String RABBIT_DEADLETTER_EXCHANGE = "dts-rmt-deadletter-exchange";
-    String RABBIT_DEADLETTER_QUEUE = "dts-rmt-deadletter-queue";
-    String RABBIT_DEADLETTER_ROUTINGKEY = "dts-rmt-deadletter-routingkey";
-
-}

+ 0 - 41
mybatis-plus-dts/src/main/java/com/baomidou/mybatisplus/dts/DtsMeta.java

@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
- * <p>
- * Licensed 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
- * <p>
- * https://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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 com.baomidou.mybatisplus.dts;
-
-import lombok.Data;
-import lombok.experimental.Accessors;
-
-/**
- * <p>
- * 分布式事务元数据
- * </p>
- *
- * @author jobob
- * @since 2019-04-20
- */
-@Data
-@Accessors(chain = true)
-public class DtsMeta {
-    /**
-     * 执行事件
-     */
-    String event;
-    /**
-     * 消息内容
-     */
-    Object payload;
-
-}

+ 0 - 41
mybatis-plus-dts/src/main/java/com/baomidou/mybatisplus/dts/EnableDtsRabbit.java

@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
- * <p>
- * Licensed 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
- * <p>
- * https://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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 com.baomidou.mybatisplus.dts;
-
-import com.baomidou.mybatisplus.dts.config.DtsAutoConfiguration;
-import com.baomidou.mybatisplus.dts.config.RabbitConfiguration;
-import org.springframework.context.annotation.Import;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-
-/**
- * <p>
- * 可靠消息事务自动配置
- * </p>
- *
- * @author jobob
- * @since 2019-04-18
- */
-@Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
-@Target(value = { java.lang.annotation.ElementType.TYPE })
-@Documented
-@Import({DtsAutoConfiguration.class, RabbitConfiguration.class})
-public @interface EnableDtsRabbit {
-
-}

+ 0 - 38
mybatis-plus-dts/src/main/java/com/baomidou/mybatisplus/dts/config/DtsAutoConfiguration.java

@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
- * <p>
- * Licensed 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
- * <p>
- * https://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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 com.baomidou.mybatisplus.dts.config;
-
-import com.baomidou.mybatisplus.dts.parser.JacksonDtsParser;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * Rabbit MQ 可靠消息配置
- *
- * @author jobob
- * @since 2019-04-19
- */
-@Configuration
-public class DtsAutoConfiguration {
-
-    @Bean
-    @ConditionalOnMissingClass
-    public JacksonDtsParser rmtParser() {
-        return new JacksonDtsParser();
-    }
-
-}

+ 0 - 99
mybatis-plus-dts/src/main/java/com/baomidou/mybatisplus/dts/config/RabbitConfiguration.java

@@ -1,99 +0,0 @@
-/*
- * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
- * <p>
- * Licensed 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
- * <p>
- * https://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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 com.baomidou.mybatisplus.dts.config;
-
-import com.baomidou.mybatisplus.dts.DtsConstants;
-import com.baomidou.mybatisplus.dts.listener.RabbitRmtListener;
-import com.baomidou.mybatisplus.dts.sender.RabbitRmtSender;
-import org.springframework.amqp.core.Binding;
-import org.springframework.amqp.core.DirectExchange;
-import org.springframework.amqp.core.Queue;
-import org.springframework.amqp.core.TopicExchange;
-import org.springframework.amqp.rabbit.annotation.EnableRabbit;
-import org.springframework.amqp.rabbit.connection.ConnectionFactory;
-import org.springframework.amqp.rabbit.core.RabbitAdmin;
-import org.springframework.amqp.rabbit.core.RabbitTemplate;
-import org.springframework.amqp.rabbit.transaction.RabbitTransactionManager;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-import javax.annotation.PostConstruct;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Rabbit MQ 可靠消息配置
- *
- * @author jobob
- * @since 2019-04-19
- */
-@Configuration
-@ConditionalOnClass(EnableRabbit.class)
-public class RabbitConfiguration {
-    @Autowired
-    protected RabbitTemplate rabbitTemplate;
-    @Autowired
-    protected RabbitAdmin rabbitAdmin;
-
-    @Bean
-    public RabbitRmtSender rmtSender() {
-        return new RabbitRmtSender();
-    }
-
-    @Bean
-    public RabbitRmtListener rabbitRmtListener() {
-        return new RabbitRmtListener();
-    }
-
-    @Bean
-    @ConditionalOnMissingBean
-    public RabbitTransactionManager rabbitTransactionManager(ConnectionFactory connectionFactory) {
-        return new RabbitTransactionManager(connectionFactory);
-    }
-
-    @Bean
-    @ConditionalOnMissingBean
-    public RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory) {
-        return new RabbitAdmin(connectionFactory);
-    }
-
-    @PostConstruct
-    protected void init() {
-        // make rmt template to support transactions
-        rabbitTemplate.setChannelTransacted(true);
-
-        // define deadletter exchange and queue
-        rabbitAdmin.declareExchange(new DirectExchange(DtsConstants.RABBIT_DEADLETTER_EXCHANGE, true, false));
-        rabbitAdmin.declareQueue(new Queue(DtsConstants.RABBIT_DEADLETTER_QUEUE, true, false, false, null));
-        rabbitAdmin.declareBinding(new Binding(DtsConstants.RABBIT_DEADLETTER_QUEUE, Binding.DestinationType.QUEUE,
-            DtsConstants.RABBIT_DEADLETTER_EXCHANGE, DtsConstants.RABBIT_DEADLETTER_ROUTINGKEY, null));
-
-        // define simple exchange, queue with deadletter support and binding
-        rabbitAdmin.declareExchange(new TopicExchange(DtsConstants.RABBIT_EXCHANGE, true, false));
-        Map<String, Object> args = new HashMap<>(2);
-        args.put("x-dead-letter-exchange", DtsConstants.RABBIT_DEADLETTER_EXCHANGE);
-        args.put("x-dead-letter-routing-key", DtsConstants.RABBIT_DEADLETTER_ROUTINGKEY);
-        rabbitAdmin.declareQueue(new Queue(DtsConstants.RABBIT_QUEUE, true, false, true, args));
-
-        // declare binding
-        rabbitAdmin.declareBinding(new Binding(DtsConstants.RABBIT_QUEUE, Binding.DestinationType.QUEUE, DtsConstants.RABBIT_EXCHANGE,
-            DtsConstants.RABBIT_ROUTINGKEY, null));
-    }
-}

+ 0 - 34
mybatis-plus-dts/src/main/java/com/baomidou/mybatisplus/dts/listener/IDtsListener.java

@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
- * <p>
- * Licensed 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
- * <p>
- * https://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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 com.baomidou.mybatisplus.dts.listener;
-
-import com.baomidou.mybatisplus.dts.DtsMeta;
-
-/**
- * 分布式事务监听
- *
- * @author jobob
- * @since 2019-04-18
- */
-public interface IDtsListener {
-
-    /**
-     * 监听处理
-     *
-     * @param dtsMeta 分布式元数据对象
-     */
-    void process(DtsMeta dtsMeta);
-}

+ 0 - 59
mybatis-plus-dts/src/main/java/com/baomidou/mybatisplus/dts/listener/RabbitRmtListener.java

@@ -1,59 +0,0 @@
-/*
- * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
- * <p>
- * Licensed 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
- * <p>
- * https://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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 com.baomidou.mybatisplus.dts.listener;
-
-import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
-import com.baomidou.mybatisplus.dts.DtsConstants;
-import com.baomidou.mybatisplus.dts.DtsMeta;
-import com.baomidou.mybatisplus.dts.parser.IDtsParser;
-import org.springframework.amqp.rabbit.annotation.RabbitHandler;
-import org.springframework.amqp.rabbit.annotation.RabbitListener;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.util.List;
-
-/**
- * Rabbit 可靠消息事务监听
- *
- * @author jobob
- * @since 2019-04-18
- */
-@Component
-@RabbitListener(queues = {DtsConstants.RABBIT_QUEUE})
-public class RabbitRmtListener {
-    @Autowired
-    private IDtsParser dtsParser;
-    @Autowired
-    private List<IDtsListener> dtsListenerList;
-
-    /**
-     * 解析处理,接收消息对象
-     *
-     * @param event rabbit 消息
-     */
-    @RabbitHandler
-    @Transactional(rollbackFor = Exception.class)
-    public void receive(String event) {
-        try {
-            DtsMeta dtsMeta = dtsParser.readValue(event, DtsMeta.class);
-            dtsListenerList.forEach(d -> d.process(dtsMeta));
-        } catch (Exception e) {
-            ExceptionUtils.mpe("rmt parser error, event: %s", e, event);
-        }
-    }
-}

+ 0 - 45
mybatis-plus-dts/src/main/java/com/baomidou/mybatisplus/dts/parser/IDtsParser.java

@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
- * <p>
- * Licensed 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
- * <p>
- * https://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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 com.baomidou.mybatisplus.dts.parser;
-
-/**
- * 可靠消息事务解析器
- *
- * @author jobob
- * @since 2019-04-18
- */
-public interface IDtsParser {
-
-    /**
-     * JSON 字符串转为对象
-     *
-     * @param jsonStr   JSON 字符串
-     * @param valueType 转换对象类
-     * @param <T>
-     * @return
-     * @throws Exception
-     */
-    <T> T readValue(String jsonStr, Class<T> valueType) throws Exception;
-
-    /**
-     * 对象转换为 JSON 字符串
-     *
-     * @param object 转换对象
-     * @return
-     * @throws Exception
-     */
-    String toJSONString(Object object) throws Exception;
-}

+ 0 - 53
mybatis-plus-dts/src/main/java/com/baomidou/mybatisplus/dts/parser/JacksonDtsParser.java

@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
- * <p>
- * Licensed 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
- * <p>
- * https://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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 com.baomidou.mybatisplus.dts.parser;
-
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.springframework.stereotype.Component;
-
-/**
- * Jackson 可靠消息解析器
- *
- * @author jobob
- * @since 2019-04-18
- */
-@Component
-public class JacksonDtsParser implements IDtsParser {
-
-    private static ObjectMapper objectMapper;
-
-    public static ObjectMapper getObjectMapper() {
-        if (objectMapper == null) {
-            objectMapper = new ObjectMapper();
-            objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-        }
-        return objectMapper;
-    }
-
-    @Override
-    public <T> T readValue(String jsonStr, Class<T> valueType) throws Exception {
-        if (null == jsonStr || "".equals(jsonStr)) {
-            return null;
-        }
-        return getObjectMapper().readValue(jsonStr, valueType);
-    }
-
-    @Override
-    public String toJSONString(Object object) throws Exception {
-        return getObjectMapper().writeValueAsString(object);
-    }
-}

+ 0 - 39
mybatis-plus-dts/src/main/java/com/baomidou/mybatisplus/dts/sender/IRmtSender.java

@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
- * <p>
- * Licensed 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
- * <p>
- * https://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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 com.baomidou.mybatisplus.dts.sender;
-
-import com.baomidou.mybatisplus.dts.DtsMeta;
-
-/**
- * <p>
- * 可靠消息发送者
- * </p>
- *
- * @author jobob
- * @since 2019-04-17
- */
-public interface IRmtSender {
-
-    /**
-     * <p>
-     * 发送消息
-     * </p>
-     *
-     * @param dtsMeta 分布式事务元数据
-     * @return
-     */
-    void send(DtsMeta dtsMeta);
-}

+ 0 - 63
mybatis-plus-dts/src/main/java/com/baomidou/mybatisplus/dts/sender/RabbitRmtSender.java

@@ -1,63 +0,0 @@
-/*
- * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
- * <p>
- * Licensed 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
- * <p>
- * https://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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 com.baomidou.mybatisplus.dts.sender;
-
-import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
-import com.baomidou.mybatisplus.dts.DtsConstants;
-import com.baomidou.mybatisplus.dts.DtsMeta;
-import com.baomidou.mybatisplus.dts.parser.IDtsParser;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.amqp.AmqpException;
-import org.springframework.amqp.rabbit.core.RabbitTemplate;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-/**
- * <p>
- * RabbitMQ 消息发送者
- * </p>
- *
- * @author hubin
- * @since 2019-04-17
- */
-@Slf4j
-@Component
-public class RabbitRmtSender implements IRmtSender {
-    @Autowired
-    private IDtsParser rmtParser;
-    @Autowired
-    private RabbitTemplate rabbitTemplate;
-
-    /**
-     * 发送MQ消息
-     *
-     * @param dtsMeta Rabbit元信息对象,用于存储交换器、队列名、消息体
-     */
-    @Override
-    public void send(DtsMeta dtsMeta) {
-        String object = null;
-        try {
-            object = rmtParser.toJSONString(dtsMeta);
-            rabbitTemplate.convertAndSend(DtsConstants.RABBIT_EXCHANGE,
-                DtsConstants.RABBIT_ROUTINGKEY, object);
-        } catch (AmqpException e) {
-            ExceptionUtils.mpe("rabbit send error, dtsMeta: %s", e, object);
-        } catch (Exception e) {
-            ExceptionUtils.mpe("rmt parser error, dtsMeta.event: %s", e, dtsMeta.getEvent());
-        }
-    }
-}

+ 0 - 1
settings.gradle

@@ -1,7 +1,6 @@
 rootProject.name = 'mybatis-plus-root'
 include 'mybatis-plus'
 include 'mybatis-plus-core'
-include 'mybatis-plus-dts'
 include 'mybatis-plus-annotation'
 include 'mybatis-plus-extension'
 include 'mybatis-plus-generator'