Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
">>>>> [%s] An error occurred for session of receiver '%s': %O.",
connectionContext.connection.id,
receiverName,
sessionError
);
}
}
};
const receiver: Receiver = await connectionContext.connection.createReceiver(
receiverOptions
);
receiver.on(ReceiverEvents.message, (context: EventContext) => {
console.log("Received message: %O", context.message);
});
receiver.on(ReceiverEvents.receiverError, (context: EventContext) => {
const receiverError = context.receiver && context.receiver.error;
if (receiverError) {
console.log(
">>>>> [%s] An error occurred for receiver '%s': %O.",
connectionContext.connection.id,
receiverName,
receiverError
);
}
});
// sleeping for 2 mins to let the receiver receive messages and then closing it.
await delay(120000);
await receiver.close();
await connectionContext.connection.close();
}
if (sessionError) {
console.log(
">>>>> [%s] An error occurred for session of receiver '%s': %O.",
connectionContext.connection.id,
receiverName,
sessionError
);
}
}
};
const receiver: Receiver = await connectionContext.connection.createReceiver(receiverOptions);
receiver.on(ReceiverEvents.message, (context: EventContext) => {
console.log("Received message: %O", context.message);
});
receiver.on(ReceiverEvents.receiverError, (context: EventContext) => {
const receiverError = context.receiver && context.receiver.error;
if (receiverError) {
console.log(
">>>>> [%s] An error occurred for receiver '%s': %O.",
connectionContext.connection.id,
receiverName,
receiverError
);
}
});
// sleeping for 2 mins to let the receiver receive messages and then closing it.
await delay(120000);
await receiver.close();
await connectionContext.connection.close();
}
if (sessionError) {
console.log(
">>>>> [%s] An error occurred for session of receiver '%s': %O.",
connectionContext.connection.id,
receiverName,
sessionError
);
}
}
};
const receiver: Receiver = await connectionContext.connection.createReceiver(receiverOptions);
receiver.on(ReceiverEvents.message, (context: EventContext) => {
console.log("Received message: %O", context.message);
});
receiver.on(ReceiverEvents.receiverError, (context: EventContext) => {
const receiverError = context.receiver && context.receiver.error;
if (receiverError) {
console.log(
">>>>> [%s] An error occurred for receiver '%s': %O.",
connectionContext.connection.id,
receiverName,
receiverError
);
}
});
// sleeping for 2 mins to let the receiver receive messages and then closing it.
await delay(120000);
await receiver.close();
await connectionContext.connection.close();
}
const finalAction = (): void => {
if (this._newMessageReceivedTimer) {
clearTimeout(this._newMessageReceivedTimer);
}
if (totalWaitTimer) {
clearTimeout(totalWaitTimer);
}
// Removing listeners, so that the next receiveMessages() call can set them again.
if (this._receiver) {
this._receiver.removeListener(ReceiverEvents.receiverError, onReceiveError);
this._receiver.removeListener(ReceiverEvents.message, onReceiveMessage);
this._receiver.session.removeListener(SessionEvents.sessionError, onSessionError);
}
if (this.detachedError) {
if (this._receiver) {
this._receiver.removeListener(ReceiverEvents.receiverDrained, onReceiveDrain);
}
this.isReceivingMessages = false;
const err = translate(this.detachedError);
return reject(err);
}
if (this._receiver && this._receiver.credit > 0) {
log.batching(
"[%s] Receiver '%s': Draining leftover credits(%d).",
logger.verbose(
"[%s] Creating sender/receiver links on a session for $cbs endpoint.",
this.connection.id
);
this._cbsSenderReceiverLink = await RequestResponseLink.create(
this.connection,
srOpt,
rxOpt
);
this._cbsSenderReceiverLink.sender.on(SenderEvents.senderError, (context: EventContext) => {
const id = context.connection.options.id;
const ehError = translate(context.sender!.error!);
logger.verbose("[%s] An error occurred on the cbs sender link.. %O", id, ehError);
});
this._cbsSenderReceiverLink.receiver.on(
ReceiverEvents.receiverError,
(context: EventContext) => {
const id = context.connection.options.id;
const ehError = translate(context.receiver!.error!);
logger.verbose("[%s] An error occurred on the cbs receiver link.. %O", id, ehError);
}
);
logger.verbose(
"[%s] Successfully created the cbs sender '%s' and receiver '%s' " +
"links over cbs session.",
this.connection.id,
this._cbsSenderReceiverLink.sender.name,
this._cbsSenderReceiverLink.receiver.name
);
} else {
logger.verbose(
"[%s] CBS session is already present. Reusing the cbs sender '%s' " +
"srOpts: %o, receiverOpts: %O.",
this._context.namespace.connectionId,
sropt,
rxopt
);
this._mgmtReqResLink = await RequestResponseLink.create(
this._context.namespace.connection,
sropt,
rxopt
);
this._mgmtReqResLink.sender.on(SenderEvents.senderError, (context: EventContext) => {
const id = context.connection.options.id;
const ehError = translate(context.sender!.error!);
log.error("[%s] An error occurred on the $management sender link.. %O", id, ehError);
});
this._mgmtReqResLink.receiver.on(ReceiverEvents.receiverError, (context: EventContext) => {
const id = context.connection.options.id;
const ehError = translate(context.receiver!.error!);
log.error("[%s] An error occurred on the $management receiver link.. %O", id, ehError);
});
log.mgmt(
"[%s] Created sender '%s' and receiver '%s' links for $management endpoint.",
this._context.namespace.connectionId,
this._mgmtReqResLink.sender.name,
this._mgmtReqResLink.receiver.name
);
await this._ensureTokenRenewal();
}
} catch (err) {
err = translate(err);
log.error(
"[%s] An error occured while establishing the $management links: %O",
"srOpts: %o, receiverOpts: %O.",
this._context.connectionId,
sropt,
rxopt
);
this._mgmtReqResLink = await RequestResponseLink.create(
this._context.connection,
sropt,
rxopt
);
this._mgmtReqResLink.sender.on(SenderEvents.senderError, (context: EventContext) => {
const id = context.connection.options.id;
const ehError = translate(context.sender!.error!);
logger.verbose("[%s] An error occurred on the $management sender link.. %O", id, ehError);
});
this._mgmtReqResLink.receiver.on(ReceiverEvents.receiverError, (context: EventContext) => {
const id = context.connection.options.id;
const ehError = translate(context.receiver!.error!);
logger.verbose(
"[%s] An error occurred on the $management receiver link.. %O",
id,
ehError
);
});
logger.verbose(
"[%s] Created sender '%s' and receiver '%s' links for $management endpoint.",
this._context.connectionId,
this._mgmtReqResLink.sender.name,
this._mgmtReqResLink.receiver.name
);
await this._ensureTokenRenewal();
}