Skip to content

Commit

Permalink
Merge branch '2.x' into dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
#	magic-api-spring-boot-starter/pom.xml
#	magic-api/pom.xml
#	magic-api/src/main/java/org/ssssssss/magicapi/controller/MagicGroupController.java
#	magic-api/src/main/java/org/ssssssss/magicapi/model/JsonCodeConstants.java
#	magic-api/src/main/java/org/ssssssss/magicapi/provider/impl/MagicDatabaseBackupService.java
#	magic-editor/pom.xml
#	magic-editor/src/console/package.json
#	magic-editor/src/console/src/scripts/parsing/ast.js
#	magic-editor/src/console/src/scripts/parsing/parser.js
#	pom.xml
  • Loading branch information
javamxd committed Feb 27, 2022
2 parents 6249077 + f61d975 commit 92864e9
Show file tree
Hide file tree
Showing 395 changed files with 8,240 additions and 30,831 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ magic-api 是一个基于Java的接口快速开发框架,编写接口将通过
<dependency>
<groupId>org.ssssssss</groupId>
<artifactId>magic-api-spring-boot-starter</artifactId>
<version>1.7.5</version>
<version>2.0.0-beta.1</version>
</dependency>
```
## 修改application.properties
Expand Down
8 changes: 4 additions & 4 deletions db/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
> 0.7.x版本之后仅需要一张表两个字段,建表语句如下:
```sql
CREATE TABLE `magic_api_file` (
CREATE TABLE `magic_api_file_v2` (
`file_path` varchar(512) NOT NULL,
`file_content` mediumtext,
PRIMARY KEY (`file_path`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
```
### 备份表建表语句
```sql
CREATE TABLE `magic_api_backup` (
CREATE TABLE `magic_backup_record_v2` (
`id` varchar(32) NOT NULL COMMENT '原对象ID',
`create_date` bigint(13) NOT NULL COMMENT '备份时间',
`tag` varchar(32) DEFAULT NULL COMMENT '标签',
`type` varchar(32) DEFAULT NULL COMMENT '类型',
`name` varchar(64) DEFAULT NULL COMMENT '原名称',
`content` mediumtext COMMENT '备份内容',
`content` blob COMMENT '备份内容',
`create_by` varchar(64) DEFAULT NULL COMMENT '操作人',
PRIMARY KEY (`id`,`create_date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
```
```
22 changes: 0 additions & 22 deletions db/v0.2.x-v0.3.sql

This file was deleted.

29 changes: 0 additions & 29 deletions db/v0.4.x-v0.5-mysql.sql

This file was deleted.

34 changes: 0 additions & 34 deletions db/v0.5.x-v0.6-mysql.sql

This file was deleted.

49 changes: 0 additions & 49 deletions db/v0.6.x-v0.7.x升级脚本.ms

This file was deleted.

27 changes: 27 additions & 0 deletions magic-api-plugins/magic-api-plugin-cluster/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.ssssssss</groupId>
<artifactId>magic-api-plugins</artifactId>
<version>2.0.0-beta.1</version>
</parent>
<artifactId>magic-api-plugin-cluster</artifactId>
<packaging>jar</packaging>
<name>magic-api-plugin-cluster</name>
<description>magic-api-plugin-cluster</description>
<dependencies>
<dependency>
<groupId>org.ssssssss</groupId>
<artifactId>magic-api-plugin-redis</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.ssssssss.magicapi.cluster;

import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.UUID;

/**
* 集群配置
*
* @author mxd
* @since 1.2.0
*/
@ConfigurationProperties(prefix = "magic-api.cluster")
public class ClusterConfig {

/**
* redis 通道
*/
private String channel = "magic-api:notify:channel";

public String getChannel() {
return channel;
}

public void setChannel(String channel) {
this.channel = channel;
}
}
Original file line number Diff line number Diff line change
@@ -1,85 +1,75 @@
package org.ssssssss.magicapi.spring.boot.starter;
package org.ssssssss.magicapi.cluster;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.ssssssss.magicapi.adapter.Resource;
import org.ssssssss.magicapi.adapter.resource.RedisResource;
import org.ssssssss.magicapi.model.MagicNotify;
import org.ssssssss.magicapi.modules.RedisModule;
import org.ssssssss.magicapi.provider.MagicAPIService;
import org.ssssssss.magicapi.provider.MagicNotifyService;
import org.ssssssss.magicapi.core.config.MagicAPIProperties;
import org.ssssssss.magicapi.core.config.MagicPluginConfiguration;
import org.ssssssss.magicapi.core.model.MagicNotify;
import org.ssssssss.magicapi.core.model.Plugin;
import org.ssssssss.magicapi.core.service.MagicAPIService;
import org.ssssssss.magicapi.core.service.MagicNotifyService;
import org.ssssssss.magicapi.utils.JsonUtils;

import java.util.Objects;

/**
* redis配置
*
* @author mxd
*/
@ConditionalOnClass(RedisConnectionFactory.class)

@EnableConfigurationProperties(ClusterConfig.class)
@Configuration
@AutoConfigureBefore(MagicAPIAutoConfiguration.class)
public class MagicRedisAutoConfiguration {
public class MagicClusterConfiguration implements MagicPluginConfiguration {

private final static Logger logger = LoggerFactory.getLogger(MagicRedisAutoConfiguration.class);
private final ClusterConfig config;

private final MagicAPIProperties properties;

private final StringRedisTemplate stringRedisTemplate;

public MagicRedisAutoConfiguration(MagicAPIProperties properties, ObjectProvider<StringRedisTemplate> stringRedisTemplateProvider) {
private final Logger logger = LoggerFactory.getLogger(MagicClusterConfiguration.class);

public MagicClusterConfiguration(MagicAPIProperties properties, ClusterConfig config, ObjectProvider<StringRedisTemplate> stringRedisTemplateProvider) {
this.properties = properties;
this.config = config;
this.stringRedisTemplate = stringRedisTemplateProvider.getIfAvailable();
}

/**
* 注入redis模块
*/
@Bean
public RedisModule redisFunctions(RedisConnectionFactory connectionFactory) {
return new RedisModule(connectionFactory);
@Override
public Plugin plugin() {
return new Plugin("Cluster");
}

/**
* 使用Redis存储
* 使用Redis推送通知
*/
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "magic-api", name = "resource.type", havingValue = "redis")
public Resource magicRedisResource(RedisConnectionFactory connectionFactory) {
ResourceConfig resource = properties.getResource();
return new RedisResource(new StringRedisTemplate(connectionFactory), resource.getPrefix(), resource.isReadonly());
public MagicNotifyService magicNotifyService() {
return magicNotify -> stringRedisTemplate.convertAndSend(config.getChannel(), Objects.requireNonNull(JsonUtils.toJsonString(magicNotify)));
}

/**
* 使用Redis推送通知
* 消息处理服务
*/
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "magic-api", name = "cluster-config.enable", havingValue = "true")
public MagicNotifyService magicNotifyService() {
return magicNotify -> stringRedisTemplate.convertAndSend(properties.getClusterConfig().getChannel(), Objects.requireNonNull(JsonUtils.toJsonString(magicNotify)));
public MagicSynchronizationService magicSynchronizationService(MagicNotifyService magicNotifyService) {
return new MagicSynchronizationService(magicNotifyService, properties.getInstanceId());
}

/**
* 集群通知监听
*/
@Bean
@ConditionalOnProperty(prefix = "magic-api", name = "cluster-config.enable", havingValue = "true")
public RedisMessageListenerContainer magicRedisMessageListenerContainer(RedisConnectionFactory redisConnectionFactory, MagicAPIService magicAPIService) {
ClusterConfig config = properties.getClusterConfig();
logger.info("开启集群通知监听, Redis channel: {}", config.getChannel());
RedisMessageListenerContainer redisMessageListenerContainer = new RedisMessageListenerContainer();
redisMessageListenerContainer.setConnectionFactory(redisConnectionFactory);
Expand Down
Loading

0 comments on commit 92864e9

Please sign in to comment.