Skip to content

property file-based initialization #324

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

Closed
rabbit-hunter opened this issue Oct 30, 2017 · 12 comments
Closed

property file-based initialization #324

rabbit-hunter opened this issue Oct 30, 2017 · 12 comments
Assignees
Milestone

Comments

@rabbit-hunter
Copy link

This is a feature request for the RabbitMQ Java library.

It would be useful if we could initialize the ConnectionFactory via a properties file. Now, whenever we want to set a new configuration property, we have to change the code to call the setter. It would be more convenient if we just could alter the properties file.

You could take Hikari as an example, see https://github.com/brettwooldridge/HikariCP#initialization. A java.util.properties file can be provided. Whenever we want to alter the configuration, we just update the properties file, without being forced to alter the code.

// Examines both filesystem and classpath for .properties file
HikariConfig config = new HikariConfig("/some/path/hikari.properties");
HikariDataSource ds = new HikariDataSource(config);
@michaelklishin
Copy link
Contributor

This can work for a limited number of (common) settings. I'm not sure what can be done about e.g. collections — should command separated lines be used?

And some values, e.g. a SocketConfigurator, would not be supported by this.

@acogoluegnes WDYT?

@acogoluegnes
Copy link
Contributor

@michaelklishin Seems to me like a good idea. Like you said, we won't be able to support all the options (e.g. SocketConfigurator, ExceptionHandler) and have to use some conventions (e.g. comma-separated for URLs), but overall it should be straightforward.

@acogoluegnes acogoluegnes self-assigned this Oct 31, 2017
@acogoluegnes acogoluegnes added this to the 4.4.0 milestone Oct 31, 2017
@rrrrrrrrramba
Copy link

+1 for this, this would be very useful

@rrrrrrrrramba
Copy link

I will try to verify this in the next days.

acogoluegnes added a commit that referenced this issue Nov 9, 2017
@rrrrrrrrramba
Copy link

rrrrrrrrramba commented Nov 9, 2017

I did a quick test with 4.4.0-SNAPSHOT as of today.

I replaced following working code:

        final ConnectionFactory f = new ConnectionFactory();

        try {
            f.setUri("amqp://user:password@localhost:5672/vhost");
        } catch (Exception) {
            e.printStackTrace();
        }
        return f.newConnection();

by

        final ConnectionFactory f = new ConnectionFactory();
        final Properties p = new Properties();

        p.setProperty("uri", "amqp://user:password@localhost:5672/vhost");
        f.load(p);

        return f.newConnection();

Now I am getting:

java.net.ConnectException: Connection refused (Connection refused)

I did not do any further analysis so far.

Any idea?

acogoluegnes added a commit that referenced this issue Nov 9, 2017
@rrrrrrrrramba
Copy link

Please ignore previous comment. I did not see that there was a default prefix. Now, when setting rabbitmq.uri instead of uri, it works!

@michaelklishin
Copy link
Contributor

@rrrrrrrrramba see the Networking guide. The best way to diagnose this kind of feature is to fire up a VisualVM or a debugger in your IDE and inspect ConnectionFactory object state directly.

@rrrrrrrrramba
Copy link

@michaelklishin I wasn't providing an uri, see previous comment. So it was probably falling back to some default credentials, which aren't allowed on my host (standard 3.6.x Docker image).

@rrrrrrrrramba
Copy link

@acogoluegnes FYI, I finished my tests, based on commit cb03deefea17364ed5d5631666734dc00142aae5 and it all seems to work fine!

@rrrrrrrrramba
Copy link

Will this also be merged in the 5.x master branch?

@michaelklishin
Copy link
Contributor

All 4.x changes that can go into 5.x, will.

@rrrrrrrrramba
Copy link

Great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants