added standalone queue from tenant exchange for tenant creation handling
This commit is contained in:
parent
02486b9d4c
commit
861c69a2ac
@ -27,7 +27,7 @@ repositories {
|
||||
val springBootVersion = "3.1.5"
|
||||
|
||||
dependencies {
|
||||
api("com.knecon.fforesight:tenant-commons:maverick-mongo")
|
||||
api("com.knecon.fforesight:tenant-commons:maverick-mongo-eval")
|
||||
api("org.liquibase:liquibase-core:4.20.0")
|
||||
api("org.liquibase.ext:liquibase-mongodb:4.20.0")
|
||||
api("org.springframework.boot:spring-boot-starter-data-mongodb:${springBootVersion}")
|
||||
|
||||
@ -0,0 +1,59 @@
|
||||
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:tenant-created}")
|
||||
private String tenantCreatedEventQueue;
|
||||
|
||||
@Value("${fforesight.mongo.multitenancy.tenant-created-dlq:tenant-created-dlq}")
|
||||
private String tenantCreatedDLQ;
|
||||
|
||||
|
||||
@Bean(name = "mongoTenantExchange")
|
||||
TopicExchange mongoTenantExchange(@Value("${fforesight.tenant-exchange.name}") String tenantExchangeName) {
|
||||
|
||||
return new TopicExchange(tenantExchangeName);
|
||||
}
|
||||
|
||||
|
||||
@Bean("persistenceServiceMongoTenantCreatedQueue")
|
||||
public Queue persistenceServiceMongoTenantCreatedQueue() {
|
||||
|
||||
return QueueBuilder.durable(tenantCreatedEventQueue)
|
||||
.withArgument("x-dead-letter-exchange", "").withArgument("x-dead-letter-routing-key", tenantCreatedDLQ).build();
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public Queue persistenceServiceMongoTenantDLQ() {
|
||||
|
||||
return QueueBuilder.durable(tenantCreatedDLQ).build();
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public Binding tenantExchangeBinding(@Qualifier("persistenceServiceMongoTenantCreatedQueue") Queue persistenceServiceTenantCreatedQueue,
|
||||
@Qualifier("mongoTenantExchange") TopicExchange tenantExchange) {
|
||||
|
||||
return BindingBuilder.bind(persistenceServiceTenantCreatedQueue).to(tenantExchange).with("tenant.created");
|
||||
}
|
||||
|
||||
}
|
||||
@ -18,7 +18,7 @@ public class MongoTenantCreatedListener {
|
||||
|
||||
private final TenantMongoLiquibaseExecutor tenantMongoLiquibaseExecutor;
|
||||
|
||||
@Value("${fforesight.multitenancy.tenant-created-queue:tenant-created}")
|
||||
@Value("${fforesight.multitenancy.mongo.tenant-created-queue:mongo-tenant-created}")
|
||||
private String tenantCreatedQueue;
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ public class MongoTenantCreatedListener {
|
||||
|
||||
|
||||
@SneakyThrows
|
||||
@RabbitListener(queues = "${fforesight.multitenancy.tenant-created-queue:tenant-created}")
|
||||
@RabbitListener(queues = "${fforesight.multitenancy.mongo.tenant-created-queue:mongo-tenant-created}")
|
||||
public void createTenant(MongoTenantCreatedEvent tenantRequest) {
|
||||
|
||||
tenantMongoLiquibaseExecutor.initializeTenant(tenantRequest.getTenantId());
|
||||
|
||||
@ -64,10 +64,11 @@ public class TenantMongoLiquibaseExecutor implements InitializingBean, ResourceL
|
||||
var mongoUrl = MongoUtils.buildMongoUrl(mongoDBConnection);
|
||||
log.info("Initializing MongoDB liquibase for tenant {} / {}", tenant.getTenantId(), mongoUrl);
|
||||
|
||||
try (MongoLiquibaseDatabase database = (MongoLiquibaseDatabase) DatabaseFactory.getInstance()
|
||||
.openDatabase(mongoUrl, mongoDBConnection.getUsername(), encryptionService.decrypt(mongoDBConnection.getPassword()), null, null)) {
|
||||
try (SpringResourceAccessor resourceAccessor = new SpringResourceAccessor(resourceLoader)) {
|
||||
|
||||
try (SpringResourceAccessor resourceAccessor = new SpringResourceAccessor(resourceLoader)) {
|
||||
try (MongoLiquibaseDatabase database = (MongoLiquibaseDatabase) DatabaseFactory.getInstance()
|
||||
.openDatabase(mongoUrl, mongoDBConnection.getUsername(), encryptionService.decrypt(mongoDBConnection.getPassword()), null, resourceAccessor)) {
|
||||
database.setSupportsValidator(false);
|
||||
try (Liquibase liquibase = new Liquibase(tenantMongoLiquibaseProperties.getChangeLog(), resourceAccessor, database)) {
|
||||
Contexts contexts = new Contexts(tenantMongoLiquibaseProperties.getContexts());
|
||||
List<ChangeSet> changeSetsList = liquibase.listUnrunChangeSets(contexts, null);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user