Class KafkaSender

  • All Implemented Interfaces:
    Closeable, AutoCloseable, zipkin2.reporter.BytesMessageSender

    public final class KafkaSender
    extends zipkin2.reporter.Sender
    This sends (usually json v2) encoded spans to a Kafka topic.

    Usage

    This type is designed for the async reporter.

    Here's a simple configuration, configured for json:

    
     sender = KafkaSender.create("localhost:9092");
     

    Here's an example that overrides properties and protocol buffers encoding:

    
     Properties overrides = new Properties();
     overrides.put(ProducerConfig.MAX_BLOCK_MS_CONFIG, 5000);
     sender = KafkaSender.newBuilder()
       .bootstrapServers("host1:9092,host2:9092")
       .overrides(overrides)
       .encoding(Encoding.PROTO3)
       .build();
     

    Compatibility with Zipkin Server

    Zipkin server should be v1.26 or higher.

    Implementation Notes

    This sender is thread-safe. This sender is linked against Kafka 0.10.2+, which allows it to work with Kafka 0.10+ brokers

    • Method Detail

      • create

        public static KafkaSender create​(String bootstrapServers)
        Creates a sender that sends Encoding.JSON messages.
      • messageSizeInBytes

        public int messageSizeInBytes​(List<byte[]> encodedSpans)
      • messageSizeInBytes

        public int messageSizeInBytes​(int encodedSizeInBytes)
        Specified by:
        messageSizeInBytes in interface zipkin2.reporter.BytesMessageSender
        Overrides:
        messageSizeInBytes in class zipkin2.reporter.Sender
      • encoding

        public zipkin2.reporter.Encoding encoding()
      • messageMaxBytes

        public int messageMaxBytes()
      • sendSpans

        @Deprecated
        public zipkin2.reporter.Call<Void> sendSpans​(List<byte[]> encodedSpans)
        Deprecated.
        Specified by:
        sendSpans in class zipkin2.reporter.Sender
      • send

        public void send​(List<byte[]> encodedSpans)
        This sends all the spans as a single message.

        NOTE: this blocks until the metadata server is available.

        Specified by:
        send in interface zipkin2.reporter.BytesMessageSender
        Overrides:
        send in class zipkin2.reporter.Sender
      • check

        @Deprecated
        public zipkin2.reporter.CheckResult check()
        Deprecated.
        Overrides:
        check in class zipkin2.reporter.Component
      • close

        public void close()
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable
        Overrides:
        close in class zipkin2.reporter.Component