Search in sources :

Example 16 with SubscriptionCursor

use of org.zalando.nakadi.view.SubscriptionCursor in project nakadi by zalando.

the class StreamingState method flushData.

private void flushData(final EventTypePartition pk, final List<ConsumedEvent> data, final Optional<String> metadata) {
    try {
        final NakadiCursor sentOffset = offsets.get(pk).getSentOffset();
        final SubscriptionCursor cursor = getContext().getCursorConverter().convert(sentOffset, getContext().getCursorTokenService().generateToken());
        final int batchSize = getContext().getWriter().writeSubscriptionBatch(getOut().getOutputStream(), cursor, data, metadata);
        bytesSentMeterPerSubscription.mark(batchSize);
        final StreamKpiData kpiData = kpiDataPerEventType.get(pk.getEventType());
        kpiData.addBytesSent(batchSize);
        kpiData.addNumberOfEventsSent(data.size());
        batchesSent++;
    } catch (final IOException e) {
        getLog().error("Failed to write data to output.", e);
        shutdownGracefully("Failed to write data to output");
    }
}
Also used : SubscriptionCursor(org.zalando.nakadi.view.SubscriptionCursor) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) IOException(java.io.IOException) StreamKpiData(org.zalando.nakadi.metrics.StreamKpiData)

Aggregations

SubscriptionCursor (org.zalando.nakadi.view.SubscriptionCursor)16 Test (org.junit.Test)14 TestStreamingClient (org.zalando.nakadi.webservice.utils.TestStreamingClient)10 Subscription (org.zalando.nakadi.domain.Subscription)6 NakadiTestUtils.createSubscription (org.zalando.nakadi.webservice.utils.NakadiTestUtils.createSubscription)6 IOException (java.io.IOException)5 List (java.util.List)5 EventType (org.zalando.nakadi.domain.EventType)5 ImmutableList (com.google.common.collect.ImmutableList)4 Collectors (java.util.stream.Collectors)3 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)3 Matchers.hasSize (org.hamcrest.Matchers.hasSize)3 Before (org.junit.Before)3 ItemsWrapper (org.zalando.nakadi.domain.ItemsWrapper)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 JSON (com.jayway.restassured.http.ContentType.JSON)2 Optional (java.util.Optional)2 CoreMatchers.equalTo (org.hamcrest.CoreMatchers.equalTo)2 SubscriptionBase (org.zalando.nakadi.domain.SubscriptionBase)2