Skip to content

Commit

Permalink
fix(rpc/service): disable autoAck if message already sealed
Browse files Browse the repository at this point in the history
  • Loading branch information
CheerlessCloud committed Sep 24, 2018
1 parent 16748ff commit ee009f0
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class RpcService extends AdapterConsumer {
}

// @todo merge _classMessageHandler and _functionalMessageHandler and extract to class
async _classMessageHandler(message: IMessage) {
async _classMessageHandler(message: IMessage): Promise<void> {
const { type: action = 'default' } = message._props;
const RpcServiceHandler = this._handlers.get(action);
const mustRequeue = !message._props.redelivered;
Expand Down Expand Up @@ -156,15 +156,23 @@ class RpcService extends AdapterConsumer {
let isSuccess = false;
try {
await handler.beforeHandle();

const replyPayload = await handler.handle();
await handler.afterHandle();

await this._reply(message, replyPayload);
isSuccess = true;

await handler.onSuccess();
} catch (err) {
await this._reply(message, null, err);
await handler.onFail(err);
} finally {
await handler.afterHandle();

if (message.isSealed) {
return; // eslint-disable-line no-unsafe-finally
}

try {
if (isSuccess) {
await message.ack();
Expand Down

0 comments on commit ee009f0

Please sign in to comment.