Search in sources :

Example 11 with StreamConsumer

use of co.cask.cdap.data2.transaction.stream.StreamConsumer in project cdap by caskdata.

the class InMemoryStreamConsumerFactory method create.

@Override
public StreamConsumer create(StreamId streamId, String namespace, ConsumerConfig consumerConfig) throws IOException {
    QueueName queueName = QueueName.fromStream(streamId);
    QueueConsumer consumer = queueClientFactory.createConsumer(queueName, consumerConfig, -1);
    return new QueueToStreamConsumer(streamId, consumerConfig, consumer);
}
Also used : QueueConsumer(co.cask.cdap.data2.queue.QueueConsumer) QueueName(co.cask.cdap.common.queue.QueueName) QueueToStreamConsumer(co.cask.cdap.data2.transaction.stream.QueueToStreamConsumer)

Example 12 with StreamConsumer

use of co.cask.cdap.data2.transaction.stream.StreamConsumer in project cdap by caskdata.

the class LineageWriterDataFabricFacade method createStreamConsumer.

@Override
public StreamConsumer createStreamConsumer(StreamId streamName, ConsumerConfig consumerConfig) throws IOException {
    String namespace = String.format("%s.%s", programId.getApplicationId(), programId.getId());
    final StreamConsumer consumer = streamConsumerFactory.create(streamName, namespace, consumerConfig);
    datasetCache.addExtraTransactionAware(consumer);
    ProgramContext programContext = this.programContext;
    if (programContext != null) {
        lineageWriter.addAccess(programContext.getProgramRunId(), streamName, AccessType.READ, programContext.getComponentId());
    }
    return new ForwardingStreamConsumer(consumer) {

        @Override
        public void close() throws IOException {
            super.close();
            datasetCache.removeExtraTransactionAware(consumer);
        }
    };
}
Also used : ForwardingStreamConsumer(co.cask.cdap.data2.transaction.stream.ForwardingStreamConsumer) StreamConsumer(co.cask.cdap.data2.transaction.stream.StreamConsumer) ProgramContext(co.cask.cdap.data.ProgramContext) ForwardingStreamConsumer(co.cask.cdap.data2.transaction.stream.ForwardingStreamConsumer)

Example 13 with StreamConsumer

use of co.cask.cdap.data2.transaction.stream.StreamConsumer in project cdap by caskdata.

the class ConsumerSupplier method open.

/**
   * Updates number of instances for the consumer group that this instance belongs to. It'll close existing
   * consumer and create a new one with the new group size.
   *
   * @param groupSize New group size.
   */
void open(int groupSize) {
    try {
        close();
        ConsumerConfig config = consumerConfig;
        if (groupSize != config.getGroupSize()) {
            config = new ConsumerConfig(consumerConfig.getGroupId(), consumerConfig.getInstanceId(), groupSize, consumerConfig.getDequeueStrategy(), consumerConfig.getHashKey());
        }
        if (queueName.isQueue()) {
            QueueConsumer queueConsumer = dataFabricFacade.createConsumer(queueName, config, numGroups);
            consumerConfig = queueConsumer.getConfig();
            consumer = queueConsumer;
        } else {
            StreamId queueStream = queueName.toStreamId();
            for (EntityId owner : owners) {
                try {
                    runtimeUsageRegistry.register(owner, queueStream);
                } catch (Exception e) {
                    LOG.warn("Failed to register usage of {} -> {}", owner, queueStream, e);
                }
            }
            StreamConsumer streamConsumer = dataFabricFacade.createStreamConsumer(queueName.toStreamId(), config);
            consumerConfig = streamConsumer.getConsumerConfig();
            consumer = streamConsumer;
        }
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : EntityId(co.cask.cdap.proto.id.EntityId) StreamConsumer(co.cask.cdap.data2.transaction.stream.StreamConsumer) StreamId(co.cask.cdap.proto.id.StreamId) QueueConsumer(co.cask.cdap.data2.queue.QueueConsumer) ConsumerConfig(co.cask.cdap.data2.queue.ConsumerConfig) IOException(java.io.IOException)

Aggregations

ConsumerConfig (co.cask.cdap.data2.queue.ConsumerConfig)8 StreamEvent (co.cask.cdap.api.flow.flowlet.StreamEvent)7 StreamId (co.cask.cdap.proto.id.StreamId)7 Test (org.junit.Test)6 TransactionContext (org.apache.tephra.TransactionContext)5 QueueConsumer (co.cask.cdap.data2.queue.QueueConsumer)3 StreamConsumer (co.cask.cdap.data2.transaction.stream.StreamConsumer)3 Properties (java.util.Properties)3 QueueName (co.cask.cdap.common.queue.QueueName)2 TableId (co.cask.cdap.data2.util.TableId)2 Tick (co.cask.cdap.api.annotation.Tick)1 Schema (co.cask.cdap.api.data.schema.Schema)1 QueueReader (co.cask.cdap.app.queue.QueueReader)1 QueueSpecification (co.cask.cdap.app.queue.QueueSpecification)1 Node (co.cask.cdap.app.queue.QueueSpecificationGenerator.Node)1 ProgramContext (co.cask.cdap.data.ProgramContext)1 TTLReadFilter (co.cask.cdap.data.file.filter.TTLReadFilter)1 LevelDBTableCore (co.cask.cdap.data2.dataset2.lib.table.leveldb.LevelDBTableCore)1 ForwardingStreamConsumer (co.cask.cdap.data2.transaction.stream.ForwardingStreamConsumer)1 QueueToStreamConsumer (co.cask.cdap.data2.transaction.stream.QueueToStreamConsumer)1