UNPKG

2.55 kBTypeScriptView Raw
1/*!
2 * Copyright 2019 Google Inc. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import { PubsubMessage, PublishCallback } from './';
17export interface BatchPublishOptions {
18 maxBytes?: number;
19 maxMessages?: number;
20 maxMilliseconds?: number;
21}
22/**
23 * @typedef BatchPublishOptions
24 * @property {number} [maxBytes=1 * 1024 * 1024] The maximum number of bytes to
25 * buffer before sending a payload.
26 * @property {number} [maxMessages=100] The maximum number of messages to
27 * buffer before sending a payload.
28 * @property {number} [maxMilliseconds=10] The maximum duration to wait before
29 * sending a payload.
30 */
31/**
32 * Call used to help batch messages.
33 *
34 * @private
35 *
36 * @param {BatchPublishOptions} options The batching options.
37 */
38export declare class MessageBatch {
39 options: BatchPublishOptions;
40 messages: PubsubMessage[];
41 callbacks: PublishCallback[];
42 created: number;
43 bytes: number;
44 constructor(options: BatchPublishOptions);
45 /**
46 * Updates our options from new values.
47 *
48 * @param {BatchPublishOptions} options The new options.
49 */
50 setOptions(options: BatchPublishOptions): void;
51 /**
52 * Adds a message to the current batch.
53 *
54 * @param {object} message The message to publish.
55 * @param {PublishCallback} callback The callback function.
56 */
57 add(message: PubsubMessage, callback: PublishCallback): void;
58 /**
59 * Indicates if a given message can fit in the batch.
60 *
61 * @param {object} message The message in question.
62 * @returns {boolean}
63 */
64 canFit({ data }: PubsubMessage): boolean;
65 /**
66 * Checks to see if this batch is at the maximum allowed payload size.
67 * When publishing ordered messages, it is ok to exceed the user configured
68 * thresholds while a batch is in flight.
69 *
70 * @returns {boolean}
71 */
72 isAtMax(): boolean;
73 /**
74 * Indicates if the batch is at capacity.
75 *
76 * @returns {boolean}
77 */
78 isFull(): boolean;
79}