Interface PartitionReceiver

    • Method Detail

      • getPartitionId

        String getPartitionId()
        Get EventHubs partition identifier.
        Returns:
        The identifier representing the partition from which this receiver is fetching data
      • getReceiveTimeout

        Duration getReceiveTimeout()
      • setReceiveTimeout

        void setReceiveTimeout​(Duration value)
      • getIsOpen

        boolean getIsOpen()
        Determine the current state of the receiver.
        Returns:
        false if the receiver is closing or has been closed, true if the receiver is open and ready to use.
      • getEpoch

        long getEpoch()
        Get the epoch value that this receiver is currently using for partition ownership.

        A value of 0 means this receiver is not an epoch-based receiver.

        Returns:
        the epoch value that this receiver is currently using for partition ownership.
      • receive

        CompletableFuture<Iterable<EventData>> receive​(int maxEventCount)
        Receive a batch of EventData's from an EventHub partition

        Sample code (sample uses sync version of the api but concept are identical):

         EventHubClient client = EventHubClient.createSync("__connection__");
         PartitionReceiver receiver = client.createPartitionReceiverSync("ConsumerGroup1", "1");
         Iterable<EventData> receivedEvents = receiver.receiveSync();
        
         while (true)
         {
             int batchSize = 0;
             if (receivedEvents != null)
             {
                 for(EventData receivedEvent: receivedEvents)
                 {
                     System.out.println(String.format("Message Payload: %s", new String(receivedEvent.getBytes(), Charset.defaultCharset())));
                     System.out.println(String.format("Offset: %s, SeqNo: %s, EnqueueTime: %s",
                         receivedEvent.getSystemProperties().getOffset(),
                         receivedEvent.getSystemProperties().getSequenceNumber(),
                         receivedEvent.getSystemProperties().getEnqueuedTime()));
                     batchSize++;
                 }
             }
        
             System.out.println(String.format("ReceivedBatch Size: %s", batchSize));
             receivedEvents = receiver.receiveSync();
         }
         
        Parameters:
        maxEventCount - maximum number of EventData's that this call should return
        Returns:
        A completableFuture that will yield a batch of EventData's from the partition on which this receiver is created. Returns 'null' if no EventData is present.
      • setReceiveHandler

        CompletableFuture<Void> setReceiveHandler​(PartitionReceiveHandler receiveHandler)
        Register a receive handler that will be called when an event is available. A PartitionReceiveHandler is a handler that allows user to specify a callback for event processing and error handling in a receive pump model.
        Parameters:
        receiveHandler - An implementation of PartitionReceiveHandler. Setting this handler to null will stop the receive pump.
        Returns:
        A completableFuture which sets receiveHandler