All Downloads are FREE. Search and download functionalities are using the official Maven repository.

co.com.bancolombia.commons.jms.utils.MQQueueUtils Maven / Gradle / Ivy

The newest version!
package co.com.bancolombia.commons.jms.utils;

import co.com.bancolombia.commons.jms.internal.models.MQListenerConfig;
import jakarta.jms.Destination;
import jakarta.jms.JMSContext;
import jakarta.jms.Queue;
import jakarta.jms.TemporaryQueue;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.log4j.Log4j2;

@Log4j2
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class MQQueueUtils {

    public static Destination setupFixedQueue(JMSContext context, MQListenerConfig config) {
        Queue queue = context.createQueue(config.getListeningQueue());
        customize(queue, config);
        if (config.getQmSetter() != null) {
            config.getQmSetter().accept(context, queue);
        }
        return queue;
    }

    public static TemporaryQueue setupTemporaryQueue(JMSContext context, MQListenerConfig config) {
        TemporaryQueue queue = context.createTemporaryQueue();
        customize(queue, config);
        return queue;
    }

    private static  void customize(T queue, MQListenerConfig config) {
        if (config.getQueueCustomizer() != null) {
            try {
                config.getQueueCustomizer().customize(queue);
            } catch (Exception ex) {
                log.warn("Error customizing queue", ex);
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy