View Javadoc
1   // Copyright (c) Microsoft Corporation. All rights reserved.
2   // Licensed under the MIT License.
3   
4   package com.microsoft.azure.servicebus;
5   
6   import java.util.Collection;
7   import java.util.concurrent.CompletableFuture;
8   
9   import com.microsoft.azure.servicebus.primitives.ServiceBusException;
10  
11  /**
12   * Represents a message browser that can browse messages from Azure Service Bus.
13   */
14  public interface IMessageBrowser {
15  
16      /**
17       * reads next the active message without changing the state of the receiver or the message source.
18       * The first call to {@link IMessageBrowser#peek()} fetches the first active message for this receiver.
19       * Each subsequent call fetches the subsequent message in the entity.
20       *
21       * @return {@link Message} peeked
22       * @throws InterruptedException if the current thread was interrupted while waiting
23       * @throws ServiceBusException  if peek failed
24       */
25      IMessage peek() throws InterruptedException, ServiceBusException;
26  
27      /**
28       * Reads next the active message without changing the state of the receiver or the message source.
29       *
30       * @param fromSequenceNumber The sequence number from where to read the message.
31       * @return {@link Message} peeked
32       * @throws InterruptedException if the current thread was interrupted while waiting
33       * @throws ServiceBusException  if peek failed
34       */
35      IMessage peek(long fromSequenceNumber) throws InterruptedException, ServiceBusException;
36  
37      /**
38       * Reads next batch of the active messages without changing the state of the receiver or the message source.
39       *
40       * @param messageCount The number of messages.
41       * @return Batch of {@link Message} peeked
42       * @throws InterruptedException if the current thread was interrupted while waiting
43       * @throws ServiceBusException  if peek failed
44       */
45      Collection<IMessage> peekBatch(int messageCount) throws InterruptedException, ServiceBusException;
46  
47      /**
48       * Reads next batch of the active messages without changing the state of the receiver or the message source.
49       *
50       * @param fromSequenceNumber The sequence number from where to read the message.
51       * @param messageCount       The number of messages.
52       * @return Batch of {@link Message} peeked
53       * @throws InterruptedException if the current thread was interrupted while waiting
54       * @throws ServiceBusException  if peek failed
55       */
56      Collection<IMessage> peekBatch(long fromSequenceNumber, int messageCount) throws InterruptedException, ServiceBusException;
57  
58      /**
59       * Asynchronously reads the active messages without changing the state of the receiver or the message source.
60       *
61       * @return {@link Message} peeked
62       */
63      CompletableFuture<IMessage> peekAsync();
64  
65      /**
66       * Asynchronously reads next the active message without changing the state of the receiver or the message source.
67       *
68       * @param fromSequenceNumber The sequence number from where to read the message.
69       * @return CompletableFuture that returns {@link Message} peeked.
70       */
71      CompletableFuture<IMessage> peekAsync(long fromSequenceNumber);
72  
73      /**
74       * Asynchronously reads the next batch of active messages without changing the state of the receiver or the message source.
75       *
76       * @param messageCount The number of messages.
77       * @return CompletableFuture that returns batch of {@link Message} peeked.
78       */
79      CompletableFuture<Collection<IMessage>> peekBatchAsync(int messageCount);
80  
81      /**
82       * Asynchronously reads the next batch of active messages without changing the state of the receiver or the message source.
83       *
84       * @param fromSequenceNumber The sequence number from where to read the message.
85       * @param messageCount       The number of messages.
86       * @return CompletableFuture that returns batch of {@link Message} peeked.
87       */
88      CompletableFuture<Collection<IMessage>> peekBatchAsync(long fromSequenceNumber, int messageCount);
89  }