-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Service Bus] Allow timeout lesser than 60 seconds #8805
Changes from 11 commits
21be5a1
9b84b74
773b838
13f41dc
c9f425e
d9b7c9a
71285b0
aecb21c
048e928
ac9aa26
d57b3d3
1d96971
afc003b
3195fda
d871475
ccb6a4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
// Licensed under the MIT license. | ||
|
||
import { generate_uuid } from "rhea-promise"; | ||
import { isTokenCredential, TokenCredential } from "@azure/core-amqp"; | ||
import { isTokenCredential, TokenCredential, Constants } from "@azure/core-amqp"; | ||
import { | ||
ServiceBusClientOptions, | ||
createConnectionContextForTokenCredential, | ||
|
@@ -15,7 +15,6 @@ import { CreateSessionReceiverOptions, CreateSenderOptions } from "./models"; | |
import { Receiver, ReceiverImpl } from "./receivers/receiver"; | ||
import { SessionReceiver, SessionReceiverImpl } from "./receivers/sessionReceiver"; | ||
import { ReceivedMessageWithLock, ReceivedMessage } from "./serviceBusMessage"; | ||
import { getRetryAttemptTimeoutInMs } from "./util/utils"; | ||
|
||
/** | ||
* A client that can create Sender instances for sending messages to queues and | ||
|
@@ -81,9 +80,13 @@ export class ServiceBusClient { | |
} | ||
this.fullyQualifiedNamespace = this._connectionContext.config.host; | ||
this._clientOptions.retryOptions = this._clientOptions.retryOptions || {}; | ||
this._clientOptions.retryOptions.timeoutInMs = getRetryAttemptTimeoutInMs( | ||
this._clientOptions.retryOptions | ||
); | ||
|
||
let timeoutInMs = this._clientOptions.retryOptions.timeoutInMs; | ||
HarshaNalluru marked this conversation as resolved.
Show resolved
Hide resolved
|
||
timeoutInMs = timeoutInMs == undefined ? Constants.defaultOperationTimeoutInMs : timeoutInMs; | ||
if (typeof timeoutInMs !== "number" || !isFinite(timeoutInMs) || timeoutInMs <= 0) { | ||
throw new Error(`${timeoutInMs} is an invalid value for retryOptions.timeoutInMs`); | ||
} | ||
this._clientOptions.retryOptions.timeoutInMs = timeoutInMs; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have to set the timeout to the default value here? This forces us to use Since the interface allows the timeout to not be set at all, I would suggest that we only do the error check here and copy over the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated messageSender with this, the other methods already have this. And thus avoided There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, now that all consumers of retry options will check for undefined and fallback to the default value, do you need the above where you set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, if the timeout is undefined, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then add the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done!! |
||
} | ||
|
||
/** | ||
|
@@ -98,7 +101,7 @@ export class ServiceBusClient { | |
* | ||
* You can settle a message by calling complete(), abandon(), defer() or deadletter() methods on | ||
* the message. | ||
* | ||
* | ||
* More information about how peekLock and message settlement works here: | ||
* https://docs.microsoft.com/en-us/azure/service-bus-messaging/message-transfers-locks-settlement#peeklock | ||
* | ||
|
@@ -127,7 +130,7 @@ export class ServiceBusClient { | |
* | ||
* You can settle a message by calling complete(), abandon(), defer() or deadletter() methods on | ||
* the message. | ||
* | ||
* | ||
* More information about how peekLock and message settlement works here: | ||
* https://docs.microsoft.com/en-us/azure/service-bus-messaging/message-transfers-locks-settlement#peeklock | ||
* | ||
|
@@ -201,7 +204,7 @@ export class ServiceBusClient { | |
* | ||
* You can settle a message by calling complete(), abandon(), defer() or deadletter() methods on | ||
* the message. | ||
* | ||
* | ||
* More information about how peekLock and message settlement works here: | ||
* https://docs.microsoft.com/en-us/azure/service-bus-messaging/message-transfers-locks-settlement#peeklock | ||
* | ||
|
@@ -240,7 +243,7 @@ export class ServiceBusClient { | |
* | ||
* You can settle a message by calling complete(), abandon(), defer() or deadletter() methods on | ||
* the message. | ||
* | ||
* | ||
* More information about how peekLock and message settlement works here: | ||
* https://docs.microsoft.com/en-us/azure/service-bus-messaging/message-transfers-locks-settlement#peeklock | ||
* | ||
|
@@ -352,7 +355,7 @@ export class ServiceBusClient { | |
* | ||
* See here for more information about dead letter queues: | ||
* https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-dead-letter-queues | ||
* | ||
* | ||
* More information about how peekLock and message settlement works here: | ||
* https://docs.microsoft.com/en-us/azure/service-bus-messaging/message-transfers-locks-settlement#peeklock | ||
* | ||
|
@@ -389,7 +392,7 @@ export class ServiceBusClient { | |
* | ||
* See here for more information about dead letter queues: | ||
* https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-dead-letter-queues | ||
* | ||
* | ||
* More information about how peekLock and message settlement works here: | ||
* https://docs.microsoft.com/en-us/azure/service-bus-messaging/message-transfers-locks-settlement#peeklock | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ import { generate_uuid } from "rhea-promise"; | |
import isBuffer from "is-buffer"; | ||
import { Buffer } from "buffer"; | ||
import * as Constants from "../util/constants"; | ||
import { Constants as CoreAMQPConstants, RetryOptions } from "@azure/core-amqp"; | ||
|
||
// This is the only dependency we have on DOM types, so rather than require | ||
// the DOM lib we can just shim this in. | ||
|
@@ -42,47 +41,6 @@ export function getUniqueName(name: string): string { | |
return `${name}-${generate_uuid()}`; | ||
} | ||
|
||
/** | ||
* @internal | ||
* @ignore | ||
* | ||
* TODO: I think this is duplicated from core-amqp and should be du-duped, but _before_ | ||
* that happens we should question whether it's even a legitimate way of setting the timeout | ||
* because it just squashes all timeouts beneath 60 seconds to be 60 seconds instead. | ||
*/ | ||
export function getRetryAttemptTimeoutInMs(retryOptions: RetryOptions | undefined): number { | ||
const timeoutInMs = | ||
retryOptions == undefined || | ||
typeof retryOptions.timeoutInMs !== "number" || | ||
!isFinite(retryOptions.timeoutInMs) || | ||
// TODO: not sure what the justification is for always forcing at least 60 seconds. | ||
retryOptions.timeoutInMs < CoreAMQPConstants.defaultOperationTimeoutInMs | ||
? CoreAMQPConstants.defaultOperationTimeoutInMs | ||
: retryOptions.timeoutInMs; | ||
|
||
return timeoutInMs; | ||
} | ||
|
||
/** | ||
* @internal | ||
* @ignore | ||
*/ | ||
export type RetryOptionsInternal = Required<Pick<RetryOptions, "timeoutInMs">> & | ||
Exclude<RetryOptions, "timeoutInMs">; | ||
|
||
/** | ||
* @internal | ||
* @ignore | ||
*/ | ||
export function normalizeRetryOptions( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this was already done at SBC level, I see no point in keeping it now. |
||
retryOptions: RetryOptions | undefined | ||
): RetryOptionsInternal { | ||
return { | ||
...retryOptions, | ||
timeoutInMs: getRetryAttemptTimeoutInMs(retryOptions) | ||
}; | ||
} | ||
|
||
/** | ||
* @internal | ||
* @ignore | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In #8685, we added a guard to ensure this does not result in -ve value in Event Hubs. Can we include that in this PR for Service Bus
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added