update
This commit is contained in:
@@ -460,8 +460,9 @@ async function smartsend(subject, data, options = {}) {
|
||||
* @param {string} options.receiverId - UUID of the receiver (default: "")
|
||||
* @param {string} options.replyTo - Topic to reply to (default: "")
|
||||
* @param {string} options.replyToMsgId - Message ID this message is replying to (default: "")
|
||||
* @param {boolean} options.isPublish - Whether to automatically publish the message to NATS (default: true)
|
||||
*
|
||||
* @returns {Promise<MessageEnvelope>} - The envelope for tracking
|
||||
* @returns {Promise<Object>} - An object with { env: MessageEnvelope, msg_json_str: string }
|
||||
*/
|
||||
const {
|
||||
natsUrl = DEFAULT_NATS_URL,
|
||||
@@ -474,7 +475,8 @@ async function smartsend(subject, data, options = {}) {
|
||||
receiverName = "",
|
||||
receiverId = "",
|
||||
replyTo = "",
|
||||
replyToMsgId = ""
|
||||
replyToMsgId = "",
|
||||
isPublish = true // Whether to automatically publish the message to NATS
|
||||
} = options;
|
||||
|
||||
log_trace(correlationId, `Starting smartsend for subject: ${subject}`);
|
||||
@@ -556,10 +558,19 @@ async function smartsend(subject, data, options = {}) {
|
||||
payloads: payloads
|
||||
});
|
||||
|
||||
// Publish message to NATS
|
||||
await publish_message(natsUrl, subject, env.toString(), correlationId);
|
||||
// Convert envelope to JSON string
|
||||
const msg_json_str = env.toString();
|
||||
|
||||
return env;
|
||||
// Publish to NATS if isPublish is true
|
||||
if (isPublish) {
|
||||
await publish_message(natsUrl, subject, msg_json_str, correlationId);
|
||||
}
|
||||
|
||||
// Return both envelope and JSON string (tuple-like structure)
|
||||
return {
|
||||
env: env,
|
||||
msg_json_str: msg_json_str
|
||||
};
|
||||
}
|
||||
|
||||
// Helper: Publish message to NATS
|
||||
|
||||
Reference in New Issue
Block a user