0

I have the following listener component:


@Component
public class Receiver {

    @RabbitListener(queues = "fmd-response")
    public void receiveMessage(Response response, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) throws IOException {
        channel.basicAck(tag, false);
    }

    @PreDestroy
    public void preDestroy() {

    }
}

What should be put into preDestroy() in order to close the channel automatically created when loading the component? I need this for reloading the component with JRebel, because on every reload a new channel will be created:


127.0.0.1:54916 (1)
guest       idle    0   250 0               
127.0.0.1:54916 (2)
guest       idle    0   250 0               
127.0.0.1:54916 (3)
guest       idle    0   250 0               
127.0.0.1:54916 (4)
guest       idle    0   250 0               
127.0.0.1:54916 (5)
guest       idle    0   250 0               
127.0.0.1:54916 (6)
guest       idle    0   250 0
Andras Hatvani
  • 4,346
  • 4
  • 29
  • 45

1 Answers1

0

I am not familiar with JRebel; the channel for a consumer is long-lived and will be closed automatically when the container is stopped().

Perhaps the container is not stopped when the reload occurs?

Turn on DEBUG logging to see the activity for the container/consumer/channel.

If it's not clear from that, post the complete DEBUG log someplace like a github gist or pastebin.

You could get a reference to the RabbitListenerEndpointRegistry and try stopping the container by id (give the @RabbitListener an id).

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • I've put `registry.getListenerContainers().forEach(Lifecycle::stop);` in `@PreDestroy` but it had no effect, so I assume that JRebel doesn't properly destroy the bean. – Andras Hatvani Dec 17 '18 at 09:13