Skip to content

Commit

Permalink
[service-bus] Fixing sample to only recover when .retryable is true (…
Browse files Browse the repository at this point in the history
…ie, "escaped" errors) (Azure#10058)

Fixing sample to only recover when .retryable is true (ie, "escaped" retryable errors).

Still a partial fix for Azure#9958 in that it demonstrates the recovery technique.
  • Loading branch information
richardpark-msft authored Jul 15, 2020
1 parent c9b2f6d commit 3d9ac3b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT Licence.
This sample demonstrates how the receive() function can be used to receive Service Bus messages
This sample demonstrates how the registerMessageHandler() function can be used to receive Service Bus messages
in a stream.
Setup: Please run "sendMessages.ts" sample before running this to populate the queue/topic
*/

const {
OnMessage,
OnError,
ServiceBusClient,
ReceiveMode,
MessagingError
} = require("@azure/service-bus");
const { ServiceBusClient, ReceiveMode } = require("@azure/service-bus");

// Load the .env file if it exists
const dotenv = require("dotenv");
Expand Down Expand Up @@ -46,11 +40,11 @@ async function main() {
};

const onErrorHandler = (err) => {
if (err.retryable === false) {
console.log("Receiver will be recreated. A fatal error occurred:", err);
if (err.retryable === true) {
console.log("Receiver will be recreated. A recoverable error occurred:", err);
resolve();
} else {
console.log("Non-fatal error occurred: ", err);
console.log("Error occurred: ", err);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT Licence.
This sample demonstrates how the receive() function can be used to receive Service Bus messages
This sample demonstrates how the registerMessageHandler() function can be used to receive Service Bus messages
in a stream.
Setup: Please run "sendMessages.ts" sample before running this to populate the queue/topic
Expand Down Expand Up @@ -46,11 +46,11 @@ export async function main() {
};

const onErrorHandler: OnError = (err) => {
if ((err as MessagingError).retryable === false) {
console.log("Receiver will be recreated. A fatal error occurred:", err);
if ((err as MessagingError).retryable === true) {
console.log("Receiver will be recreated. A recoverable error occurred:", err);
resolve();
} else {
console.log("Non-fatal error occurred: ", err);
console.log("Error occurred: ", err);
}
};

Expand Down

0 comments on commit 3d9ac3b

Please sign in to comment.