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

org.iris_events.asyncapi.parsers.DeadLetterQueueParser Maven / Gradle / Ivy

There is a newer version: 6.1.8
Show newest version
package org.iris_events.asyncapi.parsers;

import java.lang.reflect.Method;
import java.util.Objects;

import org.iris_events.annotations.Message;
import org.iris_events.asyncapi.IrisAnnotationRuntimeException;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.IndexView;

public class DeadLetterQueueParser {

    private static final String MESSAGE_DEAD_LETTER_PARAM = "deadLetter";

    public static String getFromAnnotationClass(Message messageAnnotation) {
        final var deadLetter = messageAnnotation.deadLetter();
        if (Objects.nonNull(deadLetter)) {
            return deadLetter;
        }
        try {
            Method deadLetterMethod = messageAnnotation.annotationType().getMethod(MESSAGE_DEAD_LETTER_PARAM);
            return (String) deadLetterMethod.getDefaultValue();
        } catch (NoSuchMethodException e) {
            throw new IrisAnnotationRuntimeException(
                    String.format("Malformed %s annotation. Does not contain %s parameter default",
                            Message.class.getName(),
                            MESSAGE_DEAD_LETTER_PARAM));
        }
    }

    public static String getFromAnnotationInstance(AnnotationInstance messageAnnotation, IndexView index) {
        return messageAnnotation.valueWithDefault(index, MESSAGE_DEAD_LETTER_PARAM).asString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy