Search in sources :

Example 1 with IRecordProcessorFactory

use of com.amazonaws.services.kinesis.clientlibrary.interfaces.IRecordProcessorFactory in project amazon-kinesis-video-streams-parser-library by aws.

the class KinesisDataStreamsWorker method run.

@Override
public void run() {
    try {
        String workerId = InetAddress.getLocalHost().getCanonicalHostName() + ":" + UUID.randomUUID();
        KinesisClientLibConfiguration kinesisClientLibConfiguration = new KinesisClientLibConfiguration(APPLICATION_NAME, kdsStreamName, credentialsProvider, workerId);
        kinesisClientLibConfiguration.withInitialPositionInStream(SAMPLE_APPLICATION_INITIAL_POSITION_IN_STREAM).withRegionName(region.getName());
        final IRecordProcessorFactory recordProcessorFactory = () -> new KinesisRecordProcessor(rekognizedFragmentsIndex, credentialsProvider);
        final Worker worker = new Worker(recordProcessorFactory, kinesisClientLibConfiguration);
        System.out.printf("Running %s to process stream %s as worker %s...", APPLICATION_NAME, kdsStreamName, workerId);
        int exitCode = 0;
        try {
            worker.run();
        } catch (Throwable t) {
            System.err.println("Caught throwable while processing data.");
            t.printStackTrace();
            exitCode = 1;
        }
        System.out.println("Exit code : " + exitCode);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : IRecordProcessorFactory(com.amazonaws.services.kinesis.clientlibrary.interfaces.IRecordProcessorFactory) KinesisClientLibConfiguration(com.amazonaws.services.kinesis.clientlibrary.lib.worker.KinesisClientLibConfiguration) Worker(com.amazonaws.services.kinesis.clientlibrary.lib.worker.Worker)

Example 2 with IRecordProcessorFactory

use of com.amazonaws.services.kinesis.clientlibrary.interfaces.IRecordProcessorFactory in project carbonj by salesforce.

the class KinesisConsumer method run.

public void run() {
    while (!closed) {
        try {
            AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain();
            String workerId = kinesisApplicationName + "-worker";
            if (kinesisConfig.isRecoveryEnabled()) {
                initCatchupKinesisClient();
            }
            KinesisClientLibConfiguration kinesisClientLibConfiguration = new KinesisClientLibConfiguration(kinesisApplicationName, kinesisStreamName, credentialsProvider, workerId).withInitialPositionInStream(InitialPositionInStream.LATEST).withFailoverTimeMillis(kinesisConfig.getLeaseExpirationTimeInSecs() * 1000).withRegionName(kinesisConsumerRegion);
            int maxRecords = kinesisConfig.getMaxRecords();
            if (maxRecords > 0) {
                kinesisClientLibConfiguration.withMaxRecords(maxRecords);
            }
            log.info(" Kinesis Client Library started with application name " + kinesisApplicationName + " with stream " + kinesisStreamName + " and worker id is " + workerId);
            IRecordProcessorFactory recordProcessorFactory = new KinesisRecordProcessorFactory(metricRegistry, pointProcessor, kinesisConfig, kinesisStreamName);
            worker = new Worker.Builder().recordProcessorFactory(recordProcessorFactory).config(kinesisClientLibConfiguration).leaseManager(new MemLeaseManager(kinesisConfig.getLeaseTakerDelayInMillis())).build();
            worker.run();
        } catch (Throwable t) {
            log.error("Error in initializing kinesis consumer", t);
            shutdownQuietly(worker);
            try {
                Thread.sleep(TimeUnit.SECONDS.toMillis(kinesisConfig.getInitRetryTimeInSecs()));
            } catch (InterruptedException e) {
                log.error("wait interrupted", e);
            }
            noOfRestarts.inc();
        }
    }
}
Also used : DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) MemLeaseManager(com.demandware.carbonj.service.engine.kinesis.kcl.MemLeaseManager) IRecordProcessorFactory(com.amazonaws.services.kinesis.clientlibrary.interfaces.IRecordProcessorFactory) KinesisClientLibConfiguration(com.amazonaws.services.kinesis.clientlibrary.lib.worker.KinesisClientLibConfiguration) Worker(com.amazonaws.services.kinesis.clientlibrary.lib.worker.Worker) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider)

Aggregations

IRecordProcessorFactory (com.amazonaws.services.kinesis.clientlibrary.interfaces.IRecordProcessorFactory)2 KinesisClientLibConfiguration (com.amazonaws.services.kinesis.clientlibrary.lib.worker.KinesisClientLibConfiguration)2 Worker (com.amazonaws.services.kinesis.clientlibrary.lib.worker.Worker)2 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)1 DefaultAWSCredentialsProviderChain (com.amazonaws.auth.DefaultAWSCredentialsProviderChain)1 MemLeaseManager (com.demandware.carbonj.service.engine.kinesis.kcl.MemLeaseManager)1