Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add queue subscriber and unit test #388

Merged
merged 1 commit into from
Apr 26, 2022

Conversation

stevelr
Copy link
Contributor

@stevelr stevelr commented Apr 26, 2022

add queue subscription and unit test
there are a couple open questions on function naming (see TODO in code)

Signed-off-by: Steve [email protected]

@@ -725,15 +735,38 @@ impl Client {
format!("_INBOX.{}", nuid::next())
}

pub async fn queue_subscribe(
&mut self,
subject: String,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to stray from your existing conventions, but it would be slightly more ergonomic for the signature of subscribe to be
fn subscribe<T:ToString>(&self, subject: T)
and for queue_subscribe to be
fn queue_subscribe<T1:ToString,T2:ToString>(&self, subject: T1, queue_group: T2)

Or, if they are to be unified into a single subscribe function, then
fn subscribe<T1:ToString,T2:ToString>(&self, subject: T1, queue_group: Option<T2>)

If you're ok with either of those, I can also implement it on the next commit.

Copy link
Member

@Jarema Jarema Apr 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToString allocates, even if you pass String.

Into<String> is a better option here, though we decided to NOT have that right now, as we might add Subject type later, which would break API.

We refrained from having those helpers to allow ourselves to decide later.
Both @caspervonb and I want to be very clear in the codebase - especially in publish which can happen thousands of times per second - what is allocated etc.

Copy link
Collaborator

@caspervonb caspervonb Apr 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hesitant towards doing this because the ToString implementation for String is a deep clone, it could be Into<String> which should be a move but personally I'm more for explicit conversions than implicit ones as the caller is in control of how the conversion happens.

We're considering if we want a (potentially interned) type for Subjects, header names will likely get one in the form of HeaderNames from the http crate's API.

I'd say hold off on this for now, at-least until the subject-type matter is resolved.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Short notice: So far #222 is ready for review and completely integrated the Subject type and a AsSubject trait into the old code base. It may went unnoticed with all the async rewriting process.

Copy link
Collaborator

@caspervonb caspervonb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @stevelr, appreciate the test driving, feedback and PRs! 😁

LGTM

@Jarema Jarema merged commit 716d706 into nats-io:main Apr 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants