update
This commit is contained in:
@@ -386,9 +386,9 @@ Each payload can have a different type, enabling mixed-content messages (e.g., c
|
||||
- `is_publish::Bool = true` - Whether to automatically publish the message to NATS
|
||||
|
||||
# Return:
|
||||
- A tuple `(env, msg_json_str)` where:
|
||||
- A tuple `(env, env_json_str)` where:
|
||||
- `env::msgEnvelope_v1` - The envelope object containing all metadata and payloads
|
||||
- `msg_json_str::String` - JSON string representation of the envelope for publishing
|
||||
- `env_json_str::String` - JSON string representation of the envelope for publishing
|
||||
|
||||
# Example
|
||||
```jldoctest
|
||||
@@ -415,7 +415,7 @@ env, msg_json = smartsend("chat.subject", [
|
||||
])
|
||||
|
||||
# Publish the JSON string directly using NATS request-reply pattern
|
||||
# reply = NATS.request(nats_url, subject, msg_json_str; reply_to=reply_to_topic)
|
||||
# reply = NATS.request(nats_url, subject, env_json_str; reply_to=reply_to_topic)
|
||||
```
|
||||
""" #[PENDING]
|
||||
function smartsend(
|
||||
@@ -432,7 +432,7 @@ function smartsend(
|
||||
receiver_id::String = "",
|
||||
reply_to::String = "",
|
||||
reply_to_msg_id::String = "",
|
||||
is_publish::Bool = true # some time the user want to get env and msg_json_str from this function without publishing the msg
|
||||
is_publish::Bool = true # some time the user want to get env and env_json_str from this function without publishing the msg
|
||||
) where {T1<:Any}
|
||||
|
||||
# Generate correlation ID if not provided
|
||||
@@ -516,12 +516,12 @@ function smartsend(
|
||||
metadata = Dict{String, Any}(),
|
||||
)
|
||||
|
||||
msg_json_str = envelope_to_json(env) # Convert envelope to JSON
|
||||
env_json_str = envelope_to_json(env) # Convert envelope to JSON
|
||||
if is_publish
|
||||
publish_message(nats_url, subject, msg_json_str, cid) # Publish message to NATS
|
||||
publish_message(nats_url, subject, env_json_str, cid) # Publish message to NATS
|
||||
end
|
||||
|
||||
return (env, msg_json_str)
|
||||
return (env, env_json_str)
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -462,7 +462,7 @@ async function smartsend(subject, data, options = {}) {
|
||||
* @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<Object>} - An object with { env: MessageEnvelope, msg_json_str: string }
|
||||
* @returns {Promise<Object>} - An object with { env: MessageEnvelope, env_json_str: string }
|
||||
*/
|
||||
const {
|
||||
natsUrl = DEFAULT_NATS_URL,
|
||||
@@ -559,17 +559,17 @@ async function smartsend(subject, data, options = {}) {
|
||||
});
|
||||
|
||||
// Convert envelope to JSON string
|
||||
const msg_json_str = env.toString();
|
||||
const env_json_str = env.toString();
|
||||
|
||||
// Publish to NATS if isPublish is true
|
||||
if (isPublish) {
|
||||
await publish_message(natsUrl, subject, msg_json_str, correlationId);
|
||||
await publish_message(natsUrl, subject, env_json_str, correlationId);
|
||||
}
|
||||
|
||||
// Return both envelope and JSON string (tuple-like structure)
|
||||
return {
|
||||
env: env,
|
||||
msg_json_str: msg_json_str
|
||||
env_json_str: env_json_str
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -462,9 +462,9 @@ def smartsend(subject, data, nats_url=DEFAULT_NATS_URL, fileserver_url=DEFAULT_F
|
||||
is_publish: Whether to automatically publish the message to NATS (default: True)
|
||||
|
||||
Returns:
|
||||
tuple: (env, msg_json_str) where:
|
||||
tuple: (env, env_json_str) where:
|
||||
- env: MessageEnvelope object with all metadata and payloads
|
||||
- msg_json_str: JSON string representation of the envelope for publishing
|
||||
- env_json_str: JSON string representation of the envelope for publishing
|
||||
"""
|
||||
# Generate correlation ID if not provided
|
||||
cid = correlation_id if correlation_id else str(uuid.uuid4())
|
||||
|
||||
Reference in New Issue
Block a user