Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if (!this._isOpen()) {
debug("Acquiring lock %s for initializing the session, sender and " +
"possibly the connection.", this.senderLock);
yield utils_1.defaultLock.acquire(this.senderLock, () => { return this._init(); });
}
debug("[%s] Sender '%s', trying to send EventData[]: %O", this._context.connectionId, this.name, datas);
const messages = [];
// Convert EventData to AmqpMessage.
for (let i = 0; i < datas.length; i++) {
const message = eventData_1.EventData.toAmqpMessage(datas[i]);
messages[i] = message;
}
// Encode every amqp message and then convert every encoded message to amqp data section
const batchMessage = {
body: rhea.message.data_sections(messages.map(rhea.message.encode))
};
// Set message_annotations, application_properties and properties of the first message as
// that of the envelope (batch message).
if (messages[0].message_annotations) {
batchMessage.message_annotations = messages[0].message_annotations;
}
if (messages[0].application_properties) {
batchMessage.application_properties = messages[0].application_properties;
}
for (const prop of eventData_1.messageProperties) {
if (messages[0][prop]) {
batchMessage[prop] = messages[0][prop];
}
}
// Finally encode the envelope (batch message).
const encodedBatchMessage = rhea.message.encode(batchMessage);
};
// Set message_annotations, application_properties and properties of the first message as
// that of the envelope (batch message).
if (messages[0].message_annotations) {
batchMessage.message_annotations = messages[0].message_annotations;
}
if (messages[0].application_properties) {
batchMessage.application_properties = messages[0].application_properties;
}
for (const prop of eventData_1.messageProperties) {
if (messages[0][prop]) {
batchMessage[prop] = messages[0][prop];
}
}
// Finally encode the envelope (batch message).
const encodedBatchMessage = rhea.message.encode(batchMessage);
debug("[%s]Sender '%s', sending encoded batch message.", this._context.connectionId, this.name, encodedBatchMessage);
return yield this._trySend(encodedBatchMessage, undefined, 0x80013700);
}
catch (err) {
debug("An error occurred while sending the batch message %O", err);
throw err;
}
});
}