software.amazon.awssdk.services.kinesis.model.PutRecordRequest Java Examples
The following examples show how to use
software.amazon.awssdk.services.kinesis.model.PutRecordRequest.
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: SubscribeToShardIntegrationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
/** * Puts a random record to the stream. * * @param len The number of bytes to generate for the record. * @return Record data that was put. */ private Optional<SdkBytes> putRecord(int len) { try { SdkBytes data = SdkBytes.fromByteArray(RandomUtils.nextBytes(len)); asyncClient.putRecord(PutRecordRequest.builder() .streamName(streamName) .data(data) .partitionKey(UUID.randomUUID().toString()) .build()) .join(); return Optional.of(data); } catch (Exception e) { e.printStackTrace(); return Optional.empty(); } }
Example #2
Source File: KinesisIntegrationTests.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
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 #3
Source File: KinesisIntegrationTests.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
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 #4
Source File: KinesisIntegrationTests.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
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 #5
Source File: KinesisStabilityTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
private void putRecords() { log.info(() -> "Starting to test putRecord"); producedData = new ArrayList<>(); SdkBytes data = SdkBytes.fromByteArray(RandomUtils.nextBytes(20)); IntFunction<CompletableFuture<?>> futureFunction = i -> asyncClient.putRecord(PutRecordRequest.builder() .streamName(streamName) .data(data) .partitionKey(UUID.randomUUID().toString()) .build()) .thenApply(b -> producedData.add(data)); StabilityTestRunner.newRunner() .requestCountPerRun(CONCURRENCY) .testName("KinesisStabilityTest.putRecords") .futureFactory(futureFunction) .run(); }
Example #6
Source File: StockTradesWriter.java From aws-doc-sdk-examples with Apache License 2.0 | 6 votes |
private static void sendStockTrade(StockTrade trade, KinesisClient kinesisClient, String streamName) { byte[] bytes = trade.toJsonAsBytes(); // The bytes could be null if there is an issue with the JSON serialization by the Jackson JSON library. if (bytes == null) { System.out.println("Could not get JSON bytes for stock trade"); return; } System.out.println("Putting trade: " + trade.toString()); PutRecordRequest request = PutRecordRequest.builder() .partitionKey(trade.getTickerSymbol()) // We use the ticker symbol as the partition key, explained in the Supplemental Information section below. .streamName(streamName) .data(SdkBytes.fromByteArray(bytes)) .build(); try { kinesisClient.putRecord(request); } catch (KinesisException e) { e.getMessage(); } }
Example #7
Source File: KinesisVerticle.java From reactive-refarch-cloudformation with Apache License 2.0 | 5 votes |
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 #8
Source File: RedisUpdate.java From reactive-refarch-cloudformation with Apache License 2.0 | 5 votes |
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); } }); }