Jackson sync
This commit is contained in:
parent
0dc00c8f6a
commit
68764d06b9
5
pom.xml
5
pom.xml
@ -21,6 +21,11 @@
|
||||
<guava.version>32.1.2-jre</guava.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson-bom.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.knecon.fforesight</groupId>
|
||||
<artifactId>tenant-commons</artifactId>
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package com.knecon.fforesight.databasetenantcommons;
|
||||
|
||||
|
||||
import org.springframework.amqp.core.Binding;
|
||||
import org.springframework.amqp.core.BindingBuilder;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
@ -23,13 +22,28 @@ public class TenantMessagingConfiguration {
|
||||
@Value("${fforesight.multitenancy.tenant-created-dlq:tenant-created-dlq}")
|
||||
private String tenantCreatedDLQ;
|
||||
|
||||
@Value("${fforesight.multitenancy.tenant-sync-queue:tenant-sync}")
|
||||
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() {
|
||||
|
||||
@ -40,13 +54,31 @@ public class TenantMessagingConfiguration {
|
||||
@Bean
|
||||
public Binding tenantExchangeBinding(@Qualifier("persistenceServiceTenantCreatedQueue") Queue persistenceServiceTenantCreatedQueue,
|
||||
@Qualifier("tenantExchange") TopicExchange tenantExchange) {
|
||||
|
||||
return BindingBuilder.bind(persistenceServiceTenantCreatedQueue).to(tenantExchange).with("tenant.created");
|
||||
}
|
||||
|
||||
@Bean(name = "tenantExchange")
|
||||
TopicExchange tenantExchange(@Value("${fforesight.tenant-exchange.name}") String tenantExchangeName) {
|
||||
|
||||
return new TopicExchange(tenantExchangeName);
|
||||
@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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,45 @@
|
||||
package com.knecon.fforesight.databasetenantcommons.providers;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.knecon.fforesight.databasetenantcommons.providers.TenantLiquibaseInitializer;
|
||||
import com.knecon.fforesight.databasetenantcommons.providers.events.TenantCreatedEvent;
|
||||
import com.knecon.fforesight.databasetenantcommons.providers.events.TenantSyncEvent;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class TenantSyncListener {
|
||||
|
||||
private final Optional<TenantSyncService> tenantSyncServices;
|
||||
|
||||
@Value("${fforesight.multitenancy.tenant-sync-queue:tenant-sync}")
|
||||
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}")
|
||||
public void createTenant(TenantSyncEvent tenantSyncEvent) {
|
||||
|
||||
tenantSyncServices.ifPresent(t -> t.syncTenant(tenantSyncEvent));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package com.knecon.fforesight.databasetenantcommons.providers;
|
||||
|
||||
import com.knecon.fforesight.databasetenantcommons.providers.events.TenantSyncEvent;
|
||||
|
||||
public interface TenantSyncService {
|
||||
|
||||
void syncTenant(TenantSyncEvent tenantSyncEvent);
|
||||
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package com.knecon.fforesight.databasetenantcommons.providers.events;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class TenantSyncEvent {
|
||||
|
||||
private String tenantId;
|
||||
private JsonNode payload;
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user