Skip to content

637: Configurable correlatorId generation for RPCClient #638

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

Merged
merged 3 commits into from
Feb 17, 2020

Conversation

janssk1
Copy link

@janssk1 janssk1 commented Feb 3, 2020

Change-Id: I17d7a214d3336ad6e5fe890857a48b457ea599b6

Proposed Changes

#637

Types of Changes

What types of changes does your code introduce to this project?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes issue #NNNN)
  • [x ] New feature (non-breaking change which adds functionality)
    Did remove the 'getCorrelatorId' method from RpcClient. Since i don't see a use for, did not bother adding compatiblity hacks

Checklist

Put an x in the boxes that apply. You can also fill these out after creating
the PR. If you're unsure about any of them, don't hesitate to ask on the
mailing list. We're here to help! This is simply a reminder of what we are
going to look for before merging your code.

  • I have read the CONTRIBUTING.md document
  • [x ] I have signed the CA (see https://cla.pivotal.io/sign/rabbitmq)
  • [- ] All tests pass locally with my changes
    Tried it. But gave up after a few hours. I don't have time to troubleshoot all environment issues that pop up when trying to run the 'unit' tests
  • [ x] I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in related repositories

Further Comments

Change-Id: I17d7a214d3336ad6e5fe890857a48b457ea599b6
Copy link

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

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

Drive-by comment. I don't know this code, so apologies if this feedback does not make sense for some reason.

@@ -79,12 +80,14 @@
}
};

public static Supplier<String> DEFAULT_CORRELATION_ID_GENERATOR = new IncrementingCorrelationIdGenerator("");

Choose a reason for hiding this comment

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

As-is this static instance may be used by more than one RpcClient instance. In that case Supplier#get may be invoked concurrently, as the synchronized (_continuationMap) block only ensures exclusive access for doCall invocations on the same client. This is a problem because as-is IncrementingCorrelationIdGenerator is not thread-safe.

One option would be to replace int _correlationId with an AtomicInteger (or perhaps more appropriately, an AtomicLong.)

Copy link
Author

Choose a reason for hiding this comment

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

Good catch. This should not be static. Will remove that.

Change-Id: I3bb119f3f7debeb0d45ff81dc9154e26635f03bb
@@ -389,14 +389,6 @@ public String getRoutingKey() {
return _continuationMap;
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a breaking change. The last correlation ID must be kept in some way, likely by keeping the _correlationId property and update it in the synchronized block.

Change-Id: Ib1f90d5a25f1c5db32ff9c838cfbeb35aac5d671
@janssk1 janssk1 requested a review from acogoluegnes February 4, 2020 17:53
Comment on lines +398 to +402
if (_correlationIdGenerator instanceof IncrementingCorrelationIdGenerator) {
return ((IncrementingCorrelationIdGenerator) _correlationIdGenerator).getCorrelationId();
} else {
throw new UnsupportedOperationException();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Not super fan of this code TBH. Maybe keeping a reference to the last correlation ID (a string) and trying to convert it to an integer when getCorrelationId() is called would do the job as well. This is a best-effort approach anyway, but it avoids relying on some implementation.

Copy link
Author

Choose a reason for hiding this comment

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

This is implementation is only there for BW compatiblity, So i don't think it's a problem that it only works for the 'default' id generator. I marked the method as deprecated anyway.

@acogoluegnes acogoluegnes merged commit ebffa3e into rabbitmq:master Feb 17, 2020
@acogoluegnes
Copy link
Contributor

Thanks!

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