software.amazon.awssdk.services.kinesis.model.PutRecordResponse Java Examples

The following examples show how to use software.amazon.awssdk.services.kinesis.model.PutRecordResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KinesisIntegrationTests.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
private PutRecordResponse putRecord(final String streamName,
                                  final String data) {

    PutRecordResponse result = client.putRecord(
            PutRecordRequest.builder()
                            .streamName(streamName)
                            .partitionKey("foobar")
                            .data(SdkBytes.fromUtf8String(data))
                            .build());
    Assert.assertNotNull(result);

    Assert.assertNotNull(result.shardId());
    Assert.assertNotNull(result.sequenceNumber());

    return result;
}
 
Example #2
Source File: KinesisIntegrationTests.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
private PutRecordResponse putRecordExplicit(final String streamName,
                                          final String hashKey) {

    PutRecordResponse result = client.putRecord(PutRecordRequest.builder()
                                                              .streamName(streamName)
                                                              .partitionKey("foobar")
                                                              .explicitHashKey(hashKey)
                                                              .data(SdkBytes.fromUtf8String("Speak No Evil"))
                                                              .build());
    Assert.assertNotNull(result);

    Assert.assertNotNull(result.shardId());
    Assert.assertNotNull(result.sequenceNumber());

    return result;
}
 
Example #3
Source File: KinesisIntegrationTests.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
private PutRecordResponse putRecordExplicit(final String streamName,
                                          final String hashKey,
                                          final String minSQN) {

    PutRecordResponse result = client.putRecord(PutRecordRequest.builder()
                                                              .streamName(streamName)
                                                              .partitionKey("foobar")
                                                              .explicitHashKey(hashKey)
                                                              .sequenceNumberForOrdering(minSQN)
                                                              .data(SdkBytes.fromUtf8String("Hear No Evil"))
                                                              .build());
    Assert.assertNotNull(result);

    Assert.assertNotNull(result.shardId());
    Assert.assertNotNull(result.sequenceNumber());

    return result;
}
 
Example #4
Source File: KinesisVerticle.java    From reactive-refarch-cloudformation with Apache License 2.0 5 votes vote down vote up
private void sendMessageToKinesis(byte [] byteMessage, String partitionKey) throws KinesisException {
    if (null == kinesisAsyncClient) {
        throw new KinesisException("AmazonKinesisAsync is not initialized");
    }

    SdkBytes payload = SdkBytes.fromByteArray(byteMessage);
    PutRecordRequest putRecordRequest = PutRecordRequest.builder()
            .partitionKey(partitionKey)
            .streamName(eventStream)
            .data(payload)
            .build();

    LOGGER.info("Writing to streamName " + eventStream + " using partitionkey " + partitionKey);

    try {
        CompletableFuture<PutRecordResponse> future = kinesisAsyncClient.putRecord(putRecordRequest);

        future.whenComplete((result, e) -> vertx.runOnContext(none -> {
            if (e != null) {
                LOGGER.error("Something happened ... 1");
                LOGGER.error(e);
                e.printStackTrace();
            } else {
                String sequenceNumber = result.sequenceNumber();
                LOGGER.debug("Message sequence number: " + sequenceNumber);
            }
        }));
    }
    catch (Exception exc) {
        LOGGER.error("Something happened ... 2");
        exc.printStackTrace();
        LOGGER.error(exc);
    }
}
 
Example #5
Source File: RedisUpdate.java    From reactive-refarch-cloudformation with Apache License 2.0 5 votes vote down vote up
public static void main (String ... args) {

        KinesisAsyncClient kinesisAsync = createClient();

        byte[] msg = prepareData();

        SdkBytes payload = SdkBytes.fromByteArray(msg);
        PutRecordRequest putRecordRequest = PutRecordRequest.builder()
                .partitionKey("test")
                .streamName(kinesisStream)
                .data(payload)
                .build();

        CompletableFuture<PutRecordResponse> future = kinesisAsync.putRecord(putRecordRequest);

        future.whenComplete((result, e) -> {
            if (e != null) {
                System.out.println(e);
            } else {
                String sequenceNumber = result.sequenceNumber();
                System.out.println("Message sequence number: " + sequenceNumber);
            }
        });
    }
 
Example #6
Source File: KinesisStatsReporter.java    From kinesis-logback-appender with Apache License 2.0 5 votes vote down vote up
/**
 * This method is invoked when there is an exception in sending a log record
 * to Kinesis. These logs would end up in the application log if configured
 * properly.
 */
@Override
public final void accept(PutRecordResponse response, Throwable exception) {
  if (exception != null) {
    failedRequestCount++;
    appender.addError("Failed to publish a log entry to kinesis using appender: " + appenderName, exception);
  } else {
    successfulRequestCount++;
  }
}
 
Example #7
Source File: KinesisIntegrationTests.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
private void testPuts(final String streamName, final Shard shard)
        throws InterruptedException {

    // Put a record into the shard.
    System.out.println("Putting two records...");
    PutRecordResponse r1 = putRecord(streamName, "See No Evil");
    Assert.assertEquals(shard.shardId(), r1.shardId());

    // Check that it's sequence number is sane.
    BigInteger startingSQN = new BigInteger(
            shard.sequenceNumberRange().startingSequenceNumber()
    );
    BigInteger sqn1 = new BigInteger(r1.sequenceNumber());
    Assert.assertTrue(sqn1.compareTo(startingSQN) >= 0);

    // Put another record, which should show up later in the same shard.
    PutRecordResponse r2 = putRecord(streamName, "See No Evil");
    Assert.assertEquals(shard.shardId(), r2.shardId());
    BigInteger sqn2 = new BigInteger(r2.sequenceNumber());
    System.out.println("  OK");

    // Not guaranteed an order unless we explicitly ask for one, but
    // it has to at least be larger than the starting sqn.
    Assert.assertTrue(sqn2.compareTo(startingSQN) >= 0);

    // Split the shard in two: [0-1000) and [1000-*]
    System.out.println("Splitting the shard...");
    List<Shard> shards = splitShard(streamName, shard, 1000);
    System.out.println("  OK");

    // Sleep a bit for eventual consistency.
    Thread.sleep(5000);


    // Put records into the two new shards, one after another.
    System.out.println("Putting some more...");
    PutRecordResponse r3 = putRecordExplicit(streamName, "999");
    PutRecordResponse r4 = putRecordExplicit(streamName,
                                           "1000",
                                           r3.sequenceNumber());

    BigInteger sqn3 = new BigInteger(r3.sequenceNumber());
    BigInteger sqn4 = new BigInteger(r4.sequenceNumber());
    Assert.assertTrue(sqn4.compareTo(sqn3) >= 0);
    System.out.println("  OK");

    // Merge the two shards back together.
    System.out.println("Merging the shards back together...");
    mergeShards(streamName,
                shards.get(1).shardId(),
                shards.get(2).shardId());
    System.out.println("  OK");
}