Table of Contents
Question content
Workaround
Home Java Spring amqp - No compatible authentication mechanism found - providing server

Spring amqp - No compatible authentication mechanism found - providing server

Feb 14, 2024 am 08:50 AM

php editor Xinyi introduces to you today Spring AMQP, which is a messaging framework based on the AMQP protocol. However, sometimes when using Spring AMQP, we may encounter an error: "No compatible authentication mechanism found - providing server". This error message can be confusing and you don't know how to solve it. Next, we will explain the cause of this error in detail and provide solutions to help everyone use the Spring AMQP framework smoothly.

Question content

I am trying to connect a spring boot application to rabbit mq via an external authentication mechanism (https://github.com/rabbitmq/rabbitmq-auth-mechanism-ssl) .

I get the following error:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

org.springframework.amqp.amqpioexception: java.io.ioexception: no compatible authentication mechanism found - server offered []

    at org.springframework.amqp.rabbit.support.rabbitexceptiontranslator.convertrabbitaccessexception(rabbitexceptiontranslator.java:70) ~[spring-rabbit-3.0.5.jar:3.0.5]

    at org.springframework.amqp.rabbit.connection.abstractconnectionfactory.createbareconnection(abstractconnectionfactory.java:594) ~[spring-rabbit-3.0.5.jar:3.0.5]

    at org.springframework.amqp.rabbit.connection.cachingconnectionfactory.createconnection(cachingconnectionfactory.java:687) ~[spring-rabbit-3.0.5.jar:3.0.5]

    at org.springframework.amqp.rabbit.connection.connectionfactoryutils.createconnection(connectionfactoryutils.java:257) ~[spring-rabbit-3.0.5.jar:3.0.5]

    at org.springframework.amqp.rabbit.core.rabbittemplate.doexecute(rabbittemplate.java:2225) ~[spring-rabbit-3.0.5.jar:3.0.5]

    at org.springframework.amqp.rabbit.core.rabbittemplate.execute(rabbittemplate.java:2198) ~[spring-rabbit-3.0.5.jar:3.0.5]

    at org.springframework.amqp.rabbit.core.rabbittemplate.execute(rabbittemplate.java:2178) ~[spring-rabbit-3.0.5.jar:3.0.5]

    at org.springframework.amqp.rabbit.core.rabbitadmin.getqueueinfo(rabbitadmin.java:459) ~[spring-rabbit-3.0.5.jar:3.0.5]

    at org.springframework.amqp.rabbit.core.rabbitadmin.getqueueproperties(rabbitadmin.java:443) ~[spring-rabbit-3.0.5.jar:3.0.5]

    at org.springframework.amqp.rabbit.listener.abstractmessagelistenercontainer.attemptdeclarations(abstractmessagelistenercontainer.java:1891) ~[spring-rabbit-3.0.5.jar:3.0.5]

    at org.springframework.amqp.rabbit.listener.abstractmessagelistenercontainer.redeclareelementsifnecessary(abstractmessagelistenercontainer.java:1858) ~[spring-rabbit-3.0.5.jar:3.0.5]

    at org.springframework.amqp.rabbit.listener.simplemessagelistenercontainer$asyncmessageprocessingconsumer.initialize(simplemessagelistenercontainer.java:1384) ~[spring-rabbit-3.0.5.jar:3.0.5]

    at org.springframework.amqp.rabbit.listener.simplemessagelistenercontainer$asyncmessageprocessingconsumer.run(simplemessagelistenercontainer.java:1230) ~[spring-rabbit-3.0.5.jar:3.0.5]

    at java.base/java.lang.thread.run(thread.java:833) ~[na:na]

caused by: java.io.ioexception: no compatible authentication mechanism found - server offered []

    at com.rabbitmq.client.impl.amqconnection.start(amqconnection.java:343) ~[amqp-client-5.17.0.jar:5.17.0]

    at com.rabbitmq.client.connectionfactory.newconnection(connectionfactory.java:1225) ~[amqp-client-5.17.0.jar:5.17.0]

    at com.rabbitmq.client.connectionfactory.newconnection(connectionfactory.java:1173) ~[amqp-client-5.17.0.jar:5.17.0]

    at org.springframework.amqp.rabbit.connection.abstractconnectionfactory.connectaddresses(abstractconnectionfactory.java:632) ~[spring-rabbit-3.0.5.jar:3.0.5]

    at org.springframework.amqp.rabbit.connection.abstractconnectionfactory.connect(abstractconnectionfactory.java:607) ~[spring-rabbit-3.0.5.jar:3.0.5]

    at org.springframework.amqp.rabbit.connection.abstractconnectionfactory.createbareconnection(abstractconnectionfactory.java:557) ~[spring-rabbit-3.0.5.jar:3.0.5]

    ... 12 common frames omitted

Copy after login

Dependencies:

1

2

3

4

5

<dependency>

                <groupid>org.springframework.boot</groupid>

                <artifactid>spring-boot-starter-amqp</artifactid>

                <version>3.2.1</version>

            </dependency>

Copy after login

rabbitmq version: rabbitmq:3.12.1-management

rabbitmq.conf contains these properties:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

default_user=guest

default_pass=guest

listeners.tcp=none

listeners.ssl.default=5672

ssl_options.cacertfile=/etc/rabbitmq/cert/ca_bundle.pem

ssl_options.certfile=/etc/rabbitmq/cert/certificate.pem

ssl_options.keyfile=/etc/rabbitmq/cert/key.pem

ssl_options.password=pass

ssl_options.verify=verify_peer

ssl_options.fail_if_no_peer_cert=true

ssl_options.versions.1=tlsv1.2

ssl_options.depth=1

auth_mechanisms.1=external

ssl_cert_login_from=common_name

Copy after login

Application Properties:

1

2

3

4

5

6

7

8

spring.rabbitmq.ssl.enabled=true

spring.rabbitmq.ssl.algorithm=tlsv1.2

spring.rabbitmq.ssl.key-store=keystore.p12

spring.rabbitmq.ssl.key-store-password=pass

spring.rabbitmq.ssl.key-store-type=pkcs12

spring.rabbitmq.ssl.trust-store=truststore.p12

spring.rabbitmq.ssl.trust-store-password=pass

spring.rabbitmq.ssl.trust-store-type=pkcs12

Copy after login

I declared the following method to include the sasl configuration:

1

2

3

4

5

6

7

8

9

10

11

@Bean

  public AmqpTemplate amqpTemplate(ConnectionFactory connectionFactory) {

    CachingConnectionFactory cachingConnectionFactory = (CachingConnectionFactory) connectionFactory;

    cachingConnectionFactory.getRabbitConnectionFactory().setAutomaticRecoveryEnabled(true);

    cachingConnectionFactory.getRabbitConnectionFactory().setSaslConfig(DefaultSaslConfig.EXTERNAL);

    cachingConnectionFactory.resetConnection();

 

    RabbitTemplate rabbitTemplate = new RabbitTemplate(cachingConnectionFactory);

    rabbitTemplate.setMessageConverter(converter());

    return rabbitTemplate;

  }

Copy after login

Workaround

I'm not sure what the listeners.ssl.default=5672 is on the rabbitmq config side, but it sounds like you're overwriting the default ssl port to that .

The logic in spring boot is as follows:

1

return (optional.ofnullable(getssl().getenabled()).orelse(false)) ? default_port_secure : default_port;

Copy after login

Place:

1

private static final int default_port_secure = 5671;

Copy after login

Therefore, you may want to consider providing the port explicitly:

1

spring.rabbitmq.port=5672

Copy after login

You may not need to customize the rabbittemplate bean either, just add connectionfactorycustomizer to set defaultsaslconfig.external to the auto-configured com .rabbitmq.client.connectionfactory.

It is also not recommended to use setautomaticrecoveryenabled(true): https://www.php.cn/link/3c0de3fec9ab8a3df01109251f137119

The above is the detailed content of Spring amqp - No compatible authentication mechanism found - providing server. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1655
14
PHP Tutorial
1253
29
C# Tutorial
1227
24