Skip to content

NIFI-14117 - PublishKafka should send default attribute as key if cus…#9608

Merged
exceptionfactory merged 2 commits intoapache:mainfrom
greyp9:NIFI-14117
Jan 6, 2025
Merged

NIFI-14117 - PublishKafka should send default attribute as key if cus…#9608
exceptionfactory merged 2 commits intoapache:mainfrom
greyp9:NIFI-14117

Conversation

@greyp9
Copy link
Contributor

@greyp9 greyp9 commented Dec 31, 2024

…tom attribute not specified

Summary

NIFI-14117

Tracking

Please complete the following tracking steps prior to pull request creation.

Issue Tracking

Pull Request Tracking

  • Pull Request title starts with Apache NiFi Jira issue number, such as NIFI-00000
  • Pull Request commit message starts with Apache NiFi Jira issue number, as such NIFI-00000

Pull Request Formatting

  • Pull Request based on current revision of the main branch
  • Pull Request refers to a feature branch with one commit containing changes

Verification

Please indicate the verification steps performed prior to pull request creation.

Build

  • Build completed using mvn clean install -P contrib-check
    • JDK 21

Licensing

  • New dependencies are compatible with the Apache License 2.0 according to the License Policy
  • New dependencies are documented in applicable LICENSE and NOTICE files

Documentation

  • Documentation formatting appears as expected in rendered files

Copy link
Contributor

@exceptionfactory exceptionfactory left a comment

Choose a reason for hiding this comment

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

Thanks for addressing this issue and adding the test @greyp9. One minor recommendation is to move the key attribute selection logic to the constructor, instead of the getKey method invocation. Otherwise this looks good.

@Override
public byte[] getKey(final Map<String, String> attributes, final Record record) throws UnsupportedEncodingException {
final String keyAttributeValue = (keyAttribute == null) ? null : attributes.get(keyAttribute);
final String keyAttributeEffective = (keyAttribute == null) ? KafkaFlowFileAttribute.KAFKA_KEY : keyAttribute;
Copy link
Contributor

Choose a reason for hiding this comment

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

For clarity, it looks like this logic could be handled in the constructor, instead of on every method invocation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks; sure. Believe it or not, I went back and forth about which style was better :)

Copy link
Contributor

@exceptionfactory exceptionfactory left a comment

Choose a reason for hiding this comment

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

Thanks for making the adjustment @greyp9, looks good! +1 merging

@exceptionfactory exceptionfactory merged commit 1ae31c3 into apache:main Jan 6, 2025
6 checks passed
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