0.16.1 • Published 8 months ago

@blackglory/mq-js v0.16.1

Weekly downloads
202
License
MIT
Repository
github
Last release
8 months ago

mq-js

Install

npm install --save @blackglory/mq-js
# or
yarn add @blackglory/mq-js

API

MQClient

interface IMQClientOptions {
  server: string
  timeout?: number
  retryIntervalForReconnection?: number
}

interface IQueueConfig extends JSONObject {
  unique: boolean
  draftingTimeout: number
  orderedTimeout: number
  activeTimeout: number
  concurrency: number | null
  behaviorWhenCompleted: AdditionalBehavior
  behaviorWhenAbandoned: AdditionalBehavior
}

interface IMessage {
  slots: Record<string, JSONValue>
  priority: number | null
  state: MessageState
}

interface IQueueStats {
  drafting: number
  waiting: number
  ordered: number
  active: number
  failed: number
  completed: number
  abandoned: number
}

enum MessageState {
  Drafting
, Waiting
, Ordered
, Active
, Failed
, Completed
, Abandoned
}

enum AdditionalBehavior {
  None
, RemoveMessage
, RemoveAllSlots
}

class QueueNotFound extends CustomError {}
class MessageNotFound extends CustomError {}
class SlotNotFound extends CustomError {}
class DuplicateMessage extends CustomError {}
class BadMessageState extends CustomError {}

class MQClient {
  static create(options: IMQClientOptions): Promise<MQClient>

  close(): Promise<void>

  getAllQueueIds(signal?: AbortSignal): Promise<string[]>

  getQueue(queueId: string, signal?: AbortSignal): Promise<IQueueConfig | null>

  setQueue(queueId: string, config: IQueueConfig, signal?: AbortSignal): Promise<void>

  removeQueue(queueId: string, signal?: AbortSignal): Promise<void>

  getQueueStats(queueId: string, signal?: AbortSignal): Promise<IQueueStats | null>

  resetQueue(queueId: string, signal?: AbortSignal): Promise<void>

  /**
   * @throws {QueueNotFound}
   */
  draftMessage(
    queueId: string
  , priority: number | null
  , slotNames: NonEmptyArray<string>
  , signal?: AbortSignal
  ): Promise<string>

  /**
   * @throws {QueueNotFound}
   * @throws {MessageNotFound}
   * @throws {SlotNotFound}
   * @throws {BadMessageState}
   * @throws {DuplicateMessage}
   */
  setMessageSlot(
    queueId: string
  , messageId: string
  , slotName: string
  , value: JSONValue
  , signal?: AbortSignal
  ): Promise<void>

  /**
   * @throws {QueueNotFound}
   * @throws {AbortError}
   */
  orderMessage(queueId: string, signal?: AbortSignal): Promise<string>

  /**
   * @throws {QueueNotFound}
   */
  getMessage(
    queueId: string
  , messageId: string
  , signal?: AbortSignal
  ): Promise<IMessage | null>

  /**
   * @throws {QueueNotFound}
   * @throws {MessageNotFound}
   * @throws {BadMessageState}
   */
  completeMessage(queueId: string, messageId: string, signal?: AbortSignal): Promise<void>

  /**
   * @throws {QueueNotFound}
   * @throws {MessageNotFound}
   * @throws {BadMessageState}
   */
  failMessage(queueId: string, messageId: string, signal?: AbortSignal): Promise<void>

  /**
   * @throws {QueueNotFound}
   * @throws {MessageNotFound}
   * @throws {BadMessageState}
   */
  renewMessage(queueId: string, messageId: string, signal?: AbortSignal): Promise<void>

  /**
   * @throws {QueueNotFound}
   * @throws {MessageNotFound}
   */
  abandonMessage(queueId: string, messageId: string, signal?: AbortSignal): Promise<void>

  /**
   * @throws {QueueNotFound}
   */
  removeMessage(queueId: string, messageId: string, signal?: AbortSignal): Promise<void>

  /**
   * @throws {QueueNotFound}
   */
  abandonAllFailedMessages(queueId: string, signal?: AbortSignal): Promise<void>

  /**
   * @throws {QueueNotFound}
   */
  renewAllFailedMessages(queueId: string, signal?: AbortSignal): Promise<void>

  /**
   * @throws {QueueNotFound}
   */
  getMessageIdsByState(
    queueId: string
  , state: MessageState
  , signal?: AbortSignal
  ): Promise<string[]>

  /**
   * @throws {QueueNotFound}
   */
  clearMessagesByState(
    queueId: string
  , state: MessageState
  , signal?: AbortSignal
  ): Promise<void>
}
0.16.0

8 months ago

0.16.1

8 months ago

0.15.1

3 years ago

0.15.0

3 years ago

0.14.3

3 years ago

0.14.0

3 years ago

0.14.1

3 years ago

0.14.2

3 years ago

0.13.3

3 years ago

0.13.4

3 years ago

0.13.2

3 years ago

0.13.0

4 years ago

0.13.1

4 years ago

0.12.0

4 years ago

0.11.0

4 years ago

0.11.1

4 years ago

0.11.2

4 years ago

0.11.3

4 years ago

0.10.1

4 years ago

0.10.0

4 years ago

0.9.8

4 years ago

0.9.7

4 years ago

0.9.6

4 years ago

0.9.5

4 years ago

0.9.4

4 years ago

0.9.3

5 years ago

0.9.0

5 years ago

0.9.2

5 years ago

0.9.1

5 years ago

0.8.2

5 years ago

0.8.1

5 years ago

0.8.0

5 years ago

0.7.0

5 years ago

0.6.17

5 years ago

0.6.16

5 years ago

0.6.15

5 years ago

0.6.14

5 years ago

0.6.13

5 years ago

0.6.12

5 years ago

0.6.11

5 years ago

0.6.9

5 years ago

0.6.10

5 years ago

0.6.8

5 years ago

0.6.7

5 years ago

0.6.6

5 years ago

0.6.5

5 years ago

0.6.4

5 years ago

0.6.3

5 years ago

0.6.2

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.11

5 years ago

0.5.10

5 years ago

0.5.9

5 years ago

0.5.8

5 years ago

0.5.7

5 years ago

0.5.6

5 years ago

0.5.5

5 years ago

0.5.4

5 years ago

0.5.3

5 years ago

0.5.2

5 years ago

0.5.0

5 years ago

0.5.1

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago