Skip to content

Commit 981c24f

Browse files
API changes and batch schedule (Azure#12796)
1 parent 4fa6e57 commit 981c24f

File tree

53 files changed

+1026
-915
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1026
-915
lines changed

sdk/servicebus/Azure.Messaging.ServiceBus/MigrationGuide.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,27 +63,27 @@ In the interest of simplifying the API surface we've made a single top level cli
6363

6464
### Sending messages
6565

66-
The v4 client allowed for sending a single message or a list of messages, which had the potential to fail unexpectedly if the maximum allowable size was exceeded. v7 aims to prevent this by asking that you first create a batch of messages using `CreateBatchAsync` and then attempt to add messages to that using `TryAdd()`. If the batch accepts a message, you can be confident that it will not violate size constraints when calling Send to send the batch. v7 still allows sending a single message.
66+
The v4 client allowed for sending a single message or a list of messages, which had the potential to fail unexpectedly if the maximum allowable size was exceeded. v7 aims to prevent this by allowing you to first create a batch of messages using `CreateMessageBatchAsync` and then attempt to add messages to that using `TryAddMessage()`. If the batch accepts a message, you can be confident that it will not violate size constraints when calling Send to send the batch. v7 still allows sending a single message and sending an `IEnumerable` of messages, though using the `IEnumerable` overload has the same risks as V4.
6767

6868
| In v4 | Equivalent in v7 | Sample |
6969
|------------------------------------------------|------------------------------------------------------------------|--------|
70-
| `QueueClient.SendAsync(Message)` or `MessageSender.SendAsync(Message)` | `ServiceBusSender.SendAsync(ServiceBusMessage)` | [Send a message](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/servicebus/Azure.Messaging.ServiceBus/samples/Sample01_HelloWorld.md#sending-and-receiving-a-message) |
71-
| `QueueClient.SendAsync(IList<Message>)` or `MessageSender.SendAsync(IList<Message>)` | `messageBatch = ServiceBusSender.CreateBatchAsync()` `messageBatch.TryAdd(ServiceBusMessage)` `ServiceBusSender.SendAsync(messageBatch)` | [Send a batch of messages](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/servicebus/Azure.Messaging.ServiceBus/samples/Sample01_HelloWorld.md#sending-and-receiving-a-batch-of-messages) |
70+
| `QueueClient.SendAsync(Message)` or `MessageSender.SendAsync(Message)` | `ServiceBusSender.SendMessageAsync(ServiceBusMessage)` | [Send a message](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/servicebus/Azure.Messaging.ServiceBus/samples/Sample01_HelloWorld.md#sending-and-receiving-a-message) |
71+
| `QueueClient.SendAsync(IList<Message>)` or `MessageSender.SendAsync(IList<Message>)` | `messageBatch = ServiceBusSender.CreateMessageBatchAsync()` `messageBatch.TryAddMessage(ServiceBusMessage)` `ServiceBusSender.SendMessagesAsync(messageBatch)` or `ServiceBusSender.SendMessagesAsync(IEnumerable<ServiceBusMessage>)` | [Send a batch of messages](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/servicebus/Azure.Messaging.ServiceBus/samples/Sample01_HelloWorld.md#sending-and-receiving-a-batch-of-messages) |
7272

7373
### Receiving messages
7474

7575
| In v4 | Equivalent in v7 | Sample |
7676
|------------------------------------------------|------------------------------------------------------------------|--------|
77-
| `MessageReceiver.ReceiveAsync()` | `ServiceBusReceiver.ReceiveAsync()` | [Receive a message](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/servicebus/Azure.Messaging.ServiceBus/samples/Sample01_HelloWorld.md#sending-and-receiving-a-message) |
78-
| `MessageReceiver.ReceiveAsync()` | `ServiceBusReceiver.ReceiveBatchAsync()` | [Receive a batch of messages](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/servicebus/Azure.Messaging.ServiceBus/samples/Sample01_HelloWorld.md#sending-and-receiving-a-batch-of-messages) |
77+
| `MessageReceiver.ReceiveAsync()` | `ServiceBusReceiver.ReceiveMessageAsync()` | [Receive a message](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/servicebus/Azure.Messaging.ServiceBus/samples/Sample01_HelloWorld.md#sending-and-receiving-a-message) |
78+
| `MessageReceiver.ReceiveAsync()` | `ServiceBusReceiver.ReceiveMessagesAsync()` | [Receive a batch of messages](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/servicebus/Azure.Messaging.ServiceBus/samples/Sample01_HelloWorld.md#sending-and-receiving-a-batch-of-messages) |
7979
| `QueueClient.RegisterMessageHandler()` or `MessageReceiver.RegisterMessageHandler()` | `ServiceBusProcessor.ProcessMessageAsync += MessageHandler` `ServiceBusProcessor.ProcessErrorAsync += ErrorHandler` `ServiceBusProcessor.StartProcessingAsync()` | [Receive messages using processor](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/servicebus/Azure.Messaging.ServiceBus/samples/Sample04_Processor.md) |
8080

8181
### Working with sessions
8282

8383
| In v4 | Equivalent in v7 | Sample |
8484
|------------------------------------------------|------------------------------------------------------------------|--------|
85-
| `MessageSender.SendAsync(new Message{SessionId = "sessionId"})` | `ServiceBusSender.SendAsync(new ServiceBusMessage{SessionId = "sessionId"})` | [Send a message to session](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/servicebus/Azure.Messaging.ServiceBus/samples/Sample03_SendReceiveSessions.md) |
86-
| `IMessageSession.ReceiveAsync()` | `ServiceBusSessionReceiver.ReceiveAsync()` | [Receive a message from session](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/servicebus/Azure.Messaging.ServiceBus/samples/Sample03_SendReceiveSessions.md) |
85+
| `MessageSender.SendAsync(new Message{SessionId = "sessionId"})` | `ServiceBusSender.SendMessageAsync(new ServiceBusMessage{SessionId = "sessionId"})` | [Send a message to session](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/servicebus/Azure.Messaging.ServiceBus/samples/Sample03_SendReceiveSessions.md) |
86+
| `IMessageSession.ReceiveAsync()` | `ServiceBusSessionReceiver.ReceiveMessageAsync()` | [Receive a message from session](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/servicebus/Azure.Messaging.ServiceBus/samples/Sample03_SendReceiveSessions.md) |
8787
| `IMessageSession.RegisterMessageHandler()` | `ServiceBusSessionProcessor.ProcessMessageAsync += MessageHandler` `ServiceBusSessionProcessor.ProcessErrorAsync += ErrorHandler` `ServiceBusSessionProcessor.StartProcessingAsync()` | [Receive messages from session processor](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/servicebus/Azure.Messaging.ServiceBus/samples/Sample05_SessionProcessor.md) |
8888

8989
## Migration samples
@@ -92,7 +92,7 @@ The v4 client allowed for sending a single message or a list of messages, which
9292

9393
In v4, `QueueClient`/`MessageSender`/`MessageReceiver` would be created directly, after which user would call `SendAsync()` method via `QueueClient`/`MessageSender` to send a message and `ReceiveAsync()` method via `MessageReceiver` to receive a message.
9494

95-
In v7, user would initialize the `ServiceBusClient` and call `CreateSender()` method to create a `ServiceBusSender` and `CreateReceiver()` method to create a `ServiceBusReceiver`. To send a message, user would call `SendAsync()` via `ServiceBusSender` and to receive a message, user would call `ReceiveAsync()` via `ServiceBusReceiver`.
95+
In v7, user would initialize the `ServiceBusClient` and call `CreateSender()` method to create a `ServiceBusSender` and `CreateReceiver()` method to create a `ServiceBusReceiver`. To send a message, user would call `SendMessageAsync()` via `ServiceBusSender` and to receive a message, user would call `ReceiveMessageAsync()` via `ServiceBusReceiver`.
9696

9797
In v4:
9898

@@ -140,13 +140,13 @@ ServiceBusSender sender = client.CreateSender(queueName);
140140
ServiceBusMessage message = new ServiceBusMessage(Encoding.UTF8.GetBytes("Hello world!"));
141141

142142
// send the message
143-
await sender.SendAsync(message);
143+
await sender.SendMessageAsync(message);
144144

145145
// create a receiver that we can use to receive the message
146146
ServiceBusReceiver receiver = client.CreateReceiver(queueName);
147147

148148
// the received message is a different type as it contains some service set properties
149-
ServiceBusReceivedMessage receivedMessage = await receiver.ReceiveAsync();
149+
ServiceBusReceivedMessage receivedMessage = await receiver.ReceiveMessageAsync();
150150

151151
// get the message body as a string
152152
string body = receivedMessage.Body.ToString();
@@ -160,15 +160,15 @@ In v4, `QueueClient`/`MessageSender`/`MessageReceiver` would be created directly
160160
In v7, user would initialize the `ServiceBusClient` and call `CreateSender()` method to create a `ServiceBusSender` and
161161
`CreateReceiver()` method to create a `ServiceBusReceiver`. There are two ways of sending several messages at once.
162162

163-
The first way uses the `SendAsync`overload that accepts an IEnumerable of `ServiceBusMessage`. With this method, we will
163+
The first way uses the `SendMessagesAsync`overload that accepts an IEnumerable of `ServiceBusMessage`. With this method, we will
164164
attempt to fit all of the supplied messages in a single message batch that we will send to the service. If the messages are
165165
too large to fit in a single batch, the operation will throw an exception.
166166

167167
The second way of doing this is using safe-batching. With safe-batching, you can create a `ServiceBusMessageBatch` object,
168-
which will allow you to attempt to add messages one at a time to the batch using the `TryAdd` method. If the message cannot
169-
fit in the batch, `TryAdd` will return false. If the `ServiceBusMessageBatch` accepts a message, user can be confident that
170-
it will not violate size constraints when calling `SendAsync()` via `ServiceBusSender`. To receive a batch of messages,
171-
user would call `ReceiveBatchAsync()` method via `ServiceBusReceiver`.
168+
which will allow you to attempt to add messages one at a time to the batch using the `TryAddMessage` method. If the message cannot
169+
fit in the batch, `TryAddMessage` will return false. If the `ServiceBusMessageBatch` accepts a message, user can be confident that
170+
it will not violate size constraints when calling `SendMessagesAsync()` via `ServiceBusSender`. To receive a set of messages, a
171+
user would call `ReceiveMessagesAsync()` method via `ServiceBusReceiver`.
172172

173173
In v4:
174174

@@ -223,18 +223,18 @@ IList<ServiceBusMessage> messages = new List<ServiceBusMessage>();
223223
messages.Add(new ServiceBusMessage(Encoding.UTF8.GetBytes("First")));
224224
messages.Add(new ServiceBusMessage(Encoding.UTF8.GetBytes("Second")));
225225
// send the messages
226-
await sender.SendAsync(messages);
226+
await sender.SendMessagesAsync(messages);
227227
```
228228

229229
Or using the safe-batching feature:
230230

231231
```C# Snippet:ServiceBusSendAndReceiveSafeBatch
232-
ServiceBusMessageBatch messageBatch = await sender.CreateBatchAsync();
233-
messageBatch.TryAdd(new ServiceBusMessage(Encoding.UTF8.GetBytes("First")));
234-
messageBatch.TryAdd(new ServiceBusMessage(Encoding.UTF8.GetBytes("Second")));
232+
ServiceBusMessageBatch messageBatch = await sender.CreateMessageBatchAsync();
233+
messageBatch.TryAddMessage(new ServiceBusMessage(Encoding.UTF8.GetBytes("First")));
234+
messageBatch.TryAddMessage(new ServiceBusMessage(Encoding.UTF8.GetBytes("Second")));
235235

236236
// send the message batch
237-
await sender.SendAsync(messageBatch);
237+
await sender.SendMessagesAsync(messageBatch);
238238
```
239239

240240
And to receive a batch:
@@ -243,7 +243,7 @@ And to receive a batch:
243243
ServiceBusReceiver receiver = client.CreateReceiver(queueName);
244244

245245
// the received message is a different type as it contains some service set properties
246-
IList<ServiceBusReceivedMessage> receivedMessages = await receiver.ReceiveBatchAsync(maxMessages: 2);
246+
IList<ServiceBusReceivedMessage> receivedMessages = await receiver.ReceiveMessagesAsync(maxMessages: 2);
247247

248248
foreach (ServiceBusReceivedMessage receivedMessage in receivedMessages)
249249
{

sdk/servicebus/Azure.Messaging.ServiceBus/README.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ ServiceBusSender sender = client.CreateSender(queueName);
116116
ServiceBusMessage message = new ServiceBusMessage(Encoding.UTF8.GetBytes("Hello world!"));
117117

118118
// send the message
119-
await sender.SendAsync(message);
119+
await sender.SendMessageAsync(message);
120120

121121
// create a receiver that we can use to receive the message
122122
ServiceBusReceiver receiver = client.CreateReceiver(queueName);
123123

124124
// the received message is a different type as it contains some service set properties
125-
ServiceBusReceivedMessage receivedMessage = await receiver.ReceiveAsync();
125+
ServiceBusReceivedMessage receivedMessage = await receiver.ReceiveMessageAsync();
126126

127127
// get the message body as a string
128128
string body = receivedMessage.Body.ToString();
@@ -131,7 +131,7 @@ Console.WriteLine(body);
131131

132132
### Send and receive a batch of messages
133133

134-
There are two ways of sending several messages at once. The first way uses the `SendAsync`
134+
There are two ways of sending several messages at once. The first way uses the `SendMessagesAsync`
135135
overload that accepts an IEnumerable of `ServiceBusMessage`. With this method, we will attempt to fit all of
136136
the supplied messages in a single message batch that we will send to the service. If the messages are too large
137137
to fit in a single batch, the operation will throw an exception.
@@ -141,19 +141,19 @@ IList<ServiceBusMessage> messages = new List<ServiceBusMessage>();
141141
messages.Add(new ServiceBusMessage(Encoding.UTF8.GetBytes("First")));
142142
messages.Add(new ServiceBusMessage(Encoding.UTF8.GetBytes("Second")));
143143
// send the messages
144-
await sender.SendAsync(messages);
144+
await sender.SendMessagesAsync(messages);
145145
```
146146
The second way of doing this is using safe-batching. With safe-batching, you can create a
147147
`ServiceBusMessageBatch` object, which will allow you to attempt to add messages one at a time to the
148148
batch using the `TryAdd` method. If the message cannot fit in the batch, `TryAdd` will return false.
149149

150150
```C# Snippet:ServiceBusSendAndReceiveSafeBatch
151-
ServiceBusMessageBatch messageBatch = await sender.CreateBatchAsync();
152-
messageBatch.TryAdd(new ServiceBusMessage(Encoding.UTF8.GetBytes("First")));
153-
messageBatch.TryAdd(new ServiceBusMessage(Encoding.UTF8.GetBytes("Second")));
151+
ServiceBusMessageBatch messageBatch = await sender.CreateMessageBatchAsync();
152+
messageBatch.TryAddMessage(new ServiceBusMessage(Encoding.UTF8.GetBytes("First")));
153+
messageBatch.TryAddMessage(new ServiceBusMessage(Encoding.UTF8.GetBytes("Second")));
154154

155155
// send the message batch
156-
await sender.SendAsync(messageBatch);
156+
await sender.SendMessagesAsync(messageBatch);
157157
```
158158

159159
### Complete a message
@@ -173,41 +173,41 @@ ServiceBusSender sender = client.CreateSender(queueName);
173173
ServiceBusMessage message = new ServiceBusMessage(Encoding.UTF8.GetBytes("Hello world!"));
174174

175175
// send the message
176-
await sender.SendAsync(message);
176+
await sender.SendMessageAsync(message);
177177

178178
// create a receiver that we can use to receive and settle the message
179179
ServiceBusReceiver receiver = client.CreateReceiver(queueName);
180180

181181
// the received message is a different type as it contains some service set properties
182-
ServiceBusReceivedMessage receivedMessage = await receiver.ReceiveAsync();
182+
ServiceBusReceivedMessage receivedMessage = await receiver.ReceiveMessageAsync();
183183

184184
// complete the message, thereby deleting it from the service
185-
await receiver.CompleteAsync(receivedMessage);
185+
await receiver.CompleteMessageAsync(receivedMessage);
186186
```
187187

188188
### Abandon a message
189189

190190
Abandoning a message releases our receiver's lock, which allows the message to be received by this or other receivers.
191191

192192
```C# Snippet:ServiceBusAbandonMessage
193-
ServiceBusReceivedMessage receivedMessage = await receiver.ReceiveAsync();
193+
ServiceBusReceivedMessage receivedMessage = await receiver.ReceiveMessageAsync();
194194

195195
// abandon the message, thereby releasing the lock and allowing it to be received again by this or other receivers
196-
await receiver.AbandonAsync(receivedMessage);
196+
await receiver.AbandonMessageAsync(receivedMessage);
197197
```
198198

199199
### Defer a message
200200

201-
Deferring a message will prevent it from being received again using the `ReceiveAsync` or `ReceiveBatchAsync` methods.
202-
Instead, there are separate methods, `ReceiveDeferredMessageAsync` and `ReceiveDeferredMessageBatchAsync`
201+
Deferring a message will prevent it from being received again using the `ReceiveMessageAsync` or `ReceiveMessagesAsync` methods.
202+
Instead, there are separate methods, `ReceiveDeferredMessageAsync` and `ReceiveDeferredMessagesAsync`
203203
for receiving deferred messages.
204204

205205
```C# Snippet:ServiceBusDeferMessage
206-
ServiceBusReceivedMessage receivedMessage = await receiver.ReceiveAsync();
206+
ServiceBusReceivedMessage receivedMessage = await receiver.ReceiveMessageAsync();
207207

208208
// defer the message, thereby preventing the message from being received again without using
209209
// the received deferred message API.
210-
await receiver.DeferAsync(receivedMessage);
210+
await receiver.DeferMessageAsync(receivedMessage);
211211

212212
// receive the deferred message by specifying the service set sequence number of the original
213213
// received message
@@ -221,14 +221,14 @@ by the service after they have been received a certain number of times. Applicat
221221
their requirements. When a message is dead lettered it is actually moved to a subqueue of the original queue.
222222

223223
```C# Snippet:ServiceBusDeadLetterMessage
224-
ServiceBusReceivedMessage receivedMessage = await receiver.ReceiveAsync();
224+
ServiceBusReceivedMessage receivedMessage = await receiver.ReceiveMessageAsync();
225225

226226
// deadletter the message, thereby preventing the message from being received again without receiving from the dead letter queue.
227-
await receiver.DeadLetterAsync(receivedMessage);
227+
await receiver.DeadLetterMessageAsync(receivedMessage);
228228

229229
// receive the dead lettered message with receiver scoped to the dead letter queue.
230230
ServiceBusReceiver dlqReceiver = client.CreateDeadLetterReceiver(queueName);
231-
ServiceBusReceivedMessage dlqMessage = await dlqReceiver.ReceiveAsync();
231+
ServiceBusReceivedMessage dlqMessage = await dlqReceiver.ReceiveMessageAsync();
232232
```
233233

234234
### Using the Processor
@@ -249,12 +249,12 @@ await using var client = new ServiceBusClient(connectionString);
249249
ServiceBusSender sender = client.CreateSender(queueName);
250250

251251
// create a message batch that we can send
252-
ServiceBusMessageBatch messageBatch = await sender.CreateBatchAsync();
253-
messageBatch.TryAdd(new ServiceBusMessage(Encoding.UTF8.GetBytes("First")));
254-
messageBatch.TryAdd(new ServiceBusMessage(Encoding.UTF8.GetBytes("Second")));
252+
ServiceBusMessageBatch messageBatch = await sender.CreateMessageBatchAsync();
253+
messageBatch.TryAddMessage(new ServiceBusMessage(Encoding.UTF8.GetBytes("First")));
254+
messageBatch.TryAddMessage(new ServiceBusMessage(Encoding.UTF8.GetBytes("Second")));
255255

256256
// send the message batch
257-
await sender.SendAsync(messageBatch);
257+
await sender.SendMessagesAsync(messageBatch);
258258

259259
// get the options to use for configuring the processor
260260
var options = new ServiceBusProcessorOptions

0 commit comments

Comments
 (0)