Notification service config update

This commit is contained in:
Thomas Georgios Giannos 2024-01-12 13:55:50 +02:00
parent 2fb387825d
commit 93ce7ecd6d
6 changed files with 54 additions and 50 deletions

View File

@ -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<QueueOutbox, Boolean> 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<QueueOutbox, Boolean> 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<QueueOutboxEntity> 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<QueueOutboxEntity> 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;
}

View File

@ -15,4 +15,4 @@ queue:
options:
exchange: cite_dmp_devel_queue
rabbitmq:
enable: false
enable: true

View File

@ -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

View File

@ -32,6 +32,9 @@ public class AppRabbitConfigurer extends RabbitConfigurer {
@Bean
public InboxBindings inboxBindingsCreator() {
List<String> 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());

View File

@ -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<String> notifyTopic;
@NotNull
private final List<String> tenantRemovedTopic;
private final List<String> tenantRemovalTopic;
@NotNull
private final List<String> tenantTouchedTopic;
@ -29,12 +31,15 @@ public class InboxProperties {
private final List<String> userTouchedTopic;
public InboxProperties(
String exchange, List<String> notifyTopic, List<String> tenantRemovedTopic, List<String> tenantTouchedTopic,
String exchange,
List<String> notifyTopic,
List<String> tenantRemovalTopic,
List<String> tenantTouchedTopic,
List<String> userRemovalTopic,
List<String> 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<String> getTenantRemovedTopic() {
return tenantRemovedTopic;
public List<String> getTenantRemovalTopic() {
return tenantRemovalTopic;
}
public List<String> getTenantTouchedTopic() {

View File

@ -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<String> topics) {
private Boolean routingKeyMatched(String routingKey, List<String> topics) {
if (topics == null || topics.isEmpty())
return false;
return topics.stream().anyMatch(x -> x.equals(routingKey));