rabbitmq / rabbitmq/rabbitmq-java-client
Add option to automatically set User-ID in basicPublish
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.3k
- Forks
- 587
- Avg merge
- 7h 29m
- Merged PRs (30d)
- 41
Description
Is your feature request related to a problem? Please describe.
I am in the process of enabling Validated User-IDs to authorize RPCs.
Here is the example code from the documentation:
AMQP.BasicProperties properties = new AMQP.BasicProperties();
properties.setUserId("guest");
channel.basicPublish("amq.fanout", "", properties, "test".getBytes());
But right now getting the correct user id is kind of complicated. To gain access to the the username I would have to pass it down multiple layers of abstractions and dependency injection, as it is currently only available when creating the connection, not when using it.
Describe the solution you'd like
I would like to enable an option while creating the connection to always use my username as the user ID when publishing a message. Something like this:
connectionFactory.setUsername("bob")
.setPassword("mypassword")
.automaticallySetUserIdToUsername(true);
Alternatively this could be solved by making the username a public attribute of the Connection, so I could solve it like this:
AMQP.BasicProperties properties = new AMQP.BasicProperties();
properties.setUserId(channel.getConnection().getUsername());
channel.basicPublish("amq.fanout", "", properties, "test".getBytes());
This would require me to update a handful of code segments, but would be doable.
Describe alternatives you've considered
No response
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by examining ConnectionFactory, Connection, channel.basicPublish, and AMQP.BasicProperties as referenced in the issue. Determine where the configured username could be retained and how publishing currently handles user IDs. Done means an explicit connection option or accessible username supports setting the publishing User-ID without passing it through application layers, with the relevant behavior covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, rabbitmq
- Domain
- backend-api-design, distributed-systems
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100