You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Service Bus] Use processor in the readme (Azure#17386)
The processor client is what we should share in the getting started scenario and not the sync/async receiver clients. In this PR I have,
- used the processor client to receive messages instead of sync/async receiver clients
- removed the part on renewing locks as this is now done by default. These are remnants from the time when people had to opt in explicitly
- merged settling messages into the processor sample
- removed the session receiver example, put in just a note that it is similar to the non sessions case and listed out differences.
@srnagar I put together this PR in a haste, please make corrections as you see fit. I'd like to see the basic version checked in ASAP and you can make improvements in a different PR
You'll need to create an asynchronous [`ServiceBusReceiverAsyncClient`][ServiceBusReceiverAsyncClient] or a synchronous
175
-
[`ServiceBusReceiverClient`][ServiceBusReceiverClient] to receive messages. Each receiver can consume messages from
176
-
either a queue or a topic subscription.
174
+
To receive messages, you will need to create a `ServiceBusProcessorClient` with callbacks for incoming messages and any error that occurs in the process. You can then start and stop the client as required.
177
175
178
-
By default, the receive mode is [`ReceiveMode.PEEK_LOCK`][ReceiveMode]. This tells the broker that the receiving client
179
-
wants to manage settlement of received messages explicitly. The message is made available for the receiver to process,
180
-
while held under an exclusive lock in the service so that other, competing receivers cannot see it.
181
-
`ServiceBusReceivedMessage.getLockedUntil()` indicates when the lock expires and can be extended by the client using
182
-
`receiver.renewMessageLock()`. A session lock can be extended by `receiver.renewSessionLock()` for a session enabled
183
-
queue or topic/subscriber.
176
+
By default, the `autoComplete` feature is enabled on the processor client which means that after executing your callback for the message, the client will complete the message i.e. remove it from the queue/subscription. If your callback throws an error, then the client will abandon the message i.e. make it available to be received again. You can disable this feature when creating the processor client.
184
177
185
-
#### Receive a batch of messages
186
-
187
-
The snippet below creates a [`ServiceBusReceiverClient`][ServiceBusReceiverClient] to receive messages from a topic
// Starts the processor in the background and returns immediately
206
+
processorClient.start();
259
207
```
260
208
261
-
There are four ways of settling messages:
209
+
There are four ways of settling messages using the methods on the message context passed to your callback.
262
210
- Complete - causes the message to be deleted from the queue or topic.
263
211
- Abandon - releases the receiver's lock on the message allowing for the message to be received by other receivers.
264
212
- Defer - defers the message from being received by normal means. In order to receive deferred messages, the sequence
@@ -298,29 +246,9 @@ sender.sendMessage(message);
298
246
299
247
#### Receive messages from a session
300
248
301
-
Receivers can fetch messages from a specific session or the first available, unlocked session.
249
+
Receiving messages from sessions is similar to receiving messages from a non session enabled queue or subscription. The difference is in the builder and the class you use.
In non-session case, you would use the sub builder `processor()`. In case of sessions, you would use the sub builder `sessionProcessor()`. Both sub builders will create an instance of `ServiceBusProcessorClient` configured to work on a session or a non-session Service Bus entity. In the case of the session processor, you can pass the maximum number of sessions you want the processor to process concurrently as well.
0 commit comments