当前位置: 首页>>代码示例>>Java>>正文


Java InitialPositionInStream类代码示例

本文整理汇总了Java中com.amazonaws.services.kinesis.clientlibrary.lib.worker.InitialPositionInStream的典型用法代码示例。如果您正苦于以下问题:Java InitialPositionInStream类的具体用法?Java InitialPositionInStream怎么用?Java InitialPositionInStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


InitialPositionInStream类属于com.amazonaws.services.kinesis.clientlibrary.lib.worker包,在下文中一共展示了InitialPositionInStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readsDataFromMockKinesis

import com.amazonaws.services.kinesis.clientlibrary.lib.worker.InitialPositionInStream; //导入依赖的package包/类
@Test
public void readsDataFromMockKinesis() {
  int noOfShards = 3;
  int noOfEventsPerShard = 100;
  List<List<AmazonKinesisMock.TestData>> testData =
      provideTestData(noOfShards, noOfEventsPerShard);

  PCollection<AmazonKinesisMock.TestData> result = p
      .apply(
          KinesisIO.read()
              .withStreamName("stream")
              .withInitialPositionInStream(InitialPositionInStream.TRIM_HORIZON)
              .withAWSClientsProvider(new AmazonKinesisMock.Provider(testData, 10))
              .withMaxNumRecords(noOfShards * noOfEventsPerShard))
      .apply(ParDo.of(new KinesisRecordToTestData()));
  PAssert.that(result).containsInAnyOrder(Iterables.concat(testData));
  p.run();
}
 
开发者ID:apache,项目名称:beam,代码行数:19,代码来源:KinesisMockReadTest.java

示例2: startKinesisConsumer

import com.amazonaws.services.kinesis.clientlibrary.lib.worker.InitialPositionInStream; //导入依赖的package包/类
private void startKinesisConsumer() throws Exception {
    AWSCredentialsProvider credentialsProvider = new
            DefaultAWSCredentialsProviderChain();

    String region = "eu-west-1";
    logger.info("Starting in Region " + region);

    String workerId = InetAddress.getLocalHost().getCanonicalHostName() + ":" + UUID.randomUUID();

    KinesisClientLibConfiguration kinesisClientLibConfiguration = new KinesisClientLibConfiguration(
            this.getClass().getName(), TestConstants.stream, credentialsProvider, workerId)
            .withInitialPositionInStream(InitialPositionInStream.LATEST).withRegionName(region);

    IRecordProcessorFactory recordProcessorFactory = new
            RecordFactory();
    worker = new Worker(recordProcessorFactory,
            kinesisClientLibConfiguration);

    es = Executors.newSingleThreadExecutor();
    es.execute(worker);
}
 
开发者ID:SaschaMoellering,项目名称:ingestion-service,代码行数:22,代码来源:KafkaKinesisIntegrationTest.java

示例3: JKinesisReceiver

import com.amazonaws.services.kinesis.clientlibrary.lib.worker.InitialPositionInStream; //导入依赖的package包/类
public JKinesisReceiver(String applicationName, String streamName,
                        String endpointUrl, String regionName,
                        Duration checkpoint, InitialPositionInStream position) {
    super(StorageLevel.MEMORY_ONLY_SER());

    this.workerId = getHostname() + ":" + String.valueOf(UUID.randomUUID());
    this.checkpointInterval = checkpoint;
    this.initialPosition = position;

    Region region = RegionUtils.getRegion(regionName);

    try {
        this.kclConfig = new KinesisClientLibConfiguration(applicationName, streamName,
                                                  getCredsProvider(),
                                                  workerId)
                        .withCommonClientConfig(CLIENT_CONF)
                        .withRegionName(region.getName())
                        .withKinesisEndpoint(endpointUrl)
                        .withInitialPositionInStream(InitialPositionInStream.LATEST)
                        .withTaskBackoffTimeMillis(500);
    } catch (Exception ex) {
        // do absolutely nothing - and feel good about it!
        // but ...
        // we'd do something meaningful in a PROD context
    }
}
 
开发者ID:lenards,项目名称:spark-cstar-canaries,代码行数:27,代码来源:JKinesisReceiver.java

示例4: getKinesisClientLibConfig

import com.amazonaws.services.kinesis.clientlibrary.lib.worker.InitialPositionInStream; //导入依赖的package包/类
/**
 * Get KCL config for a given system stream.
 * @param system name of the system
 * @param stream name of the stream
 * @param appName name of the application
 * @return Stream scoped KCL configs required to build
 *         {@link KinesisClientLibConfiguration}
 */
public KinesisClientLibConfiguration getKinesisClientLibConfig(String system, String stream, String appName) {
  ClientConfiguration clientConfig = getAWSClientConfig(system);
  String workerId = appName + "-" + UUID.randomUUID();
  InitialPositionInStream startPos = InitialPositionInStream.LATEST;
  AWSCredentialsProvider provider = credentialsProviderForStream(system, stream);
  KinesisClientLibConfiguration kinesisClientLibConfiguration =
      new KinesisClientLibConfiguration(appName, stream, provider, workerId)
          .withRegionName(getRegion(system, stream).getName())
          .withKinesisClientConfig(clientConfig)
          .withCloudWatchClientConfig(clientConfig)
          .withDynamoDBClientConfig(clientConfig)
          .withInitialPositionInStream(startPos)
          .withCallProcessRecordsEvenForEmptyRecordList(true); // For health monitoring metrics.
  // First, get system scoped configs for KCL and override with configs set at stream scope.
  setKinesisClientLibConfigs(
      subset(String.format(CONFIG_SYSTEM_KINESIS_CLIENT_LIB_CONFIG, system)), kinesisClientLibConfiguration);
  setKinesisClientLibConfigs(subset(String.format(CONFIG_STREAM_KINESIS_CLIENT_LIB_CONFIG, system, stream)),
      kinesisClientLibConfiguration);
  return kinesisClientLibConfiguration;
}
 
开发者ID:apache,项目名称:samza,代码行数:29,代码来源:KinesisConfig.java

示例5: upgradeToConsumerConfigBeanV1

import com.amazonaws.services.kinesis.clientlibrary.lib.worker.InitialPositionInStream; //导入依赖的package包/类
private void upgradeToConsumerConfigBeanV1(List<Config> configs) {
  for (Config config : configs) {
    // Migrate existing configs that were moved into the Kinesis Consumer config bean
    switch (config.getName()) {
      case "applicationName":
        // fall through
      case "maxBatchSize":
        // fall through
      case "idleTimeBetweenReads":
        // fall through
      case "maxWaitTime":
        // fall through
      case "previewWaitTime":
        moveConfigToBean(config, KINESIS_CONFIG_BEAN);
        break;
      default:
        // no-op
    }
  }
  commitMove(configs);

  configs.add(new Config(KINESIS_CONFIG_BEAN + ".initialPositionInStream", InitialPositionInStream.LATEST));
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:24,代码来源:KinesisSourceUpgrader.java

示例6: getKinesisConsumerConfig

import com.amazonaws.services.kinesis.clientlibrary.lib.worker.InitialPositionInStream; //导入依赖的package包/类
private KinesisConsumerConfigBean getKinesisConsumerConfig(String streamName) {
  KinesisConsumerConfigBean conf = new KinesisConsumerConfigBean();
  conf.dataFormatConfig = new DataParserFormatConfig();
  conf.awsConfig = new AWSConfig();
  conf.awsConfig.awsAccessKeyId = () -> "foo";
  conf.awsConfig.awsSecretAccessKey = () -> "boo";

  conf.region = AWSRegions.OTHER;
  conf.endpoint = getKinesisEndpoint();
  conf.streamName = streamName;

  conf.dataFormat = DataFormat.JSON;
  conf.dataFormatConfig.jsonContent = JsonMode.MULTIPLE_OBJECTS;
  conf.dataFormatConfig.charset = "UTF-8";
  conf.dataFormatConfig.jsonMaxObjectLen = 1024;

  conf.applicationName = UUID.randomUUID().toString();
  conf.idleTimeBetweenReads = 250;
  conf.initialPositionInStream = InitialPositionInStream.TRIM_HORIZON;
  conf.maxBatchSize = 1000;
  conf.maxRecordProcessors = 2; // Must be at least 1

  return conf;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:25,代码来源:KinesisSourceIT.java

示例7: initKinesis

import com.amazonaws.services.kinesis.clientlibrary.lib.worker.InitialPositionInStream; //导入依赖的package包/类
private void initKinesis() {
    String pid = ManagementFactory.getRuntimeMXBean().getName();
    pid = pid.indexOf('@') == -1 ? pid : pid.substring(0, pid.indexOf('@'));
    log.info("Creating kinesis consumer with pid {}.", pid);
    KinesisClientLibConfiguration config
            = new KinesisClientLibConfiguration(
                    "Zombies" /* aplication name */,
                    streamName,
                    new DefaultAWSCredentialsProviderChain(),
                    "ZombieConsumer_" + pid /* worker id*/)
            .withRegionName(region)
            .withFailoverTimeMillis(1000 * 30) // after 30 seconds this worker is considered ko                        
            .withMaxLeasesForWorker(2) // forced to read only 1 shard for demo reasons.
            .withMaxRecords(500) // max records per GetRecords
            .withCallProcessRecordsEvenForEmptyRecordList(false) // no records -> no processing
            .withInitialLeaseTableWriteCapacity(10) // Dynamodb lease table capacity
            .withInitialLeaseTableReadCapacity(10)
            .withInitialPositionInStream(InitialPositionInStream.TRIM_HORIZON);

    final Worker worker
            = new Worker.Builder()
            .recordProcessorFactory(zombieRecordFactory)
            .config(config)
            .build();

    new Thread() {
        @Override
        public void run() {
            worker.run();
        }
    }.start();
}
 
开发者ID:capside,项目名称:aws-kinesis-zombies,代码行数:33,代码来源:Consumer.java

示例8: shouldMapAllShardsToCheckpoints

import com.amazonaws.services.kinesis.clientlibrary.lib.worker.InitialPositionInStream; //导入依赖的package包/类
@Test
public void shouldMapAllShardsToCheckpoints() throws Exception {
  given(shard1.getShardId()).willReturn("shard-01");
  given(shard2.getShardId()).willReturn("shard-02");
  given(shard3.getShardId()).willReturn("shard-03");
  given(kinesisClient.listShards("stream")).willReturn(asList(shard1, shard2, shard3));

  StartingPoint startingPoint = new StartingPoint(InitialPositionInStream.LATEST);
  DynamicCheckpointGenerator underTest = new DynamicCheckpointGenerator("stream",
      startingPoint);

  KinesisReaderCheckpoint checkpoint = underTest.generate(kinesisClient);

  assertThat(checkpoint).hasSize(3);
}
 
开发者ID:apache,项目名称:beam,代码行数:16,代码来源:DynamicCheckpointGeneratorTest.java

示例9: start

import com.amazonaws.services.kinesis.clientlibrary.lib.worker.InitialPositionInStream; //导入依赖的package包/类
public void start() {
    final JavaStreamingContext context = new JavaStreamingContext(conf, checkpointInterval);

    // for graceful shutdown of the application ...
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            System.out.println("Shutting down streaming app...");
            context.stop(true, true);
            System.out.println("Shutdown of streaming app complete.");
        }
    });

    JKinesisReceiver receiver = new JKinesisReceiver(appName, streamName,
                                                     endpointUrl, regionName,
                                                     checkpointInterval,
                                                     InitialPositionInStream.LATEST);

    JavaDStream<String> dstream = context.receiverStream(receiver);

    JavaDStream<EventRecord> recs = dstream.map(new EventRecordMapFunc());

    recs.print();

    // persist to DStream to Cassandra
    javaFunctions(recs)
        .writerBuilder("canary", "eventrecord", mapToRow(EventRecord.class))
        .saveToCassandra();


    System.out.println("Start Spark Stream Processing...");

    context.start();
    context.awaitTermination();

}
 
开发者ID:lenards,项目名称:spark-cstar-canaries,代码行数:37,代码来源:Consumer.java

示例10: setKinesisClientLibConfigs

import com.amazonaws.services.kinesis.clientlibrary.lib.worker.InitialPositionInStream; //导入依赖的package包/类
private void setKinesisClientLibConfigs(Map<String, String> config, KinesisClientLibConfiguration kinesisLibConfig) {
  for (Entry<String, String> entry : config.entrySet()) {
    boolean found = false;
    String key = entry.getKey();
    String value = entry.getValue();
    if (StringUtils.isEmpty(value)) {
      continue;
    }
    for (Method method : KinesisClientLibConfiguration.class.getMethods()) {
      if (method.getName().equals("with" + key)) {
        found = true;
        Class<?> type = method.getParameterTypes()[0];
        try {
          if (type == long.class) {
            method.invoke(kinesisLibConfig, Long.valueOf(value));
          } else if (type == int.class) {
            method.invoke(kinesisLibConfig, Integer.valueOf(value));
          } else if (type == boolean.class) {
            method.invoke(kinesisLibConfig, Boolean.valueOf(value));
          } else if (type == String.class) {
            method.invoke(kinesisLibConfig, value);
          } else if (type == InitialPositionInStream.class) {
            method.invoke(kinesisLibConfig, InitialPositionInStream.valueOf(value.toUpperCase()));
          }
          LOG.info("Loaded property " + key + " = " + value);
          break;
        } catch (Exception e) {
          throw new IllegalArgumentException(
              String.format("Error trying to set field %s with the value '%s'", key, value), e);
        }
      }
    }
    if (!found) {
      LOG.warn("Property " + key + " ignored as there is no corresponding set method");
    }
  }
}
 
开发者ID:apache,项目名称:samza,代码行数:38,代码来源:KinesisConfig.java

示例11: testKclConfigs

import com.amazonaws.services.kinesis.clientlibrary.lib.worker.InitialPositionInStream; //导入依赖的package包/类
@Test
public void testKclConfigs() {
  Map<String, String> kv = new HashMap<>();
  String system = "kinesis";
  String stream = "kinesis-stream";
  String systemConfigPrefix = String.format("systems.%s.", system);

  // region config is required for setting kcl config.
  kv.put(systemConfigPrefix + "aws.region", "us-east-1");

  // Kcl Configs
  kv.put(systemConfigPrefix + "aws.kcl.TableName", "sample-table");
  kv.put(systemConfigPrefix + "aws.kcl.MaxRecords", "100");
  kv.put(systemConfigPrefix + "aws.kcl.CallProcessRecordsEvenForEmptyRecordList", "true");
  kv.put(systemConfigPrefix + "aws.kcl.InitialPositionInStream", "TRIM_HORIZON");
  // override one of the Kcl configs for kinesis-stream1
  kv.put(systemConfigPrefix + "streams.kinesis-stream1.aws.kcl.InitialPositionInStream", "LATEST");

  Config config = new MapConfig(kv);
  KinesisConfig kConfig = new KinesisConfig(config);
  KinesisClientLibConfiguration kclConfig = kConfig.getKinesisClientLibConfig(system, stream, "sample-app");

  assertEquals("sample-table", kclConfig.getTableName());
  assertEquals(100, kclConfig.getMaxRecords());
  assertTrue(kclConfig.shouldCallProcessRecordsEvenForEmptyRecordList());
  assertEquals(InitialPositionInStream.TRIM_HORIZON, kclConfig.getInitialPositionInStream());

  // verify if the overriden config is applied for kinesis-stream1
  kclConfig = kConfig.getKinesisClientLibConfig(system, "kinesis-stream1", "sample-app");
  assertEquals(InitialPositionInStream.LATEST, kclConfig.getInitialPositionInStream());
}
 
开发者ID:apache,项目名称:samza,代码行数:32,代码来源:TestKinesisConfig.java

示例12: KinesisEventConsumer

import com.amazonaws.services.kinesis.clientlibrary.lib.worker.InitialPositionInStream; //导入依赖的package包/类
public KinesisEventConsumer(String propertiesFile, String streamName, String appName, String initialPosition) {
    KinesisProducerConfiguration config = KinesisProducerConfiguration.fromPropertiesFile(propertiesFile);

    InitialPositionInStream position = InitialPositionInStream.valueOf(initialPosition);
    
    KinesisClientLibConfiguration clientConfig = new KinesisClientLibConfiguration(appName, streamName,
            new DefaultAWSCredentialsProviderChain(), appName)
                    .withRegionName(config.getRegion())
                    .withInitialPositionInStream(position);
    
    this.builder = new Worker.Builder().recordProcessorFactory(this).config(clientConfig);
}
 
开发者ID:monetate,项目名称:koupler,代码行数:13,代码来源:KinesisEventConsumer.java

示例13: createKinesisWorker

import com.amazonaws.services.kinesis.clientlibrary.lib.worker.InitialPositionInStream; //导入依赖的package包/类
private Worker createKinesisWorker(IRecordProcessorFactory recordProcessorFactory, int maxBatchSize) {
  KinesisClientLibConfiguration kclConfig =
      new KinesisClientLibConfiguration(
          conf.applicationName,
          conf.streamName,
          credentials,
          getWorkerId()
      );

  kclConfig
      .withMaxRecords(maxBatchSize)
      .withCallProcessRecordsEvenForEmptyRecordList(false)
      .withIdleTimeBetweenReadsInMillis(conf.idleTimeBetweenReads)
      .withInitialPositionInStream(conf.initialPositionInStream)
      .withKinesisClientConfig(clientConfiguration);

  if (conf.initialPositionInStream == InitialPositionInStream.AT_TIMESTAMP) {
    kclConfig.withTimestampAtInitialPositionInStream(new Date(conf.initialTimestamp));
  }

  if (conf.region == AWSRegions.OTHER) {
    kclConfig.withKinesisEndpoint(conf.endpoint);
  } else {
    kclConfig.withRegionName(conf.region.getLabel());
  }

  return new Worker.Builder()
      .recordProcessorFactory(recordProcessorFactory)
      .metricsFactory(metricsFactory)
      .dynamoDBClient(dynamoDBClient)
      .cloudWatchClient(cloudWatchClient)
      .execService(executor)
      .config(kclConfig)
      .build();
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:36,代码来源:KinesisSource.java

示例14: convertToPosition

import com.amazonaws.services.kinesis.clientlibrary.lib.worker.InitialPositionInStream; //导入依赖的package包/类
private InitialPositionInStream convertToPosition(KinesisInputProperties.OffsetType offsetType) {
    switch (offsetType) {
    case LATEST:
        return InitialPositionInStream.LATEST;
    case EARLIEST:
        return InitialPositionInStream.TRIM_HORIZON;
    default:
        TalendRuntimeException.build(CommonErrorCodes.UNEXPECTED_ARGUMENT).setAndThrow(
                String.format("Do not support OffsetType %s", offsetType));
        return null;
    }
}
 
开发者ID:Talend,项目名称:components,代码行数:13,代码来源:KinesisInputRuntime.java

示例15: loadProperties

import com.amazonaws.services.kinesis.clientlibrary.lib.worker.InitialPositionInStream; //导入依赖的package包/类
/**
 * @param propertiesFile
 * @throws IOException Thrown when we run into issues reading properties
 */
private static void loadProperties(String propertiesFile) throws IOException {
    FileInputStream inputStream = new FileInputStream(propertiesFile);
    Properties properties = new Properties();
    try {
        properties.load(inputStream);
    } finally {
        inputStream.close();
    }
    
    String appNameOverride = properties.getProperty(ConfigKeys.APPLICATION_NAME_KEY);
    if (appNameOverride != null) {
        applicationName = appNameOverride;
    }
    LOG.info("Using application name " + applicationName);
    
    String streamNameOverride = properties.getProperty(ConfigKeys.STREAM_NAME_KEY);
    if (streamNameOverride != null) {
        streamName = streamNameOverride;
    }
    LOG.info("Using stream name " + streamName);
    
    String kinesisEndpointOverride = properties.getProperty(ConfigKeys.KINESIS_ENDPOINT_KEY);
    if (kinesisEndpointOverride != null) {
        kinesisEndpoint = kinesisEndpointOverride;
    }
    String initialPositionOverride = properties.getProperty(ConfigKeys.INITIAL_POSITION_IN_STREAM_KEY);
    if (initialPositionOverride != null) {
         initialPositionInStream = InitialPositionInStream.valueOf(initialPositionOverride);
    }
     LOG.info("Using initial position " + initialPositionInStream.toString() + " (if a checkpoint is not found).");
}
 
开发者ID:dselman,项目名称:tweetamo,代码行数:36,代码来源:TweetamoServer.java


注:本文中的com.amazonaws.services.kinesis.clientlibrary.lib.worker.InitialPositionInStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。