From 93ce7ecd6d94319a363f2449feb4d2ccf73c7c69 Mon Sep 17 00:00:00 2001 From: Thomas Georgios Giannos Date: Fri, 12 Jan 2024 13:55:50 +0200 Subject: [PATCH] Notification service config update --- .../outbox/OutboxRepositoryImpl.java | 58 +++++++++---------- .../src/main/resources/config/queue-devel.yml | 2 +- .../src/main/resources/config/queue.yml | 12 ++-- .../integrationevent/AppRabbitConfigurer.java | 3 + .../inbox/InboxProperties.java | 15 +++-- .../inbox/InboxRepositoryImpl.java | 14 ++--- 6 files changed, 54 insertions(+), 50 deletions(-) diff --git a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/OutboxRepositoryImpl.java b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/OutboxRepositoryImpl.java index a9e36748c..0b93590f7 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/OutboxRepositoryImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/OutboxRepositoryImpl.java @@ -50,7 +50,7 @@ public class OutboxRepositoryImpl implements OutboxRepository { EntityTransaction transaction = null; EntityManager entityManager = null; CandidateInfo candidate = null; - try (FakeRequestScope fakeRequestScope = new FakeRequestScope()) { + try (FakeRequestScope ignored = new FakeRequestScope()) { try { QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class); EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); @@ -86,18 +86,18 @@ public class OutboxRepositoryImpl implements OutboxRepository { transaction.commit(); } catch (OptimisticLockException ex) { // we get this if/when someone else already modified the notifications. We want to essentially ignore this, and keep working - this.logger.debug("Concurrency exception getting queue outbox. Skipping: {} ", ex.getMessage()); + logger.debug("Concurrency exception getting queue outbox. Skipping: {} ", ex.getMessage()); if (transaction != null) transaction.rollback(); candidate = null; } catch (Exception ex) { - this.logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex); + logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex); if (transaction != null) transaction.rollback(); candidate = null; } finally { if (entityManager != null) entityManager.close(); } } catch (Exception ex) { - this.logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex); + logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex); } return candidate; @@ -107,9 +107,9 @@ public class OutboxRepositoryImpl implements OutboxRepository { public Boolean shouldOmit(CandidateInfo candidate, Function shouldOmit) { EntityTransaction transaction = null; EntityManager entityManager = null; - Boolean success = false; + boolean success = false; - try (FakeRequestScope fakeRequestScope = new FakeRequestScope()) { + try (FakeRequestScope ignored = new FakeRequestScope()) { try { EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); @@ -122,7 +122,7 @@ public class OutboxRepositoryImpl implements OutboxRepository { QueueOutboxEntity item = queryFactory.query(QueueOutboxQuery.class).ids(candidate.getId()).first(); if (item == null) { - this.logger.warn("Could not lookup queue outbox {} to process. Continuing...", candidate.getId()); + logger.warn("Could not lookup queue outbox {} to process. Continuing...", candidate.getId()); } else { if (shouldOmit.apply(item)) { item.setNotifyStatus(QueueOutboxNotifyStatus.OMITTED); @@ -135,14 +135,14 @@ public class OutboxRepositoryImpl implements OutboxRepository { transaction.commit(); } catch (Exception ex) { - this.logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex); + logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex); if (transaction != null) transaction.rollback(); success = false; } finally { if (entityManager != null) entityManager.close(); } } catch (Exception ex) { - this.logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex); + logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex); } return success; } @@ -151,9 +151,9 @@ public class OutboxRepositoryImpl implements OutboxRepository { public Boolean shouldWait(CandidateInfo candidate, Function itIsTimeFunc) { EntityTransaction transaction = null; EntityManager entityManager = null; - Boolean success = false; + boolean success = false; - try (FakeRequestScope fakeRequestScope = new FakeRequestScope()) { + try (FakeRequestScope ignored = new FakeRequestScope()) { try { EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); @@ -180,14 +180,14 @@ public class OutboxRepositoryImpl implements OutboxRepository { } transaction.commit(); } catch (Exception ex) { - this.logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex); + logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex); if (transaction != null) transaction.rollback(); success = false; } finally { if (entityManager != null) entityManager.close(); } } catch (Exception ex) { - this.logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex); + logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex); } return success; } @@ -198,7 +198,7 @@ public class OutboxRepositoryImpl implements OutboxRepository { EntityManager entityManager = null; Boolean success = false; - try (FakeRequestScope fakeRequestScope = new FakeRequestScope()) { + try (FakeRequestScope ignored = new FakeRequestScope()) { try { EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); @@ -211,7 +211,7 @@ public class OutboxRepositoryImpl implements OutboxRepository { QueueOutboxEntity item = queryFactory.query(QueueOutboxQuery.class).ids(candidateInfo.getId()).first(); if (item == null) { - this.logger.warn("Could not lookup queue outbox {} to process. Continuing...", candidateInfo.getId()); + logger.warn("Could not lookup queue outbox {} to process. Continuing...", candidateInfo.getId()); } else { success = publish.apply(item); @@ -235,14 +235,14 @@ public class OutboxRepositoryImpl implements OutboxRepository { transaction.commit(); } catch (Exception ex) { - this.logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex); + logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex); if (transaction != null) transaction.rollback(); success = false; } finally { if (entityManager != null) entityManager.close(); } } catch (Exception ex) { - this.logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex); + logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex); } return success; } @@ -252,7 +252,7 @@ public class OutboxRepositoryImpl implements OutboxRepository { EntityTransaction transaction = null; EntityManager entityManager = null; - try (FakeRequestScope fakeRequestScope = new FakeRequestScope()) { + try (FakeRequestScope ignored = new FakeRequestScope()) { try { EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); @@ -265,7 +265,7 @@ public class OutboxRepositoryImpl implements OutboxRepository { List queueOutboxMessages = queryFactory.query(QueueOutboxQuery.class).ids(confirmedMessages).collect(); if (queueOutboxMessages == null) { - this.logger.warn("Could not lookup messages {} to process. Continuing...", String.join(",", confirmedMessages.stream().map(x -> x.toString()).collect(Collectors.toList()))); + logger.warn("Could not lookup messages {} to process. Continuing...", String.join(",", confirmedMessages.stream().map(x -> x.toString()).collect(Collectors.toList()))); } else { for (QueueOutboxEntity queueOutboxMessage : queueOutboxMessages) { @@ -279,13 +279,13 @@ public class OutboxRepositoryImpl implements OutboxRepository { transaction.commit(); } catch (Exception ex) { - this.logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex); + logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex); if (transaction != null) transaction.rollback(); } finally { if (entityManager != null) entityManager.close(); } } catch (Exception ex) { - this.logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex); + logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex); } } @@ -294,7 +294,7 @@ public class OutboxRepositoryImpl implements OutboxRepository { EntityTransaction transaction = null; EntityManager entityManager = null; - try (FakeRequestScope fakeRequestScope = new FakeRequestScope()) { + try (FakeRequestScope ignored = new FakeRequestScope()) { try { EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); @@ -307,7 +307,7 @@ public class OutboxRepositoryImpl implements OutboxRepository { List queueOutboxMessages = queryFactory.query(QueueOutboxQuery.class).ids(nackedMessages).collect(); if (queueOutboxMessages == null) { - this.logger.warn("Could not lookup messages {} to process. Continuing...", String.join(",", nackedMessages.stream().map(x -> x.toString()).collect(Collectors.toList()))); + logger.warn("Could not lookup messages {} to process. Continuing...", String.join(",", nackedMessages.stream().map(x -> x.toString()).collect(Collectors.toList()))); } else { for (QueueOutboxEntity queueOutboxMessage : queueOutboxMessages) { @@ -321,13 +321,13 @@ public class OutboxRepositoryImpl implements OutboxRepository { transaction.commit(); } catch (Exception ex) { - this.logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex); + logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex); if (transaction != null) transaction.rollback(); } finally { if (entityManager != null) entityManager.close(); } } catch (Exception ex) { - this.logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex); + logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex); } } @@ -335,9 +335,9 @@ public class OutboxRepositoryImpl implements OutboxRepository { public QueueOutbox create(IntegrationEvent item) { EntityTransaction transaction = null; EntityManager entityManager = null; - Boolean success = false; + boolean success = false; QueueOutboxEntity queueMessage = null; - try (FakeRequestScope fakeRequestScope = new FakeRequestScope()) { + try (FakeRequestScope ignored = new FakeRequestScope()) { try { queueMessage = this.mapEvent((OutboxIntegrationEvent) item); EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); @@ -352,14 +352,14 @@ public class OutboxRepositoryImpl implements OutboxRepository { transaction.commit(); } catch (Exception ex) { - this.logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex); + logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex); if (transaction != null) transaction.rollback(); success = false; } finally { if (entityManager != null) entityManager.close(); } } catch (Exception ex) { - this.logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex); + logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex); } return queueMessage; } diff --git a/dmp-backend/notification-service/notification-web/src/main/resources/config/queue-devel.yml b/dmp-backend/notification-service/notification-web/src/main/resources/config/queue-devel.yml index f0e31766d..04855c727 100644 --- a/dmp-backend/notification-service/notification-web/src/main/resources/config/queue-devel.yml +++ b/dmp-backend/notification-service/notification-web/src/main/resources/config/queue-devel.yml @@ -15,4 +15,4 @@ queue: options: exchange: cite_dmp_devel_queue rabbitmq: - enable: false + enable: true diff --git a/dmp-backend/notification-service/notification-web/src/main/resources/config/queue.yml b/dmp-backend/notification-service/notification-web/src/main/resources/config/queue.yml index 2886f369a..4bc96aee1 100644 --- a/dmp-backend/notification-service/notification-web/src/main/resources/config/queue.yml +++ b/dmp-backend/notification-service/notification-web/src/main/resources/config/queue.yml @@ -26,11 +26,6 @@ queue: options: exchange: null forget-me-completed-topic: forgetme.completed - notify-topic: notification.notify - tenant-reactivation-topic: tenant.reactivated - tenant-removal-topic: tenant.remove - tenant-touch-topic: tenant.touch - tenant-user-invite-topic: tenant.invite what-you-know-about-me-completed-topic: whatyouknowaboutme.completed generate-file-topic: generate.file rabbitmq: @@ -46,8 +41,11 @@ queue: enable: false options: exchange: null - user-removal-topic: [ "user.remove" ] - user-touched-topic: [ "user.touch" ] + notify-topic: notification.notify + tenant-removal-topic: tenant.remove + tenant-touch-topic: tenant.touch + user-removal-topic: user.remove + user-touch-topic: user.touch rabbitmq: enable: false interval-seconds: 30 diff --git a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/AppRabbitConfigurer.java b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/AppRabbitConfigurer.java index ab93cf53f..cfe2ecd6e 100644 --- a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/AppRabbitConfigurer.java +++ b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/AppRabbitConfigurer.java @@ -32,6 +32,9 @@ public class AppRabbitConfigurer extends RabbitConfigurer { @Bean public InboxBindings inboxBindingsCreator() { List bindingItems = new ArrayList<>(); + bindingItems.addAll(this.inboxProperties.getNotifyTopic()); + bindingItems.addAll(this.inboxProperties.getTenantRemovalTopic()); + bindingItems.addAll(this.inboxProperties.getTenantTouchedTopic()); bindingItems.addAll(this.inboxProperties.getUserRemovalTopic()); bindingItems.addAll(this.inboxProperties.getUserTouchedTopic()); diff --git a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/InboxProperties.java b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/InboxProperties.java index a3345ca98..3d257f8aa 100644 --- a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/InboxProperties.java +++ b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/InboxProperties.java @@ -1,6 +1,7 @@ package gr.cite.notification.integrationevent.inbox; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.ConstructorBinding; import org.springframework.validation.annotation.Validated; import javax.validation.constraints.NotNull; @@ -8,6 +9,7 @@ import java.util.List; @Validated @ConfigurationProperties(prefix = "queue.task.listener.options") +@ConstructorBinding public class InboxProperties { @NotNull @@ -17,7 +19,7 @@ public class InboxProperties { private final List notifyTopic; @NotNull - private final List tenantRemovedTopic; + private final List tenantRemovalTopic; @NotNull private final List tenantTouchedTopic; @@ -29,12 +31,15 @@ public class InboxProperties { private final List userTouchedTopic; public InboxProperties( - String exchange, List notifyTopic, List tenantRemovedTopic, List tenantTouchedTopic, + String exchange, + List notifyTopic, + List tenantRemovalTopic, + List tenantTouchedTopic, List userRemovalTopic, List userTouchedTopic) { this.exchange = exchange; this.notifyTopic = notifyTopic; - this.tenantRemovedTopic = tenantRemovedTopic; + this.tenantRemovalTopic = tenantRemovalTopic; this.tenantTouchedTopic = tenantTouchedTopic; this.userRemovalTopic = userRemovalTopic; this.userTouchedTopic = userTouchedTopic; @@ -44,8 +49,8 @@ public class InboxProperties { return notifyTopic; } - public List getTenantRemovedTopic() { - return tenantRemovedTopic; + public List getTenantRemovalTopic() { + return tenantRemovalTopic; } public List getTenantTouchedTopic() { diff --git a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/InboxRepositoryImpl.java b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/InboxRepositoryImpl.java index 3dcff805b..811725fbe 100644 --- a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/InboxRepositoryImpl.java +++ b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/InboxRepositoryImpl.java @@ -26,14 +26,12 @@ import jakarta.persistence.EntityTransaction; import jakarta.persistence.OptimisticLockException; import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationContext; -import org.springframework.stereotype.Component; import java.time.Instant; import java.util.List; import java.util.UUID; import java.util.function.Function; -@Component public class InboxRepositoryImpl implements InboxRepository { private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(InboxRepositoryImpl.class)); @@ -325,15 +323,15 @@ public class InboxRepositoryImpl implements InboxRepository { private EventProcessingStatus processMessage(String routingKey, String messageId, String appId, String message) { IntegrationEventHandler handler; - if (this.RoutingKeyMatched(routingKey, this.inboxProperties.getNotifyTopic())) + if (this.routingKeyMatched(routingKey, this.inboxProperties.getNotifyTopic())) handler = this.applicationContext.getBean(NotifyIntegrationEventHandler.class); - else if (this.RoutingKeyMatched(routingKey, this.inboxProperties.getTenantRemovedTopic())) + else if (this.routingKeyMatched(routingKey, this.inboxProperties.getTenantRemovalTopic())) handler = this.applicationContext.getBean(TenantRemovalIntegrationEventHandler.class); - else if (this.RoutingKeyMatched(routingKey, this.inboxProperties.getTenantTouchedTopic())) + else if (this.routingKeyMatched(routingKey, this.inboxProperties.getTenantTouchedTopic())) handler = this.applicationContext.getBean(TenantTouchedIntegrationEventHandler.class); - else if (this.RoutingKeyMatched(routingKey, this.inboxProperties.getUserRemovalTopic())) + else if (this.routingKeyMatched(routingKey, this.inboxProperties.getUserRemovalTopic())) handler = this.applicationContext.getBean(UserRemovalIntegrationEventHandler.class); - else if (this.RoutingKeyMatched(routingKey, this.inboxProperties.getUserTouchedTopic())) + else if (this.routingKeyMatched(routingKey, this.inboxProperties.getUserTouchedTopic())) handler = this.applicationContext.getBean(UserTouchedIntegrationEventHandler.class); else handler = null; @@ -357,7 +355,7 @@ public class InboxRepositoryImpl implements InboxRepository { // } } - private Boolean RoutingKeyMatched(String routingKey, List topics) { + private Boolean routingKeyMatched(String routingKey, List topics) { if (topics == null || topics.isEmpty()) return false; return topics.stream().anyMatch(x -> x.equals(routingKey));