Merge branch 'removed-legacy-code-tenant-messaging' into 'main'

Removed legacy tenant exchange config

See merge request fforesight/database-tenant-commons!30
This commit is contained in:
Timo Bejan 2024-09-23 22:51:52 +02:00
commit abcf905548
5 changed files with 44 additions and 97 deletions

1
.gitignore vendored
View File

@ -32,6 +32,7 @@ build/
### VS Code ###
.vscode/
.DS_Store/
.DS_Store
gradle.properties
gradlew

View File

@ -29,7 +29,7 @@ val springCloudVersion = "4.0.4"
dependencies {
api("com.fasterxml.jackson.core:jackson-databind:2.15.2:")
api("com.knecon.fforesight:tenant-commons:0.26.0")
api("com.knecon.fforesight:tenant-commons:0.30.0")
api("com.zaxxer:HikariCP:5.0.1")
api("com.google.guava:guava:32.1.2-jre")
api("org.liquibase:liquibase-core:4.20.0")
@ -113,4 +113,4 @@ tasks.jacocoTestReport {
java {
withJavadocJar()
}
}

View File

@ -1,84 +0,0 @@
package com.knecon.fforesight.databasetenantcommons;
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.Configuration;
import lombok.RequiredArgsConstructor;
@Configuration
@RequiredArgsConstructor
public class TenantMessagingConfiguration {
@Value("${fforesight.multitenancy.tenant-created-queue:tenant-created-queue}")
private String tenantCreatedEventQueue;
@Value("${fforesight.multitenancy.tenant-created-dlq:tenant-created-dlq}")
private String tenantCreatedDLQ;
@Value("${fforesight.multitenancy.tenant-sync-queue:tenant-sync-queue}")
private String tenantSyncEventQueue;
@Value("${fforesight.multitenancy.tenant-sync-dlq:tenant-sync-dlq}")
private String tenantSyncDQL;
@Bean(name = "tenantExchange")
TopicExchange tenantExchange(@Value("${fforesight.tenant-exchange.name}") String tenantExchangeName) {
return new TopicExchange(tenantExchangeName);
}
@Bean("persistenceServiceTenantCreatedQueue")
public Queue persistenceServiceTenantCreatedQueue() {
return QueueBuilder.durable(tenantCreatedEventQueue)
.withArgument("x-dead-letter-exchange", "").withArgument("x-dead-letter-routing-key", tenantCreatedDLQ).build();
}
@Bean
public Queue persistenceServiceTenantDLQ() {
return QueueBuilder.durable(tenantCreatedDLQ).build();
}
@Bean
public Binding tenantExchangeBinding(@Qualifier("persistenceServiceTenantCreatedQueue") Queue persistenceServiceTenantCreatedQueue,
@Qualifier("tenantExchange") TopicExchange tenantExchange) {
return BindingBuilder.bind(persistenceServiceTenantCreatedQueue).to(tenantExchange).with("tenant.created");
}
@Bean("persistenceServiceTenantSyncQueue")
public Queue persistenceServiceTenantSyncQueue() {
return QueueBuilder.durable(tenantSyncEventQueue)
.withArgument("x-dead-letter-exchange", "").withArgument("x-dead-letter-routing-key", tenantSyncDQL).build();
}
@Bean
public Queue persistenceServiceTenantSyncDLQ() {
return QueueBuilder.durable(tenantSyncDQL).build();
}
@Bean
public Binding tenantExchangeSyncBinding(@Qualifier("persistenceServiceTenantSyncQueue") Queue persistenceServiceTenantSyncQueue,
@Qualifier("tenantExchange") TopicExchange tenantExchange) {
return BindingBuilder.bind(persistenceServiceTenantSyncQueue).to(tenantExchange).with("tenant.sync");
}
}

View File

@ -0,0 +1,40 @@
package com.knecon.fforesight.databasetenantcommons;
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.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.knecon.fforesight.tenantcommons.queue.TenantMessagingConfiguration;
@Configuration
public class TenantMessagingConfigurationImpl extends TenantMessagingConfiguration {
public String getTenantSyncQueue() {
return this.getQueueNameWithSuffix("_tenant_sync");
}
@Bean({"tenantSyncQueue"})
public Queue tenantSyncQueue() {
return QueueBuilder.durable(this.getTenantCreatedQueueName())
.withArgument("x-dead-letter-exchange", "")
.withArgument("x-dead-letter-routing-key", this.getTenantEventsDLQName())
.withArgument("x-expires", 300000)
.build();
}
@Bean
public Binding tenantSyncBinding(@Qualifier("tenantSyncQueue") Queue tenantCreatedQueue, @Qualifier("tenantExchange") TopicExchange tenantExchange) {
return BindingBuilder.bind(tenantCreatedQueue).to(tenantExchange).with("tenant.sync");
}
}

View File

@ -20,19 +20,9 @@ public class TenantSyncListener {
private final Optional<TenantSyncService> tenantSyncServices;
@Value("${fforesight.multitenancy.tenant-sync-queue:tenant-sync-queue}")
private String tenantSyncQueue;
@PostConstruct
public void postConstruct() {
log.info("Listener for tenant-sync started for queue: {}", tenantSyncQueue);
}
@SneakyThrows
@RabbitListener(queues = "${fforesight.multitenancy.tenant-sync-queue:tenant-sync-queue}")
@RabbitListener(queues = "#{tenantMessagingConfigurationImpl.getTenantSyncQueue()}")
public void createTenant(TenantSyncEvent tenantSyncEvent) {
tenantSyncServices.ifPresent(t -> t.syncTenant(tenantSyncEvent));