Giter VIP home page Giter VIP logo

spring-amqp-listener-issue's Introduction

SpringAMQP ConnectionListener Issue example

Sample project to show an issue on SpringAMQP ConnectionListener

Problem

The problem is happening when using CachingConnectionFactory with cache mode CacheMode.CHANNEL. Too see the problem you need to run this app and stop the rabbitmq server, then the method SimpleConnectionListener::onClose is called printing the 'Connection CLOSED' message, but if you start and stop again the method isn't called.

Running

To run the app just use the following command filling the parameters:

./mvnw spring-boot:run -Dspring.rabbitmq.host= -Dspring.rabbitmq.username= -Dspring.rabbitmq.password=

Solution

The class ChannelCachingConnectionProxy has a parameter closeNotified that when connection is closed for the first time it is changed to true, but when the connection is recreated this value still true and for new close events the listener is not triggered. So I added a line on createConnection() method of the class and the problem was solved, see the snippet below.

// spring-amqp/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/CachingConnectionFactory.java

...

@Override
public final Connection createConnection() throws AmqpException {
    Assert.state(!this.stopped, "The ApplicationContext is closed and the ConnectionFactory can no longer create connections.");
    synchronized (this.connectionMonitor) {
        if (this.cacheMode == CacheMode.CHANNEL) {
            if (this.connection.target == null) {
                this.connection.target = super.createBareConnection();
                // invoke the listener *after* this.connection is assigned
                if (!this.checkoutPermits.containsKey(this.connection)) {
                    this.checkoutPermits.put(this.connection, new Semaphore(this.channelCacheSize));
                }
                connection.closeNotified.set(false); // This line was added
                getConnectionListener().onCreate(this.connection);
            }
            return this.connection;

...

spring-amqp-listener-issue's People

Watchers

Marcos Costa Pinto avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.