001/* 002 * (C) Copyright 2017 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * bdelbosc 018 */ 019 020package org.nuxeo.ecm.platform.importer.mqueues.workmanager; 021 022import org.apache.commons.logging.Log; 023import org.apache.commons.logging.LogFactory; 024import org.nuxeo.ecm.platform.importer.mqueues.computation.Record; 025import org.nuxeo.ecm.platform.importer.mqueues.kafka.KafkaConfigService; 026import org.nuxeo.ecm.platform.importer.mqueues.mqueues.MQManager; 027import org.nuxeo.ecm.platform.importer.mqueues.mqueues.kafka.KafkaMQManager; 028import org.nuxeo.runtime.api.Framework; 029 030 031/** 032 * @since 9.2 033 */ 034public class WorkManagerComputationKafka extends WorkManagerComputation { 035 protected static final Log log = LogFactory.getLog(WorkManagerComputationKafka.class); 036 public static final String NUXEO_WORKMANAGER_KAFKA_CONFIG_PROP = "nuxeo.mqueue.work.kafka.config"; 037 public static final String NUXEO_WORKMANAGER_KAFKA_OVERPROVISIONING_PROP = "nuxeo.mqueue.work.kafka.overprovisioning"; 038 public static final String DEFAULT_CONFIG = "default"; 039 public static final String DEFAULT_OVERPROVISIONING = "3"; 040 041 @Override 042 protected MQManager<Record> initStream() { 043 KafkaConfigService service = Framework.getService(KafkaConfigService.class); 044 String kafkaConfig = Framework.getProperty(NUXEO_WORKMANAGER_KAFKA_CONFIG_PROP, DEFAULT_CONFIG); 045 log.info("Init WorkManagerComputation with Kafka, using configuration: " + kafkaConfig); 046 return new KafkaMQManager<>(service.getZkServers(kafkaConfig), 047 service.getTopicPrefix(kafkaConfig), 048 service.getProducerProperties(kafkaConfig), 049 service.getConsumerProperties(kafkaConfig)); 050 } 051 052 @Override 053 protected int getOverProvisioningFactor() { 054 return Integer.valueOf(Framework.getProperty(NUXEO_WORKMANAGER_KAFKA_OVERPROVISIONING_PROP, 055 DEFAULT_OVERPROVISIONING)); 056 } 057}