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

AddressResolver with DNS or List? #1029

Closed
lmx1989219 opened this issue Jun 20, 2019 · 3 comments · Fixed by #1030
Closed

AddressResolver with DNS or List? #1029

lmx1989219 opened this issue Jun 20, 2019 · 3 comments · Fixed by #1030
Assignees
Milestone

Comments

@lmx1989219
Copy link

lmx1989219 commented Jun 20, 2019

hi,
i found the addresses conf with spring.rabbitmq.addresses=192.168.103.34:5672,192.168.73.129:5672 is not well,because it fixed target rabbitmq server node rather than random a node.
and i could not want to use DnsRecordIpAddressResolver.because it has higher costs.

following code if not set to false,i think more well.because the connect is random

	public RabbitConnectionFactoryBean() {
		this.connectionFactory.setAutomaticRecoveryEnabled(false);
	}
 if (isAutomaticRecoveryEnabled()) {
            // see com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory#newConnection
            AutorecoveringConnection conn = new AutorecoveringConnection(params, fhFactory, addressResolver, metricsCollector);

            conn.init();
            return conn;
        } else {
            List<Address> addrs = addressResolver.getAddresses();
            Exception lastException = null;
            for (Address addr : addrs) {
                try {
                    FrameHandler handler = fhFactory.create(addr);
                    AMQConnection conn = createConnection(params, handler, metricsCollector);
                    conn.start();
                    this.metricsCollector.newConnection(conn);
                    return conn;
                } catch (IOException e) {
                    lastException = e;
                } catch (TimeoutException te) {
                    lastException = te;
                }
            }
@lmx1989219
Copy link
Author

random a address

public RecoveryAwareAMQConnection newConnection() throws IOException, TimeoutException {
        Exception lastException = null;
        List<Address> shuffled = shuffle(addressResolver.getAddresses());

        for (Address addr : shuffled) {
            try {
                FrameHandler frameHandler = factory.create(addr);
                RecoveryAwareAMQConnection conn = createConnection(params, frameHandler, metricsCollector);
                conn.start();
                metricsCollector.newConnection(conn);

@garyrussell
Copy link
Contributor

this.connectionFactory.setAutomaticRecoveryEnabled(false);

Spring AMQP has its own connection recovery mechanism; it existed before the rabbitmq client added connection recovery.

It is best not to use the client recovery; there have been problems with the two mechanisms adversely interacting in the past (hung consumers); we have fixed all known problems, but it's safer to simply turn off the client's recovery mechanism.

The shuffle is interesting; we can add a similar mechanism to this framework.

@garyrussell garyrussell self-assigned this Jun 20, 2019
@garyrussell garyrussell added this to the 2.1.8 milestone Jun 20, 2019
@lmx1989219
Copy link
Author

thank you @garyrussell

garyrussell added a commit to garyrussell/spring-amqp that referenced this issue Jun 20, 2019
Resolves spring-projects#1029

Add `shuffleAddresses` to the `CachingConnectionFactory`.
garyrussell added a commit to garyrussell/spring-amqp that referenced this issue Jun 20, 2019
Resolves spring-projects#1029

Add `shuffleAddresses` to the `CachingConnectionFactory`.
garyrussell added a commit to garyrussell/spring-amqp that referenced this issue Jun 20, 2019
Resolves spring-projects#1029

Add `shuffleAddresses` to the `CachingConnectionFactory`.
artembilan pushed a commit that referenced this issue Jun 20, 2019
Resolves #1029

Add `shuffleAddresses` to the `CachingConnectionFactory`.
artembilan pushed a commit that referenced this issue Jun 20, 2019
Resolves #1029

Add `shuffleAddresses` to the `CachingConnectionFactory`.

# Conflicts:
#	spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/ConnectionFactoryParserTests.java
#	spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/CachingConnectionFactoryTests.java
#	src/reference/asciidoc/whats-new.adoc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants