Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88b64e7116 | ||
|
|
8e9c80dbd8 | ||
|
|
92e4b67ea2 | ||
|
|
39c32ffa12 | ||
|
|
d52a3f4648 | ||
|
|
df42a6bd91 | ||
|
|
d5aece1287 | ||
|
|
5cddef012d | ||
|
|
0f1d9d11f2 | ||
|
|
27925d6b3c | ||
|
|
987e720dad | ||
|
|
0f351a0e13 | ||
|
|
0b57648740 | ||
|
|
a68912407c |
1
.gitignore
vendored
1
.gitignore
vendored
@ -40,3 +40,4 @@ gradle/
|
||||
|
||||
**/.gradle
|
||||
**/build
|
||||
.DS_Store
|
||||
|
||||
@ -18,4 +18,5 @@ deploy:
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
||||
- if: $CI_COMMIT_BRANCH =~ /^release/
|
||||
- if: $CI_COMMIT_BRANCH =~ /^feature/
|
||||
- if: $CI_COMMIT_TAG
|
||||
@ -1,7 +1,6 @@
|
||||
plugins {
|
||||
`java-library`
|
||||
`maven-publish`
|
||||
`kotlin-dsl`
|
||||
pmd
|
||||
checkstyle
|
||||
jacoco
|
||||
@ -25,10 +24,11 @@ repositories {
|
||||
val springBootVersion = "3.1.5"
|
||||
|
||||
dependencies {
|
||||
api("com.knecon.fforesight:tenant-commons:0.26.0")
|
||||
api("org.liquibase:liquibase-core:4.20.0")
|
||||
api("org.liquibase.ext:liquibase-mongodb:4.20.0")
|
||||
api("com.knecon.fforesight:tenant-commons:0.31.0")
|
||||
api("org.liquibase:liquibase-core:4.29.2")
|
||||
api("org.liquibase.ext:liquibase-mongodb:4.29.2")
|
||||
api("org.springframework.boot:spring-boot-starter-data-mongodb:${springBootVersion}")
|
||||
api("org.springframework.boot:spring-boot-starter-validation:${springBootVersion}")
|
||||
api("org.springframework.boot:spring-boot-configuration-processor:${springBootVersion}")
|
||||
api("org.projectlombok:lombok:1.18.28")
|
||||
runtimeOnly("org.springframework.boot:spring-boot-devtools:${springBootVersion}")
|
||||
@ -83,7 +83,7 @@ tasks.named<Test>("test") {
|
||||
|
||||
sonarqube {
|
||||
properties {
|
||||
property("sonar.login", providers.gradleProperty("sonarToken").getOrNull())
|
||||
providers.gradleProperty("sonarToken").getOrNull()?.let { property("sonar.login", it) }
|
||||
property("sonar.host.url", "https://sonarqube.knecon.com")
|
||||
}
|
||||
}
|
||||
@ -103,4 +103,4 @@ tasks.jacocoTestReport {
|
||||
|
||||
java {
|
||||
withJavadocJar()
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,59 +0,0 @@
|
||||
package com.knecon.fforesight.mongo.database.commons;
|
||||
|
||||
import org.springframework.amqp.core.Binding;
|
||||
import org.springframework.amqp.core.BindingBuilder;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.core.QueueBuilder;
|
||||
import org.springframework.amqp.core.TopicExchange;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Conditional;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.knecon.fforesight.mongo.database.commons.liquibase.EnableMongoLiquibaseCondition;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
@Conditional(EnableMongoLiquibaseCondition.class)
|
||||
public class MongoTenantMessagingConfiguration {
|
||||
|
||||
@Value("${fforesight.mongo.multitenancy.tenant-created-queue:mongo-tenant-created}")
|
||||
private String mongoTenantCreatedEventQueue;
|
||||
|
||||
@Value("${fforesight.mongo.multitenancy.tenant-created-dlq:mongo-tenant-created-dlq}")
|
||||
private String mongoTenantCreatedDLQ;
|
||||
|
||||
|
||||
@Bean(name = "mongoTenantExchange")
|
||||
TopicExchange mongoTenantExchange(@Value("${fforesight.tenant-exchange.name:tenants-exchange}") String tenantExchangeName) {
|
||||
|
||||
return new TopicExchange(tenantExchangeName);
|
||||
}
|
||||
|
||||
|
||||
@Bean("persistenceServiceMongoTenantCreatedQueue")
|
||||
public Queue persistenceServiceMongoTenantCreatedQueue() {
|
||||
|
||||
return QueueBuilder.durable(mongoTenantCreatedEventQueue)
|
||||
.withArgument("x-dead-letter-exchange", "").withArgument("x-dead-letter-routing-key", mongoTenantCreatedDLQ).build();
|
||||
}
|
||||
|
||||
|
||||
@Bean("persistenceServiceMongoTenantDLQ")
|
||||
public Queue persistenceServiceMongoTenantDLQ() {
|
||||
|
||||
return QueueBuilder.durable(mongoTenantCreatedDLQ).build();
|
||||
}
|
||||
|
||||
|
||||
@Bean("mongoTenantExchangeBinding")
|
||||
public Binding mongoTenantExchangeBinding(@Qualifier("persistenceServiceMongoTenantCreatedQueue") Queue persistenceServiceTenantCreatedQueue,
|
||||
@Qualifier("mongoTenantExchange") TopicExchange tenantExchange) {
|
||||
|
||||
return BindingBuilder.bind(persistenceServiceTenantCreatedQueue).to(tenantExchange).with("tenant.created");
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,15 +1,20 @@
|
||||
package com.knecon.fforesight.mongo.database.commons.config;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.bson.Document;
|
||||
import org.bson.codecs.configuration.CodecRegistry;
|
||||
import org.bson.conversions.Bson;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory;
|
||||
|
||||
import com.knecon.fforesight.mongo.database.commons.service.MongoDataSources;
|
||||
import com.mongodb.ClientSessionOptions;
|
||||
import com.mongodb.ReadConcern;
|
||||
import com.mongodb.ReadPreference;
|
||||
import com.mongodb.WriteConcern;
|
||||
import com.mongodb.client.ChangeStreamIterable;
|
||||
import com.mongodb.client.ClientSession;
|
||||
import com.mongodb.client.ListDatabasesIterable;
|
||||
@ -40,6 +45,7 @@ public class MultiTenantMongoDBFactory extends SimpleMongoClientDatabaseFactory
|
||||
|
||||
private static MongoClient getBootstrapMongoClient() {
|
||||
return new MongoClient() {
|
||||
|
||||
@Override
|
||||
public MongoDatabase getDatabase(String s) {
|
||||
|
||||
|
||||
@ -2,11 +2,12 @@ package com.knecon.fforesight.mongo.database.commons.liquibase;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.context.annotation.Condition;
|
||||
import org.springframework.context.annotation.ConditionContext;
|
||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
public class EnableMongoLiquibaseCondition implements Condition {
|
||||
|
||||
@Override
|
||||
|
||||
@ -23,7 +23,7 @@ public class MongoLiquibaseConfig {
|
||||
|
||||
|
||||
@Bean
|
||||
public TenantMongoLiquibaseExecutor tenantLiquibase(EncryptionDecryptionService encryptionService,
|
||||
public TenantMongoLiquibaseExecutor tenantMongoLiquibaseExecutor(EncryptionDecryptionService encryptionService,
|
||||
TenantProvider tenantProvider,
|
||||
@Qualifier("tenantMongoLiquibaseProperties") LiquibaseProperties mongoLiquibaseProperties) {
|
||||
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
package com.knecon.fforesight.mongo.database.commons.liquibase;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class MongoTenantCreatedEvent {
|
||||
|
||||
private String tenantId;
|
||||
|
||||
}
|
||||
@ -1,39 +0,0 @@
|
||||
package com.knecon.fforesight.mongo.database.commons.liquibase;
|
||||
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Conditional;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Conditional(EnableMongoLiquibaseCondition.class)
|
||||
public class MongoTenantCreatedListener {
|
||||
|
||||
private final TenantMongoLiquibaseExecutor tenantMongoLiquibaseExecutor;
|
||||
|
||||
@Value("${fforesight.multitenancy.mongo.tenant-created-queue:mongo-tenant-created}")
|
||||
private String tenantCreatedQueue;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void postConstruct() {
|
||||
|
||||
log.info("Listener for tenant-created started for queue: {}", tenantCreatedQueue);
|
||||
}
|
||||
|
||||
|
||||
@SneakyThrows
|
||||
@RabbitListener(queues = "${fforesight.multitenancy.mongo.tenant-created-queue:mongo-tenant-created}")
|
||||
public void createTenant(MongoTenantCreatedEvent tenantRequest) {
|
||||
|
||||
tenantMongoLiquibaseExecutor.initializeTenant(tenantRequest.getTenantId());
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
package com.knecon.fforesight.mongo.database.commons.liquibase;
|
||||
|
||||
import org.springframework.context.annotation.Conditional;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.knecon.fforesight.tenantcommons.listener.ITenantEventHandler;
|
||||
import com.knecon.fforesight.tenantcommons.model.TenantCreatedEvent;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Conditional(EnableMongoLiquibaseCondition.class)
|
||||
public class TenantCreatedMongoEventHandler implements ITenantEventHandler<TenantCreatedEvent> {
|
||||
|
||||
private final TenantMongoLiquibaseExecutor tenantMongoLiquibaseExecutor;
|
||||
|
||||
|
||||
@Override
|
||||
public void handle(TenantCreatedEvent tenantCreatedEvent) {
|
||||
|
||||
tenantMongoLiquibaseExecutor.initializeTenant(tenantCreatedEvent.getTenantId());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Class<TenantCreatedEvent> getEventClass() {
|
||||
|
||||
return TenantCreatedEvent.class;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,6 +1,8 @@
|
||||
package com.knecon.fforesight.mongo.database.commons.liquibase;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties;
|
||||
@ -96,6 +98,12 @@ public class TenantMongoLiquibaseExecutor implements InitializingBean, ResourceL
|
||||
liquibase.setChangeLog(tenantMongoLiquibaseProperties.getChangeLog());
|
||||
liquibase.setContexts(tenantMongoLiquibaseProperties.getContexts());
|
||||
liquibase.setClearCheckSums(tenantMongoLiquibaseProperties.isClearChecksums());
|
||||
|
||||
String databaseName = database.getConnection().getCatalog(); // or getDatabaseName() depending on your implementation
|
||||
Map<String, String> changeLogParameters = new HashMap<>();
|
||||
changeLogParameters.put("databaseName", databaseName);
|
||||
liquibase.setChangeLogParameters(changeLogParameters);
|
||||
|
||||
liquibase.afterPropertiesSet();
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,6 @@ package com.knecon.fforesight.mongo.database.commons.service;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -16,6 +15,7 @@ import com.mongodb.client.MongoClient;
|
||||
import com.mongodb.client.MongoClients;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
@ -70,4 +70,4 @@ public class MongoClientCache {
|
||||
return clients.get(tenantId);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user