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