Skip to content

Conversation

@scottf
Copy link
Contributor

@scottf scottf commented Aug 20, 2025

No description provided.

@scottf scottf requested a review from MauriceVanVeen August 20, 2025 21:15
if (pubStream != null && !pubStream.equals(ackStream)) {
throw new IOException("Expected ack from stream " + pubStream + ", received from: " + ackStream);
if (optAckStream != null && !optAckStream.equals(ackStream)) {
throw new IOException("Expected ack from stream " + optAckStream + ", received from: " + ackStream);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

While I was fixing this code I came across the PublishOptions.getStream() and was confused because there is also getExpectedStream() So I made the name clearer.

* @deprecated Just use null to unset
* Use this variable to unset a stream in publish options.
*/
@Deprecated
Copy link
Contributor Author

@scottf scottf Aug 20, 2025

Choose a reason for hiding this comment

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

The constant is null. Sigh, I blame myself.

public static final long UNSET_LAST_SEQUENCE = -1;

private final String stream;
private final String pubAckStream;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

rename / clarification

private final Duration streamTimeout;
private final String expectedStream;
private final String expectedLastId;
private final String expectedLastMsgId;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

better name for this variable too, also matches the getter

* Gets the name of the stream.
* @return the name of the stream.
*/
@Deprecated
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an internal class, but is public so am deprecating

this.expectedLastMsgId = b.expectedLastMsgId;
this.expectedLastSeq = b.expectedLastSeq;
this.expectedLastSubSeq = b.expectedLastSubSeq;
this.expectedLastSubSeqSubject = b.expectedLastSubSeqSubject;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is new

assertTrue(ee.getCause() instanceof RuntimeException);
assertTrue(ee.getCause().getCause() instanceof IOException);
assertInstanceOf(RuntimeException.class, ee.getCause());
assertInstanceOf(IOException.class, ee.getCause().getCause());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

just cleaning up stuff since I'm already in the test

* @param stream The name of the stream.
* @return The Builder
*/
public Builder pubAckStream(String stream) {
Copy link
Member

Choose a reason for hiding this comment

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

Should this behavior be deprecated maybe?

My understanding is that the server supports Nats-Expected-Stream, and that's the intended way to not persist the message into the stream unless it's what you expect. This is already supported with expectedStream(stream).

stream/pubAckStream will let you persist data in the stream you don't expect, and then error once the PubAck reaches the client?

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 have no idea what the history of this is. Deprecating seems like a good idea since it's pretty worthless to check the expectation after the publish.

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'm also removing the new naming. No point adding anew name if it's just deprecated. Also changing the comment as to why it's deprecated.

expectedLastSubSeq = UNSET_LAST_SEQUENCE;
expectedLastSubSeqSubject = null;
msgId = null;
messageTtl = null;
Copy link
Member

Choose a reason for hiding this comment

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

Was this intentional? The messageTtl shouldn't be an "expected-type" check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So the question is if they are re-using the builder, what fields should be kept. Would they want to continue using the messageTtl on every message for the user? Now that I write it out, maybe they would want the same ttl on every message.
This is just a convenience method anyway as they could always create a new instance for every message. And if it is re-used they can always set over it anyway.
But I'm going to remove clearing messageTtl and update the comment


/**
* @deprecated Prefer pubAckStream(...)
* @deprecated Not a very useful function
Copy link
Member

Choose a reason for hiding this comment

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

Should this suggest to migrate to expectedStream(..) instead?

@scottf scottf changed the base branch from main to server-2-12 August 21, 2025 15:04
@scottf scottf merged commit 546714f into server-2-12 Aug 21, 2025
5 checks passed
@scottf scottf deleted the last-subject-sequence-subject branch August 21, 2025 15:04
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.

2 participants