Skip to content

Commit

Permalink
SL: Fixed duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
amusarra committed May 13, 2024
1 parent c21d0c1 commit 46bd8c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package it.dontesta.eventbus.consumers.events.handlers.nosql;

import static it.dontesta.eventbus.application.configuration.EventHandlerAddress.*;

import io.quarkus.mongodb.reactive.ReactiveMongoClient;
import io.quarkus.mongodb.reactive.ReactiveMongoCollection;
import io.quarkus.runtime.ShutdownEvent;
Expand Down Expand Up @@ -65,19 +67,17 @@ public class MongoDbEventHandler {

public static final String SOURCE_COMPONENT = "source-component";

public static final String SOURCE_VIRTUAL_ADDRESS = "nosql-trace";
public static final String SOURCE_VIRTUAL_ADDRESS_NOSQL = "nosql-trace";

void onStart(@Observes StartupEvent ev) {

boolean existsAndEnabled = EventHandlerAddress.isAddressAndExistsEnabled(
eventHandlerAddresses, SOURCE_VIRTUAL_ADDRESS);

if (existsAndEnabled) {
if (isAddressAndExistsEnabled(
eventHandlerAddresses, SOURCE_VIRTUAL_ADDRESS_NOSQL)) {
log.debugf(
"Registering the MongoDB event handler at addresses: {%s}",
SOURCE_VIRTUAL_ADDRESS);
SOURCE_VIRTUAL_ADDRESS_NOSQL);

consumer = eventBus.consumer(SOURCE_VIRTUAL_ADDRESS);
consumer = eventBus.consumer(SOURCE_VIRTUAL_ADDRESS_NOSQL);
consumer.handler(this::handleEvent);
}

Expand All @@ -88,7 +88,7 @@ void onStop(@Observes ShutdownEvent ev) {
consumer.unregisterAndAwait();
log.debugf(
"Unregistering the MongoDB event handler at addresses: {%s}",
SOURCE_VIRTUAL_ADDRESS);
SOURCE_VIRTUAL_ADDRESS_NOSQL);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package it.dontesta.eventbus.consumers.events.handlers.queue;

import static it.dontesta.eventbus.application.configuration.EventHandlerAddress.isAddressAndExistsEnabled;

import io.quarkus.runtime.ShutdownEvent;
import io.quarkus.runtime.StartupEvent;
import io.vertx.core.json.JsonObject;
Expand Down Expand Up @@ -57,18 +59,16 @@ public class AmqpEventHandler {

public static final String SOURCE_COMPONENT = "source-component";

public static final String SOURCE_VIRTUAL_ADDRESS = "queue-trace";
public static final String SOURCE_VIRTUAL_ADDRESS_QUEUE = "queue-trace";

void onStart(@Observes StartupEvent ev) {

boolean existsAndEnabled = EventHandlerAddress.isAddressAndExistsEnabled(
eventHandlerAddresses, SOURCE_VIRTUAL_ADDRESS);

if (existsAndEnabled) {
if (isAddressAndExistsEnabled(
eventHandlerAddresses, SOURCE_VIRTUAL_ADDRESS_QUEUE)) {
log.debugf("Registering the AMQP event handler at addresses: {%s}",
SOURCE_VIRTUAL_ADDRESS);
SOURCE_VIRTUAL_ADDRESS_QUEUE);

consumer = eventBus.consumer(SOURCE_VIRTUAL_ADDRESS);
consumer = eventBus.consumer(SOURCE_VIRTUAL_ADDRESS_QUEUE);
consumer.handler(this::handleEvent);
}
}
Expand All @@ -77,7 +77,7 @@ void onStop(@Observes ShutdownEvent ev) {
if (consumer != null) {
consumer.unregisterAndAwait();
log.debugf("Unregistering the AMQP event handler at addresses: {%s}",
SOURCE_VIRTUAL_ADDRESS);
SOURCE_VIRTUAL_ADDRESS_QUEUE);
}
}

Expand Down

0 comments on commit 46bd8c3

Please sign in to comment.