We will be sunsetting Advisor during Jan, 2026 and will instead be providing information in Snyk Security DB.

You can begin to take advantage of Snyk Security DB today for a unified, package-centric experience.

How to use the @azure/amqp-common.defaultLock.acquire function in @azure/amqp-common

To help you get started, we’ve selected a few @azure/amqp-common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / azure-sdk-for-js / sdk / servicebus / service-bus / src / core / managementClient.ts View on Github external
application_properties: {
          operation: Constants.operations.enumerateRules
        }
      };
      request.application_properties![Constants.trackingId] = generate_uuid();

      log.mgmt(
        "[%s] Get rules request body: %O.",
        this._context.namespace.connectionId,
        request.body
      );
      log.mgmt(
        "[%s] Acquiring lock to get the management req res link.",
        this._context.namespace.connectionId
      );
      await defaultLock.acquire(this.managementLock, () => {
        return this._init();
      });

      const response = await this._mgmtReqResLink!.sendRequest(request);
      if (
        response.application_properties!.statusCode === 204 ||
        !response.body ||
        !Array.isArray(response.body.rules)
      ) {
        return [];
      }

      // Reference: https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-amqp-request-response#response-11
      const result: { "rule-description": Typed }[] = response.body.rules || [];
      const rules: RuleDescription[] = [];
      result.forEach((x) => {
github Azure / azure-sdk-for-js / sdk / servicebus / service-bus / src / core / messageSender.ts View on Github external
} else {
        const state: any = {
          wasCloseInitiated: wasCloseInitiated,
          senderError: senderError,
          _sender: this._sender
        };
        log.error(
          "[%s] Something went wrong. State of sender '%s' with address '%s' is: %O",
          this._context.namespace.connectionId,
          this.name,
          this.address,
          state
        );
      }
      if (shouldReopen) {
        await defaultLock.acquire(this.senderLock, () => {
          const options: SenderOptions = this._createSenderOptions({
            newName: true
          });
          // shall retry forever at an interval of 15 seconds if the error is a retryable error
          // else bail out when the error is not retryable or the oepration succeeds.
          const config: RetryConfig = {
            operation: () => this._init(options),
            connectionId: this._context.namespace.connectionId!,
            operationType: RetryOperationType.senderLink,
            times: Constants.defaultConnectionRetryAttempts,
            connectionHost: this._context.namespace.config.host,
            delayInSeconds: 15
          };
          return retry(config);
        });
      }
github Azure / azure-sdk-for-js / sdk / servicebus / service-bus / src / core / messageSender.ts View on Github external
} else {
        const state: any = {
          wasCloseInitiated: wasCloseInitiated,
          senderError: senderError,
          _sender: this._sender
        };
        log.error(
          "[%s] Something went wrong. State of sender '%s' with address '%s' is: %O",
          this._context.namespace.connectionId,
          this.name,
          this.address,
          state
        );
      }
      if (shouldReopen) {
        await defaultLock.acquire(this.senderLock, () => {
          const options: SenderOptions = this._createSenderOptions({
            newName: true
          });
          // shall retry forever at an interval of 15 seconds if the error is a retryable error
          // else bail out when the error is not retryable or the oepration succeeds.
          const config: RetryConfig = {
            operation: () => this._init(options),
            connectionId: this._context.namespace.connectionId!,
            operationType: RetryOperationType.senderLink,
            times: Constants.defaultConnectionRetryAttempts,
            connectionHost: this._context.namespace.config.host,
            delayInSeconds: 15
          };
          return retry(config);
        });
      }
github Azure / azure-sdk-for-js / sdk / servicebus / service-bus / src / core / managementClient.ts View on Github external
};
      const associatedLinkName = this._getAssociatedReceiverName(this._context, sessionId);
      if (associatedLinkName) {
        request.application_properties![Constants.associatedLinkName] = associatedLinkName;
      }
      request.application_properties![Constants.trackingId] = generate_uuid();
      log.mgmt(
        "[%s] Peek by sequence number request body: %O.",
        this._context.namespace.connectionId,
        request.body
      );
      log.mgmt(
        "[%s] Acquiring lock to get the management req res link.",
        this._context.namespace.connectionId
      );
      await defaultLock.acquire(this.managementLock, () => {
        return this._init();
      });

      const result = await this._mgmtReqResLink!.sendRequest(request);
      if (result.application_properties!.statusCode !== 204) {
        const messages = result.body.messages as { message: Buffer }[];
        for (const msg of messages) {
          const decodedMessage = RheaMessageUtil.decode(msg.message);
          const message = fromAmqpMessage(decodedMessage as any);
          message.body = this._context.namespace.dataTransformer.decode(message.body);
          messageList.push(message);
          this._lastPeekedSequenceNumber = message.sequenceNumber!;
        }
      }
    } catch (err) {
      const error = translate(err);
github Azure / azure-sdk-for-js / sdk / servicebus / service-bus / src / core / managementClient.ts View on Github external
};
      request.application_properties![Constants.trackingId] = generate_uuid();
      const associatedLinkName = this._getAssociatedReceiverName(this._context, sessionId);
      if (associatedLinkName) {
        request.application_properties![Constants.associatedLinkName] = associatedLinkName;
      }
      log.mgmt(
        "[%s] Renew Session Lock request body: %O.",
        this._context.namespace.connectionId,
        request.body
      );
      log.mgmt(
        "[%s] Acquiring lock to get the management req res link.",
        this._context.namespace.connectionId
      );
      await defaultLock.acquire(this.managementLock, () => {
        return this._init();
      });
      const result = await this._mgmtReqResLink!.sendRequest(request, options);
      const lockedUntilUtc = new Date(result.body.expiration);
      log.mgmt(
        "[%s] Lock for session '%s' will expire at %s.",
        this._context.namespace.connectionId,
        sessionId,
        lockedUntilUtc.toString()
      );
      return lockedUntilUtc;
    } catch (err) {
      const error = translate(err);
      log.error(
        "An error occurred while sending the renew lock request to $management " + "endpoint: %O",
        error
github Azure / azure-sdk-for-js / sdk / servicebus / service-bus / src / core / managementClient.ts View on Github external
application_properties: {
          operation: Constants.operations.removeRule
        }
      };
      request.application_properties![Constants.trackingId] = generate_uuid();

      log.mgmt(
        "[%s] Remove Rule request body: %O.",
        this._context.namespace.connectionId,
        request.body
      );
      log.mgmt(
        "[%s] Acquiring lock to get the management req res link.",
        this._context.namespace.connectionId
      );
      await defaultLock.acquire(this.managementLock, () => {
        return this._init();
      });

      await this._mgmtReqResLink!.sendRequest(request);
    } catch (err) {
      const error = translate(err);
      log.error(
        "An error occurred while sending the remove rule request to $management " + "endpoint: %O",
        error
      );
      throw error;
    }
  }
github Azure / azure-sdk-for-js / sdk / servicebus / service-bus / src / core / managementClient.ts View on Github external
}
      };
      if (this._context.sender) {
        request.application_properties![Constants.associatedLinkName] = this._context.sender!.name;
      }
      request.application_properties![Constants.trackingId] = generate_uuid();
      log.mgmt(
        "[%s] Schedule messages request body: %O.",
        this._context.namespace.connectionId,
        request.body
      );
      log.mgmt(
        "[%s] Acquiring lock to get the management req res link.",
        this._context.namespace.connectionId
      );
      await defaultLock.acquire(this.managementLock, () => {
        return this._init();
      });
      const result = await this._mgmtReqResLink!.sendRequest(request);
      const sequenceNumbers = result.body[Constants.sequenceNumbers];
      const sequenceNumbersAsLong = [];
      for (let i = 0; i < sequenceNumbers.length; i++) {
        if (typeof sequenceNumbers[i] === "number") {
          sequenceNumbersAsLong.push(Long.fromNumber(sequenceNumbers[i]));
        } else {
          sequenceNumbersAsLong.push(Long.fromBytesBE(sequenceNumbers[i]));
        }
      }
      return sequenceNumbersAsLong;
    } catch (err) {
      const error = translate(err);
      log.error(
github Azure / azure-sdk-for-js / sdk / servicebus / service-bus / src / core / managementClient.ts View on Github external
};
      const associatedLinkName = this._getAssociatedReceiverName(this._context, sessionId);
      if (associatedLinkName) {
        request.application_properties![Constants.associatedLinkName] = associatedLinkName;
      }
      request.application_properties![Constants.trackingId] = generate_uuid();
      log.mgmt(
        "[%s] Set Session state request body: %O.",
        this._context.namespace.connectionId,
        request.body
      );
      log.mgmt(
        "[%s] Acquiring lock to get the management req res link.",
        this._context.namespace.connectionId
      );
      await defaultLock.acquire(this.managementLock, () => {
        return this._init();
      });
      await this._mgmtReqResLink!.sendRequest(request);
    } catch (err) {
      const error = translate(err);
      log.error(
        "An error occurred while sending the renew lock request to $management " + "endpoint: %O",
        error
      );
      throw error;
    }
  }
github Azure / azure-sdk-for-js / sdk / servicebus / service-bus / src / core / managementClient.ts View on Github external
};

      if (this._context.sender) {
        request.application_properties![Constants.associatedLinkName] = this._context.sender!.name;
      }
      request.application_properties![Constants.trackingId] = generate_uuid();
      log.mgmt(
        "[%s] Cancel scheduled messages request body: %O.",
        this._context.namespace.connectionId,
        request.body
      );
      log.mgmt(
        "[%s] Acquiring lock to get the management req res link.",
        this._context.namespace.connectionId
      );
      await defaultLock.acquire(this.managementLock, () => {
        return this._init();
      });
      await this._mgmtReqResLink!.sendRequest(request);
    } catch (err) {
      const error = translate(err);
      log.error(
        "An error occurred while sending the request to cancel the scheduled message to " +
          "$management endpoint: %O",
        error
      );
      throw error;
    }
  }
github Azure / azure-sdk-for-js / sdk / servicebus / service-bus / src / core / managementClient.ts View on Github external
};
      request.application_properties![Constants.trackingId] = generate_uuid();
      const associatedLinkName = this._getAssociatedReceiverName(this._context);
      if (associatedLinkName) {
        request.application_properties![Constants.associatedLinkName] = associatedLinkName;
      }
      log.mgmt(
        "[%s] Renew message Lock request: %O.",
        this._context.namespace.connectionId,
        request
      );
      log.mgmt(
        "[%s] Acquiring lock to get the management req res link.",
        this._context.namespace.connectionId
      );
      await defaultLock.acquire(this.managementLock, () => {
        return this._init();
      });
      const result = await this._mgmtReqResLink!.sendRequest(request, options);
      const lockedUntilUtc = new Date(result.body.expirations[0]);
      return lockedUntilUtc;
    } catch (err) {
      const error = translate(err);
      log.error(
        "An error occurred while sending the renew lock request to $management " + "endpoint: %O",
        error
      );
      throw error;
    }
  }