-
Notifications
You must be signed in to change notification settings - Fork 227
Description
Observed behavior
When creating a new subject for publishing, if there is a space in the subject, it will use the second part of the subject as a reply subject:
async fn test_1() {
let subject = async_nats::Subject::from_static("test.one two");
let conn = async_nats::connect_with_options(
"nats://127.0.0.1:43831",
ConnectOptions::with_user_and_password(
"username".to_string(),
"password".to_string(),
),
)
.await
.unwrap();
let res = conn.publish(subject, "Hello world!".into()).await;
conn.flush().await;
}This results in the following message when subscribing through the NATS cli:
[#1] Received on "test.one" with reply "two"
Hello world!
The same behavior can be replicated when using a static string directly in the publish method's arguments.
Expected behavior
Subject creation with invalid characters such as a space should return an error. The API for the crate has an explicit method for publishing a message with a reply subject (publish_with_reply(...)), so having a reply subject be created when using the publish(...) method is unexpected.
Server and client version
nats-server version: 2.11.3
nats version: 0.2.3
async_nats crate version: 0.42.0
Host environment
Pop!_OS 24.04 LTS x86_64
NATS server running on the machine (not in a container)
Steps to reproduce
- Run an instance of nats-server
- Subscribe to the following subject through the nats cli:
nats sub test.> - Create a new rust project with the async_nats and tokio crates, and run the following code, using the appropriate username and password for the nats-server instance:
#[tokio::main] async fn main() { let subject = async_nats::Subject::from_static("test.one two"); let conn = async_nats::connect_with_options( "nats://127.0.0.1:43831", async_nats::ConnectOptions::with_user_and_password( "local".to_string(), "password".to_string(), ), ) .await .unwrap(); let res = conn.publish(subject, "Hello world!".into()).await; conn.flush().await; }