rocketmq-client-nodejs
Version:
RocketMQ Node.js Client
76 lines • 3.99 kB
JavaScript
;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConsumeResultSuspend = exports.ConsumeResult = void 0;
/**
* Consume result for push consumer.
*
* <p>Designed for push consumer specifically. This is a class-based result
* (matching the Java client) so that it can be extended with suspend results.</p>
*/
class ConsumeResult {
/**
* Consume message successfully.
*/
static SUCCESS = new ConsumeResult('SUCCESS');
/**
* Failed to consume message.
*/
static FAILURE = new ConsumeResult('FAILURE');
name;
constructor(name) {
this.name = name;
}
toString() {
return this.name;
}
}
exports.ConsumeResult = ConsumeResult;
const MIN_SUSPEND_TIME_MS = 50;
/**
* Suspend consume result.
*
* <p>When returned by the message listener, the consumer will suspend
* consumption of the current message (and related messages in FIFO mode)
* for the specified duration by changing the invisible duration.</p>
*/
class ConsumeResultSuspend extends ConsumeResult {
suspendTimeMs;
constructor(suspendTimeMs) {
super('SUSPEND');
if (suspendTimeMs < MIN_SUSPEND_TIME_MS) {
throw new Error(`suspend time cannot be less than ${MIN_SUSPEND_TIME_MS}ms, got ${suspendTimeMs}ms`);
}
this.suspendTimeMs = suspendTimeMs;
}
/**
* Create a suspend result with the given suspend time in milliseconds.
*
* @param suspendTimeMs - Suspend time in milliseconds
* @return {ConsumeResultSuspend} ConsumeResultSuspend instance
* @throws {Error} if suspendTimeMs is less than 50ms
*/
static of(suspendTimeMs) {
return new ConsumeResultSuspend(suspendTimeMs);
}
toString()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