use of org.folio.rest.jaxrs.model.EventMetadata in project mod-source-record-storage by folio-org.
the class ParsedRecordChunksKafkaHandler method sendBackRecordsBatchResponse.
private Future<String> sendBackRecordsBatchResponse(RecordsBatchResponse recordsBatchResponse, List<KafkaHeader> kafkaHeaders, String tenantId, int chunkNumber, String eventType, KafkaConsumerRecord<String, String> commonRecord) {
Event event;
event = new Event().withId(UUID.randomUUID().toString()).withEventType(DI_PARSED_RECORDS_CHUNK_SAVED.value()).withEventPayload(Json.encode(normalize(recordsBatchResponse))).withEventMetadata(new EventMetadata().withTenantId(tenantId).withEventTTL(1).withPublishedBy(constructModuleName()));
String key = String.valueOf(indexer.incrementAndGet() % maxDistributionNum);
String topicName = KafkaTopicNameHelper.formatTopicName(kafkaConfig.getEnvId(), KafkaTopicNameHelper.getDefaultNameSpace(), tenantId, DI_PARSED_RECORDS_CHUNK_SAVED.value());
KafkaProducerRecord<String, String> targetRecord = KafkaProducerRecord.create(topicName, key, Json.encode(event));
targetRecord.addHeaders(kafkaHeaders);
Promise<String> writePromise = Promise.promise();
String producerName = DI_PARSED_RECORDS_CHUNK_SAVED + "_Producer";
KafkaProducer<String, String> producer = KafkaProducer.createShared(Vertx.currentContext().owner(), producerName, kafkaConfig.getProducerProps());
producer.write(targetRecord, war -> {
producer.end(ear -> producer.close());
if (war.succeeded()) {
String recordId = extractValueFromHeaders(commonRecord.headers(), RECORD_ID_HEADER);
String chunkId = extractValueFromHeaders(commonRecord.headers(), CHUNK_ID_HEADER);
LOGGER.debug("RecordCollection processing has been completed with response sent... event: '{}', chunkId: '{}', chunkNumber '{}'-'{}' with recordId: '{}'", eventType, chunkId, chunkNumber, targetRecord.key(), recordId);
writePromise.complete(targetRecord.key());
} else {
Throwable cause = war.cause();
LOGGER.error("{} write error {}", producerName, cause);
writePromise.fail(cause);
}
});
return writePromise.future();
}
use of org.folio.rest.jaxrs.model.EventMetadata 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.jaxrs.model.EventMetadata 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;
}
use of org.folio.rest.jaxrs.model.EventMetadata in project mod-inventory by folio-org.
the class QuickMarcKafkaHandler method createRecord.
private KafkaProducerRecord<String, String> createRecord(String eventPayload, String eventType, String key, OkapiConnectionParams params) {
Event event = new Event().withId(UUID.randomUUID().toString()).withEventType(eventType).withEventPayload(eventPayload).withEventMetadata(new EventMetadata().withTenantId(params.getTenantId()).withEventTTL(1).withPublishedBy(ConsumerWrapperUtil.constructModuleName()));
String topicName = formatTopicName(kafkaConfig.getEnvId(), getDefaultNameSpace(), params.getTenantId(), eventType);
var record = KafkaProducerRecord.create(topicName, key, Json.encode(event));
record.addHeaders(kafkaHeadersFromMap(params.getHeaders()));
return record;
}
use of org.folio.rest.jaxrs.model.EventMetadata in project mod-source-record-storage by folio-org.
the class EventHandlingUtil method createProducerRecord.
public static KafkaProducerRecord<String, String> createProducerRecord(String eventPayload, String eventType, String key, String tenantId, List<KafkaHeader> kafkaHeaders, KafkaConfig kafkaConfig) {
Event event = new Event().withId(UUID.randomUUID().toString()).withEventType(eventType).withEventPayload(eventPayload).withEventMetadata(new EventMetadata().withTenantId(tenantId).withEventTTL(1).withPublishedBy(constructModuleName()));
String topicName = createTopicName(eventType, tenantId, kafkaConfig);
KafkaProducerRecord<String, String> record = KafkaProducerRecord.create(topicName, key, Json.encode(event));
record.addHeaders(kafkaHeaders);
return record;
}
Aggregations