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

New dynamic database management and operation function #185

Merged
merged 5 commits into from
Jan 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ public class RocketAutoConfiguration {
private static final Logger logger = LoggerFactory.getLogger(RocketAutoConfiguration.class);

@Value("${rocketmq.producer.group}")
private String groupName;
private String producerGroupName;

@Value("${rocketmq.consumer.group}")
private String consumerGroupName;

@Value("${rocketmq.name-server}")
private String nameServer;
Expand Down Expand Up @@ -72,7 +75,7 @@ public RocketAdapter rocketAdapter(RocketMQTemplate rocketMQTemplate) {
@Bean
@ConditionalOnExpression("'${dew.cluster.mq}'=='rocket'")
public RocketClusterMQ rocketClusterMQ(RocketAdapter rocketAdapter) {
return new RocketClusterMQ(rocketAdapter, nameServer, groupName);
return new RocketClusterMQ(rocketAdapter, nameServer, producerGroupName, consumerGroupName);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,15 @@ public class RocketClusterMQ extends AbsClusterMQ {

private final String nameServer;

private final String groupName;
private final String producerGroupName;

public RocketClusterMQ(RocketAdapter rocketAdapter, String nameServer, String groupName) {
private final String consumerGroupName;

public RocketClusterMQ(RocketAdapter rocketAdapter, String nameServer, String producerGroupName, String consumerGroupName) {
this.rocketAdapter = rocketAdapter;
this.nameServer = nameServer;
this.groupName = groupName;
this.producerGroupName = producerGroupName;
this.consumerGroupName = consumerGroupName;
}

/**
Expand Down Expand Up @@ -141,7 +144,7 @@ protected boolean doPublish(String topic, String message, Optional<Map<String, O

@Override
protected void doSubscribe(String topic, Consumer<MessageWrap> consumer) {
DefaultMQPushConsumer mqConsumer = new DefaultMQPushConsumer(groupName);
DefaultMQPushConsumer mqConsumer = new DefaultMQPushConsumer(producerGroupName);
mqConsumer.setNamesrvAddr(nameServer);
mqConsumer.setInstanceName(UUID.randomUUID().toString());

Expand Down Expand Up @@ -181,7 +184,7 @@ protected boolean doRequest(String address, String message, Optional<Map<String,

@Override
protected void doResponse(String address, Consumer<MessageWrap> consumer) {
DefaultMQPushConsumer mqConsumer = new DefaultMQPushConsumer(groupName);
DefaultMQPushConsumer mqConsumer = new DefaultMQPushConsumer(consumerGroupName);
mqConsumer.setNamesrvAddr(nameServer);
mqConsumer.setInstanceName(UUID.randomUUID().toString());
try {
Expand Down
111 changes: 111 additions & 0 deletions framework/modules/dbutils-starter/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2021. the original author or authors.
~
~ 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
~
~ 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.
-->

<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>group.idealworld.dew</groupId>
<artifactId>parent-starter</artifactId>
<version>3.0.0-Beta3</version>
<relativePath>../parent-starter</relativePath>
</parent>

<artifactId>dbutils-starter</artifactId>
<name>1.1.4 Dew dbutils-</name>
<description>Dew 集群 动态数据源实现</description>
<packaging>jar</packaging>

<properties>
</properties>

<dependencies>
<dependency>
<groupId>group.idealworld.dew</groupId>
<artifactId>cluster-common</artifactId>
</dependency>
<dependency>
<groupId>group.idealworld.dew</groupId>
<artifactId>cluster-common-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>group.idealworld.dew</groupId>
<artifactId>test-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</dependency>
<dependency>
<groupId>commons-dbutils</groupId>
<artifactId>commons-dbutils</artifactId>
<version>${commons-dbutils.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>${snakeyaml.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package group.idealworld.dew.core.dbutils;


import group.idealworld.dew.core.dbutils.dto.DBUtilsConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(DBUtilsConfig.class)
public class DbutilsAutoConfiguration {

@Bean
public DewDB dewDB(DBUtilsConfig DBUtilsConfig) {
DewDBUtils.init(DBUtilsConfig);
DewDB dewDB = DewDBUtils.use("default");
return dewDB;
}

}
Loading