Search in sources :

Example 1 with BindingSetRecordExportException

use of org.apache.rya.periodic.notification.api.BindingSetRecordExportException in project incubator-rya by apache.

the class KafkaPeriodicBindingSetExporter method exportNotification.

/**
 * Exports BindingSets to Kafka.  The BindingSet and topic are extracted from
 * the indicated BindingSetRecord and the BindingSet is then exported to the topic.
 */
@Override
public void exportNotification(final BindingSetRecord record) throws BindingSetRecordExportException {
    try {
        log.info("Exporting {} records to Kafka to topic: {}", record.getBindingSet().size(), record.getTopic());
        final String bindingName = IncrementalUpdateConstants.PERIODIC_BIN_ID;
        final BindingSet bindingSet = record.getBindingSet();
        final String topic = record.getTopic();
        final long binId = ((Literal) bindingSet.getValue(bindingName)).longValue();
        final Future<RecordMetadata> future = producer.send(new ProducerRecord<String, BindingSet>(topic, Long.toString(binId), bindingSet));
        // wait for confirmation that results have been received
        future.get(5, TimeUnit.SECONDS);
    } catch (final Exception e) {
        // catch all possible exceptional behavior and throw as our checked exception.
        throw new BindingSetRecordExportException(e.getMessage(), e);
    }
}
Also used : RecordMetadata(org.apache.kafka.clients.producer.RecordMetadata) BindingSet(org.openrdf.query.BindingSet) BindingSetRecordExportException(org.apache.rya.periodic.notification.api.BindingSetRecordExportException) Literal(org.openrdf.model.Literal) BindingSetRecordExportException(org.apache.rya.periodic.notification.api.BindingSetRecordExportException)

Aggregations

RecordMetadata (org.apache.kafka.clients.producer.RecordMetadata)1 BindingSetRecordExportException (org.apache.rya.periodic.notification.api.BindingSetRecordExportException)1 Literal (org.openrdf.model.Literal)1 BindingSet (org.openrdf.query.BindingSet)1