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

[#109]Implement Correlation metadata on Sender OutboundMessages #110

Merged
merged 3 commits into from
Sep 27, 2019
Merged

[#109]Implement Correlation metadata on Sender OutboundMessages #110

merged 3 commits into from
Sep 27, 2019

Conversation

Sage-Pierce
Copy link

Still a work-in-progress, but looking for feedback. Trying to consider an approach that isn't technically backward incompatible due to the now-necessary generic type declaration on the Flux's OutboundMessage correlation metadata type.

@@ -207,19 +207,61 @@ protected Scheduler createScheduler(String name) {
* @see SendOptions#trackReturned(boolean)
*/
public Flux<OutboundMessageResult> sendWithPublishConfirms(Publisher<OutboundMessage> messages, SendOptions options) {
return sendWithCorrelatedPublishConfirms(Flux.from(messages).map(message -> (OutboundMessage<Object>) message), options)
.map(Function.identity());
Copy link
Author

@Sage-Pierce Sage-Pierce Sep 25, 2019

Choose a reason for hiding this comment

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

This is the only part of the changes that are somewhat squint-worthy to me, but necessary to make the compiler happy

Copy link
Member

Choose a reason for hiding this comment

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

the suggestions above will remove the need for such casts, but you'll probably need 2 separate operator implementations, or at least a bit more juggling at the operator level

Copy link
Member

@simonbasle simonbasle left a comment

Choose a reason for hiding this comment

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

I'd try not to force correlationMetadata on current users that don't need it

@@ -23,7 +23,7 @@
/**
* Outbound message meant to be sent by a {@link Sender}.
*/
public class OutboundMessage {
public class OutboundMessage<T> {
Copy link
Member

Choose a reason for hiding this comment

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

rather than force a null correlationMetadata on every user, I'd extend OutboundMessage and put the generic and the field on the subclass (OutboundCorrelatedMessage?)

@@ -19,9 +19,9 @@
/**
* Result of a sent message when using publisher confirm.
*/
public class OutboundMessageResult {
public class OutboundMessageResult<T> {
Copy link
Member

Choose a reason for hiding this comment

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

similarly to the above comment, I'd extract this specificity in a OutboundCorrelatedMessageResult<T>. Then Sender can have methods that take a publisher of OutboundMessage and return Flux<OutboundMessageResult vs methods that take a publisher of OutboundCorrelatedMessage<T> and return Flux<OutboundCorrelatedMessageResult<T>>

public T getCorrelationMetadata() {
return correlationMetadata;
}

@Override
public String toString() {
Copy link
Member

Choose a reason for hiding this comment

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

note: toString should probably reflect new field?

@@ -207,19 +207,61 @@ protected Scheduler createScheduler(String name) {
* @see SendOptions#trackReturned(boolean)
*/
public Flux<OutboundMessageResult> sendWithPublishConfirms(Publisher<OutboundMessage> messages, SendOptions options) {
return sendWithCorrelatedPublishConfirms(Flux.from(messages).map(message -> (OutboundMessage<Object>) message), options)
.map(Function.identity());
Copy link
Member

Choose a reason for hiding this comment

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

the suggestions above will remove the need for such casts, but you'll probably need 2 separate operator implementations, or at least a bit more juggling at the operator level

Copy link
Contributor

@acogoluegnes acogoluegnes left a comment

Choose a reason for hiding this comment

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

This new version integrates much smoother than the first one. I agree with @simonbasle regarding the introduction of 2 sub-classes (e.g. CorrelableOutboundMessage and CorrelableOutboundMessageResult) to make this new feature an opt-in. Users won't carry the empty correlation metadata and won't use a raw type if they don't want to use any correlation. The tricky part will be the operator, but handling the 2 types in there should be doable without too much duplication.

@Sage-Pierce
Copy link
Author

@acogoluegnes @simonbasle Thank you both for the callouts and suggestions 👍 I'll refactor to attempt addressing your comments

@Sage-Pierce
Copy link
Author

Sage-Pierce commented Sep 26, 2019

@acogoluegnes @simonbasle Your recommendations ended up helping me clean these changes up a bit. The main thing that needed generification was the type of OutboundMessage. Once that was generified, nothing outside of type compilation issues needed to be addressed, and I was able to reuse the existing PublishConfirmOperator as-is. I still needed to add new methods for "typed" sends in order to avoid a backward incompatible change (returning Flux<OutboundMessageResult> vs. Flux<OutboundMessageResult<T>>). I believe that makes this changeset now fully backward compatible

@Sage-Pierce
Copy link
Author

The API could be made a bit more strict and restrict users from being able to use their own extensions of OutboundMessage, and only allow OutboundMessage or CorrelableOutboundMessage, but once I realized this approach worked, figured it would be worthwhile to get your opinions on it

@@ -207,19 +207,60 @@ protected Scheduler createScheduler(String name) {
* @see SendOptions#trackReturned(boolean)
*/
public Flux<OutboundMessageResult> sendWithPublishConfirms(Publisher<OutboundMessage> messages, SendOptions options) {
return Flux.from(sendWithTypedPublishConfirms(messages, options));
Copy link
Author

Choose a reason for hiding this comment

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

No longer need the weird type casting here


private final OutboundMessage outboundMessage;
private final T outboundMessage;
Copy link
Author

Choose a reason for hiding this comment

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

Users that don't use special OutboundMessage extensions should still be able to use untyped/raw OutboundMessageResult in backward compatible fashion

Copy link
Member

@simonbasle simonbasle left a comment

Choose a reason for hiding this comment

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

looks far better to me 👍
maybe I would rename the <T> type to something that reflects that there is a type constraint, like <OMSG>, but that's all

Copy link
Contributor

@acogoluegnes acogoluegnes left a comment

Choose a reason for hiding this comment

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

Great, a new feature without breaking anything! My only concern is that people using sendWithPublishConfirms will use raw OutboundMessageResults, but this is acceptable.

I think the plan would be for sendWithPublishConfirms to adopt the same signature as sendWithTypedPublishConfirms in 2.0, and then make sendWithTypedPublishConfirms deprecated, to be removed in 3.0. This would be a breaking change for anyone declaring a variable out of the flux of OutboundMessageResult, unfortunate, but this is what major releases are for.

@acogoluegnes acogoluegnes merged commit 48d3363 into reactor:master Sep 27, 2019
@Sage-Pierce
Copy link
Author

Thanks for the quick feedback and merge turnaround, @acogoluegnes and @simonbasle !

Is there anywhere I can monitor the release timeline for a new version that will have this update in it? Looks like 1.4.0?

@acogoluegnes
Copy link
Contributor

This feature will indeed be in 1.4, which should be released in a few weeks. It should contain #111 as well and anything related to feedback from 1.3.

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.

3 participants