UNPKG

4.29 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 */
16/// <reference types="node" />
17import { CallOptions } from 'google-gax';
18import { Span } from '@opentelemetry/api';
19import { BatchPublishOptions } from './message-batch';
20import { Queue, OrderedQueue } from './message-queues';
21import { Topic } from '../topic';
22import { RequestCallback, EmptyCallback } from '../pubsub';
23import { google } from '../../protos/protos';
24export declare type PubsubMessage = google.pubsub.v1.IPubsubMessage;
25export interface Attributes {
26 [key: string]: string;
27}
28export declare type PublishCallback = RequestCallback<string>;
29export interface PublishOptions {
30 batching?: BatchPublishOptions;
31 gaxOpts?: CallOptions;
32 messageOrdering?: boolean;
33 enableOpenTelemetryTracing?: boolean;
34}
35/**
36 * @typedef PublishOptions
37 * @property {BatchPublishOptions} [batching] The maximum number of bytes to
38 * buffer before sending a payload.
39 * @property {object} [gaxOpts] Request configuration options, outlined
40 * {@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html|here.}
41 * @property {boolean} [messageOrdering] If true, messages published with the
42 * same order key in Message will be delivered to the subscribers in the order in which they
43 * are received by the Pub/Sub system. Otherwise, they may be delivered in
44 * any order.
45 */
46export declare const BATCH_LIMITS: BatchPublishOptions;
47/**
48 * A Publisher object allows you to publish messages to a specific topic.
49 *
50 * @private
51 * @class
52 *
53 * @see [Topics: publish API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/publish}
54 *
55 * @param {Topic} topic The topic associated with this publisher.
56 * @param {PublishOptions} [options] Configuration object.
57 */
58export declare class Publisher {
59 topic: Topic;
60 settings: PublishOptions;
61 queue: Queue;
62 orderedQueues: Map<string, OrderedQueue>;
63 constructor(topic: Topic, options?: PublishOptions);
64 flush(): Promise<void>;
65 flush(callback: EmptyCallback): void;
66 publish(data: Buffer, attributes?: Attributes): Promise<string>;
67 publish(data: Buffer, callback: PublishCallback): void;
68 publish(data: Buffer, attributes: Attributes, callback: PublishCallback): void;
69 /**
70 * Publish the provided message.
71 *
72 * @private
73 *
74 * @throws {TypeError} If data is not a Buffer object.
75 * @throws {TypeError} If any value in `attributes` object is not a string.
76 *
77 * @param {PubsubMessage} [message] Options for this message.
78 * @param {PublishCallback} [callback] Callback function.
79 */
80 publishMessage(message: PubsubMessage, callback: PublishCallback): void;
81 /**
82 * Indicates to the publisher that it is safe to continue publishing for the
83 * supplied ordering key.
84 *
85 * @private
86 *
87 * @param {string} key The ordering key to continue publishing for.
88 */
89 resumePublishing(key: string): void;
90 /**
91 * Returns the set of default options used for {@link Publisher}. The
92 * returned value is a copy, and editing it will have no effect elsehwere.
93 *
94 * This is a non-static method to make it easier to access/stub.
95 *
96 * @private
97 *
98 * @returns {PublishOptions}
99 */
100 getOptionDefaults(): PublishOptions;
101 /**
102 * Sets the Publisher options.
103 *
104 * @private
105 *
106 * @param {PublishOptions} options The publisher options.
107 */
108 setOptions(options?: PublishOptions): void;
109 /**
110 * Constructs an OpenTelemetry span
111 *
112 * @private
113 *
114 * @param {PubsubMessage} message The message to create a span for
115 */
116 constructSpan(message: PubsubMessage): Span | undefined;
117}