constructor()

in nodejs/src/message/PublishingMessage.ts [33:65]


  constructor(options: MessageOptions, publishingSettings: PublishingSettings, txEnabled: boolean) {
    super(options);
    const length = this.body.length;
    const maxBodySizeBytes = publishingSettings.maxBodySizeBytes;
    if (length > maxBodySizeBytes) {
      throw new TypeError(`Message body size exceeds the threshold, max size=${maxBodySizeBytes} bytes`);
    }
    // Generate message id.
    this.messageId = MessageIdFactory.create().toString();
    // Normal message.
    if (!this.messageGroup && !this.deliveryTimestamp && !txEnabled) {
      this.messageType = MessageType.NORMAL;
      return;
    }
    // Fifo message.
    if (this.messageGroup && !txEnabled) {
      this.messageType = MessageType.FIFO;
      return;
    }
    // Delay message.
    if (this.deliveryTimestamp && !txEnabled) {
      this.messageType = MessageType.DELAY;
      return;
    }
    // Transaction message.
    if (!this.messageGroup &&
        !this.deliveryTimestamp && txEnabled) {
      this.messageType = MessageType.TRANSACTION;
      return;
    }
    // Transaction semantics is conflicted with fifo/delay.
    throw new TypeError('Transactional message should not set messageGroup or deliveryTimestamp');
  }