Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.8 kB
2
Indexable
Never
@Override
    public void run() {
        Channel channel = null;
        try {
            channel = RabbitMQManager.getChannelPool().getChannel();

            channel.addShutdownListener(cause -> {

                /*
                Obsłuż sobie SMS - POLACZENIE BYLO ALE PADLO
                 */
                System.out.println("RECONNECT");
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                run();
            });
            /*
            Utworzenie kolejki
             */
            channel.queueDeclare(queueName, false, false, true, null);
            channel.exchangeDeclare(exchangeName, BuiltinExchangeType.FANOUT);
            channel.queueBind(queueName,exchangeName,"");

            channel.basicConsume(queueName, autoAck, new RabbitMQConsumer(channel, autoAck));

            logger.info("RabbitMQManager :: " + queueName + " :: start listening...");

        } catch (Exception e) {
            logger.error("QueueListener exception: ", e);

            /*
            Obsłuż sobie SMS -> PODCZAS NAWIAZYWANIA POLACZENIA NIE UDALO SIE
            */

            try {
                if(channel != null)
                    RabbitMQManager.getChannelPool().invalidateObject(channel);
            } catch (Exception exception) {
                //TODO: add logger
                //ThreadPoolManager.getLogger().error("MessageSender connection invalidateObject: ", closeException);
            }

            try {
                Thread.sleep(5000);
            } catch (InterruptedException interruptedException) {
                interruptedException.printStackTrace();
            }

            run();
        }
    }