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 DeliveryModes convenience enum #1063

Merged
merged 1 commit into from
Apr 5, 2022

Conversation

Jalalx
Copy link

@Jalalx Jalalx commented Aug 8, 2021

Proposed Changes

This pull request adds the DeliveryModes convenience class as a helper to prevent developers from hardcoding delivery mode codes using magic numbers.

Types of Changes

What types of changes does your code introduce to this project?

  • Bug fix (non-breaking change which fixes issue #NNNN)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause an observable behavior change in existing systems)
  • Documentation improvements (corrections, new content, etc)
  • Cosmetic change (whitespace, formatting, etc)

Checklist

  • I have read the CONTRIBUTING.md document
  • I have signed the CA (see https://cla.pivotal.io/sign/rabbitmq)
  • All tests pass locally with my changes
  • 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

@michaelklishin
Copy link
Member

Thank you. Besides a bit of work on naming, this looks like a good addition to me.

@Matthew-Davey
Copy link

How about an enum?

public enum DeliveryMode : byte
{
    Transient = 1,
    Persistent = 2
}

@michaelklishin
Copy link
Member

I like @Matthew-Davey's idea. @Jalalx WDYT about using an enum?

@Jalalx
Copy link
Author

Jalalx commented Aug 9, 2021

Using an enum was my initial idea, but then two options should be considered:

  1. Changing IBasicProperties.DeliveryMode from byte to DeliveryModes enum, which introduces a breaking change to user code and touches too many areas.
  2. Leaving IBasicProperties.DeliveryMode as is and just add the new DeliveryModes enum so user can use it. But then, developer should explicitly convert enum values to bytes (personally, I found it annoying 😕).
    public enum DeliveryModes: byte {  Transient = 1, Persistent = 2 };
    // ...
    
    IBasicProperties props = ... // 
    
    // error CS0266: Cannot implicitly convert type 'DeliveryModes' to 'byte'. An explicit conversion exists (are you missing a cast?)
    props.DeliveryMode = DeliveryModes.Transient
    // You have to explicitly convert enum value to byte like this:
    props.DeliveryMode = (byte)DeliveryModes.Transient

That's why I considered going with simple const values in a static DeliveryModes class.

Please let me know what you think.

@bollhals
Copy link
Contributor

bollhals commented Aug 9, 2021

I'd agree with the above statement of @Jalalx .

On the other hand I'm not sure how the usage is divided between the DeliveryMode and the Persistent property. I've personally never used the DeliveryMode. So the benefit for me would be 0.

@Jalalx
Copy link
Author

Jalalx commented Aug 10, 2021

Yes, but I wasn't aware of that property until I see that reference while making this PR 😅 I guess DeliveryMode is there for backward compatibility because removing it would introduce unnecessary breaking changes to existing client code.

@sungam3r
Copy link
Contributor

sungam3r commented Sep 1, 2021

Changing IBasicProperties.DeliveryMode from byte to DeliveryModes enum, which introduces a breaking change to user code and touches too many areas.

But it's acceptable for the next major version. See #1056

@Jalalx
Copy link
Author

Jalalx commented Sep 3, 2021

@sungam3r Does it worth a breaking change? What do you think @michaelklishin?

@bollhals
Copy link
Contributor

bollhals commented Sep 3, 2021

@sungam3r Does it worth a breaking change? What do you think @michaelklishin?

It's not breaking, it's just adding another public class.

Edit: whooops, didn't read the whole comment section, my bad. disregard my comment.

@sungam3r
Copy link
Contributor

sungam3r commented Sep 8, 2021

Does it worth a breaking change?

Why not if v7 is on the way? Nobody likes magic numbers.

@Jalalx
Copy link
Author

Jalalx commented Sep 9, 2021

So, should I drop the DeliveryModes class and introduce a DeliveryModes enum? Is everybody agree on this?

@lukebakken lukebakken added this to the 8.0.0 milestone Mar 8, 2022
@lukebakken lukebakken self-assigned this Mar 8, 2022
@lukebakken lukebakken modified the milestones: 8.0.0, 7.0.0 Mar 8, 2022
@lukebakken lukebakken changed the title add DeliveryModes convenience class add DeliveryModes convenience enum Apr 4, 2022
@lukebakken lukebakken force-pushed the feature/delivery-mode-const branch 2 times, most recently from ca2bf39 to a93d8b1 Compare April 4, 2022 22:38
change NonPersistent const name in DeliveryModes to Transient

Update DeliveryMode to be an enum
@lukebakken lukebakken merged commit 9d32bfc into rabbitmq:main Apr 5, 2022
@lukebakken
Copy link
Contributor

Thank you @Jalalx

lukebakken added a commit that referenced this pull request Apr 5, 2022
Follow-up to #1063
@lukebakken lukebakken mentioned this pull request Apr 5, 2022
@Jalalx Jalalx deleted the feature/delivery-mode-const branch April 9, 2022 17:34
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.

6 participants