forked from folio-org/mod-circulation-storage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInitAPIImpl.java
More file actions
59 lines (49 loc) · 2.5 KB
/
Copy pathInitAPIImpl.java
File metadata and controls
59 lines (49 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package org.folio.rest.impl;
import static java.lang.System.getenv;
import static org.folio.support.kafka.KafkaConfigConstants.KAFKA_ENV;
import static org.folio.support.kafka.KafkaConfigConstants.KAFKA_HOST;
import static org.folio.support.kafka.KafkaConfigConstants.KAFKA_MAX_REQUEST_SIZE;
import static org.folio.support.kafka.KafkaConfigConstants.KAFKA_PORT;
import static org.folio.support.kafka.KafkaConfigConstants.KAFKA_REPLICATION_FACTOR;
import static org.folio.support.kafka.KafkaConfigConstants.OKAPI_URL;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.folio.EventConsumerVerticle;
import org.folio.kafka.services.KafkaEnvironmentProperties;
import org.folio.rest.resource.interfaces.InitAPI;
import io.vertx.core.AsyncResult;
import io.vertx.core.Context;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
public class InitAPIImpl implements InitAPI {
private static final Logger log = LogManager.getLogger(InitAPIImpl.class);
private static final String DEFAULT_OKAPI_URL = "http://okapi:9130";
private static final int DEFAULT_MAX_REQUEST_SIZE = 4000000;
@Override
public void init(Vertx vertx, Context context, Handler<AsyncResult<Boolean>> resultHandler) {
deployEventConsumerVerticle(vertx)
.map(true)
.onSuccess(r -> log.info("init:: initialization complete"))
.onFailure(t -> log.error("init:: initialization failed", t))
.onComplete(resultHandler);
}
private static Future<String> deployEventConsumerVerticle(Vertx vertx) {
JsonObject kafkaConfig = new JsonObject()
.put(KAFKA_HOST, KafkaEnvironmentProperties.host())
.put(KAFKA_PORT, KafkaEnvironmentProperties.port())
.put(KAFKA_REPLICATION_FACTOR, KafkaEnvironmentProperties.replicationFactor())
.put(KAFKA_ENV, KafkaEnvironmentProperties.environment())
.put(OKAPI_URL, getenv().getOrDefault(OKAPI_URL, DEFAULT_OKAPI_URL))
.put(KAFKA_MAX_REQUEST_SIZE, getenv().getOrDefault(KAFKA_MAX_REQUEST_SIZE,
String.valueOf(DEFAULT_MAX_REQUEST_SIZE)));
DeploymentOptions deploymentOptions = new DeploymentOptions()
.setWorker(true)
.setConfig(kafkaConfig);
return vertx.deployVerticle(EventConsumerVerticle.class, deploymentOptions)
.onSuccess(r -> log.info("deployEventConsumerVerticle:: deployment complete"))
.onFailure(t -> log.error("deployEventConsumerVerticle:: deployment failed", t));
}
}