use of org.folio.rest.util.OkapiConnectionParams in project mod-inventory by folio-org.
the class QuickMarcKafkaHandler method handle.
@Override
public Future<String> handle(KafkaConsumerRecord<String, String> record) {
var params = new OkapiConnectionParams(kafkaHeadersToMap(record.headers()), vertx);
var context = constructContext(params.getTenantId(), params.getToken(), params.getOkapiUrl());
Event event = Json.decodeValue(record.value(), Event.class);
LOGGER.info("Quick marc event payload has been received with event type: {}", event.getEventType());
return getEventPayload(event).compose(eventPayload -> processPayload(eventPayload, context).compose(recordType -> sendEvent(eventPayload, getReplyEventType(recordType), params)).recover(throwable -> sendErrorEvent(params, eventPayload, throwable)).map(ar -> record.key()), th -> {
LOGGER.error("Update record state was failed while handle event, {}", th.getMessage());
return Future.failedFuture(th.getMessage());
});
}
use of org.folio.rest.util.OkapiConnectionParams in project mod-circulation-storage by folio-org.
the class PubSubPublishingService method publishEvent.
public CompletableFuture<Boolean> publishEvent(String eventType, String payload) {
Event event = new Event().withId(UUID.randomUUID().toString()).withEventType(eventType).withEventPayload(payload).withEventMetadata(new EventMetadata().withPublishedBy(PubSubClientUtils.getModuleId()).withTenantId(okapiHeaders.get(OKAPI_TENANT_HEADER)).withEventTTL(1));
final CompletableFuture<Boolean> publishResult = new CompletableFuture<>();
OkapiConnectionParams params = new OkapiConnectionParams();
params.setOkapiUrl(okapiHeaders.get(OKAPI_URL_HEADER));
params.setTenantId(okapiHeaders.get(OKAPI_TENANT_HEADER));
params.setToken(okapiHeaders.get(OKAPI_TOKEN_HEADER));
context.runOnContext(v -> PubSubClientUtils.sendEventMessage(event, params).whenComplete((result, throwable) -> {
if (Boolean.TRUE.equals(result)) {
logger.debug("Event published successfully. ID: {}, type: {}, payload: {}", event.getId(), event.getEventType(), event.getEventPayload());
publishResult.complete(true);
} else {
logger.error("Failed to publish event. ID: {}, type: {}, payload: {}", throwable, event.getId(), event.getEventType(), event.getEventPayload());
if (throwable == null) {
publishResult.complete(false);
} else {
publishResult.completeExceptionally(throwable);
}
}
}));
return publishResult;
}
use of org.folio.rest.util.OkapiConnectionParams in project mod-circulation by folio-org.
the class PubSubPublishingService method publishEvent.
public CompletableFuture<Boolean> publishEvent(String eventType, String payload) {
Event event = new Event().withId(UUID.randomUUID().toString()).withEventType(eventType).withEventPayload(payload).withEventMetadata(new EventMetadata().withPublishedBy(PubSubClientUtils.getModuleId()).withTenantId(okapiHeaders.get(OKAPI_TENANT_HEADER)).withEventTTL(1));
final CompletableFuture<Boolean> publishResult = new CompletableFuture<>();
OkapiConnectionParams params = new OkapiConnectionParams();
params.setOkapiUrl(okapiHeaders.get(OKAPI_URL_HEADER));
params.setTenantId(okapiHeaders.get(OKAPI_TENANT_HEADER));
params.setToken(okapiHeaders.get(OKAPI_TOKEN_HEADER));
vertxContext.runOnContext(v -> PubSubClientUtils.sendEventMessage(event, params).whenComplete((result, throwable) -> {
if (Boolean.TRUE.equals(result)) {
logger.info("Event published successfully. ID: {}, type: {}, payload: {}", event.getId(), event.getEventType(), event.getEventPayload());
publishResult.complete(true);
} else {
logger.error("Failed to publish event. ID: {}, type: {}, payload: {}, cause: {}", event.getId(), event.getEventType(), event.getEventPayload(), throwable);
if (throwable == null) {
publishResult.complete(false);
} else {
publishResult.completeExceptionally(throwable);
}
}
}));
return publishResult;
}
Aggregations