Java Code Examples for com.amazonaws.services.lambda.runtime.events.KinesisEvent#setRecords()
The following examples show how to use
com.amazonaws.services.lambda.runtime.events.KinesisEvent#setRecords() .
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: TestUtils.java From bender with Apache License 2.0 | 5 votes |
public static KinesisEvent createEvent(Class clazz, String resource, String eventSourceArn) throws IOException { /* * Create a kinesis record from a sample JSON file */ String json = IOUtils.toString(new InputStreamReader(clazz.getResourceAsStream(resource), "UTF-8")); Date approximateArrivalTimestamp = new Date(); approximateArrivalTimestamp.setTime(1478737790000l); Record rec = new Record(); rec.withPartitionKey("1").withSequenceNumber("2").withData(ByteBuffer.wrap(json.getBytes())) .withApproximateArrivalTimestamp(approximateArrivalTimestamp); /* * Create a KinesisEventRecord and add single Record */ KinesisEventRecord krecord = new KinesisEventRecord(); krecord.setKinesis(rec); krecord.setEventSourceARN(eventSourceArn); krecord.setEventID("shardId-000000000000:1234"); /* * Add single KinesisEventRecord to a KinesisEvent */ KinesisEvent kevent = new KinesisEvent(); List<KinesisEventRecord> events = new ArrayList<KinesisEventRecord>(1); events.add(krecord); kevent.setRecords(events); return kevent; }
Example 2
Source File: SpringBootKinesisEventHandlerTests.java From spring-cloud-function with Apache License 2.0 | 5 votes |
private static KinesisEvent asAggregatedKinesisEvent(List<?> payloads) { RecordAggregator aggregator = new RecordAggregator(); payloads.stream().map(SpringBootKinesisEventHandlerTests::asJsonByteBuffer) .forEach(buffer -> { try { aggregator.addUserRecord("fakePartitionKey", buffer.array()); } catch (Exception e) { fail("Creating aggregated record failed"); } }); AggRecord aggRecord = aggregator.clearAndGet(); KinesisEvent.Record record = new KinesisEvent.Record(); record.setData(ByteBuffer.wrap(aggRecord.toRecordBytes())); KinesisEvent.KinesisEventRecord wrappingRecord = new KinesisEvent.KinesisEventRecord(); wrappingRecord.setKinesis(record); wrappingRecord.setEventVersion("1.0"); KinesisEvent event = new KinesisEvent(); event.setRecords(singletonList(wrappingRecord)); return event; }
Example 3
Source File: SpringBootKinesisEventHandlerTests.java From spring-cloud-function with Apache License 2.0 | 4 votes |
private static KinesisEvent asKinesisEvent(List<Object> payloads) { KinesisEvent kinesisEvent = new KinesisEvent(); List<KinesisEvent.KinesisEventRecord> kinesisEventRecords = new ArrayList<>(); for (Object payload : payloads) { KinesisEvent.Record record = new KinesisEvent.Record(); record.setData(asJsonByteBuffer(payload)); KinesisEvent.KinesisEventRecord kinesisEventRecord = new KinesisEvent.KinesisEventRecord(); kinesisEventRecord.setKinesis(record); kinesisEventRecords.add(kinesisEventRecord); } kinesisEvent.setRecords(kinesisEventRecords); return kinesisEvent; }