Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88b64e7116 | ||
|
|
8e9c80dbd8 | ||
|
|
92e4b67ea2 | ||
|
|
39c32ffa12 | ||
|
|
d52a3f4648 | ||
|
|
df42a6bd91 | ||
|
|
d5aece1287 | ||
|
|
5cddef012d | ||
|
|
0f1d9d11f2 | ||
|
|
27925d6b3c |
1
.gitignore
vendored
1
.gitignore
vendored
@ -40,3 +40,4 @@ gradle/
|
|||||||
|
|
||||||
**/.gradle
|
**/.gradle
|
||||||
**/build
|
**/build
|
||||||
|
.DS_Store
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
`java-library`
|
`java-library`
|
||||||
`maven-publish`
|
`maven-publish`
|
||||||
`kotlin-dsl`
|
|
||||||
pmd
|
pmd
|
||||||
checkstyle
|
checkstyle
|
||||||
jacoco
|
jacoco
|
||||||
@ -25,10 +24,11 @@ repositories {
|
|||||||
val springBootVersion = "3.1.5"
|
val springBootVersion = "3.1.5"
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
api("com.knecon.fforesight:tenant-commons:0.29.0")
|
api("com.knecon.fforesight:tenant-commons:0.31.0")
|
||||||
api("org.liquibase:liquibase-core:4.20.0")
|
api("org.liquibase:liquibase-core:4.29.2")
|
||||||
api("org.liquibase.ext:liquibase-mongodb:4.20.0")
|
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-data-mongodb:${springBootVersion}")
|
||||||
|
api("org.springframework.boot:spring-boot-starter-validation:${springBootVersion}")
|
||||||
api("org.springframework.boot:spring-boot-configuration-processor:${springBootVersion}")
|
api("org.springframework.boot:spring-boot-configuration-processor:${springBootVersion}")
|
||||||
api("org.projectlombok:lombok:1.18.28")
|
api("org.projectlombok:lombok:1.18.28")
|
||||||
runtimeOnly("org.springframework.boot:spring-boot-devtools:${springBootVersion}")
|
runtimeOnly("org.springframework.boot:spring-boot-devtools:${springBootVersion}")
|
||||||
@ -83,7 +83,7 @@ tasks.named<Test>("test") {
|
|||||||
|
|
||||||
sonarqube {
|
sonarqube {
|
||||||
properties {
|
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")
|
property("sonar.host.url", "https://sonarqube.knecon.com")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -103,4 +103,4 @@ tasks.jacocoTestReport {
|
|||||||
|
|
||||||
java {
|
java {
|
||||||
withJavadocJar()
|
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-error}")
|
|
||||||
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;
|
package com.knecon.fforesight.mongo.database.commons.config;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
|
import org.bson.codecs.configuration.CodecRegistry;
|
||||||
import org.bson.conversions.Bson;
|
import org.bson.conversions.Bson;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory;
|
import org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory;
|
||||||
|
|
||||||
import com.knecon.fforesight.mongo.database.commons.service.MongoDataSources;
|
import com.knecon.fforesight.mongo.database.commons.service.MongoDataSources;
|
||||||
import com.mongodb.ClientSessionOptions;
|
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.ChangeStreamIterable;
|
||||||
import com.mongodb.client.ClientSession;
|
import com.mongodb.client.ClientSession;
|
||||||
import com.mongodb.client.ListDatabasesIterable;
|
import com.mongodb.client.ListDatabasesIterable;
|
||||||
@ -40,6 +45,7 @@ public class MultiTenantMongoDBFactory extends SimpleMongoClientDatabaseFactory
|
|||||||
|
|
||||||
private static MongoClient getBootstrapMongoClient() {
|
private static MongoClient getBootstrapMongoClient() {
|
||||||
return new MongoClient() {
|
return new MongoClient() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MongoDatabase getDatabase(String s) {
|
public MongoDatabase getDatabase(String s) {
|
||||||
|
|
||||||
|
|||||||
@ -2,11 +2,12 @@ package com.knecon.fforesight.mongo.database.commons.liquibase;
|
|||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.springframework.context.annotation.Condition;
|
import org.springframework.context.annotation.Condition;
|
||||||
import org.springframework.context.annotation.ConditionContext;
|
import org.springframework.context.annotation.ConditionContext;
|
||||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
public class EnableMongoLiquibaseCondition implements Condition {
|
public class EnableMongoLiquibaseCondition implements Condition {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -23,7 +23,7 @@ public class MongoLiquibaseConfig {
|
|||||||
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public TenantMongoLiquibaseExecutor tenantLiquibase(EncryptionDecryptionService encryptionService,
|
public TenantMongoLiquibaseExecutor tenantMongoLiquibaseExecutor(EncryptionDecryptionService encryptionService,
|
||||||
TenantProvider tenantProvider,
|
TenantProvider tenantProvider,
|
||||||
@Qualifier("tenantMongoLiquibaseProperties") LiquibaseProperties mongoLiquibaseProperties) {
|
@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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -2,7 +2,6 @@ package com.knecon.fforesight.mongo.database.commons.service;
|
|||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -16,6 +15,7 @@ import com.mongodb.client.MongoClient;
|
|||||||
import com.mongodb.client.MongoClients;
|
import com.mongodb.client.MongoClients;
|
||||||
|
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
|
|
||||||
@ -70,4 +70,4 @@ public class MongoClientCache {
|
|||||||
return clients.get(tenantId);
|
return clients.get(tenantId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user