void generateConsumeRoutes()

in extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/ConsumeProcessor.java [146:210]


    void generateConsumeRoutes(
            ConsumeRecorder recorder,
            CombinedIndexBuildItem index,
            List<CapabilityBuildItem> capabilities,
            CamelContextBuildItem camelContext) {

        final Collection<AnnotationInstance> consumeAnnotations = index.getIndex().getAnnotations(CONSUME_ANNOTATION);
        if (!consumeAnnotations.isEmpty()) {
            final RuntimeValue<RoutesDefinition> routesDefinition = recorder.createRoutesDefinition();

            final boolean beanCapabilityAvailable = capabilities.stream().map(CapabilityBuildItem::getName)
                    .anyMatch(feature -> CamelCapabilities.BEAN.equals(feature));

            for (AnnotationInstance annot : consumeAnnotations) {
                final AnnotationTarget target = annot.target();
                switch (target.kind()) {
                case METHOD: {
                    final MethodInfo methodInfo = target.asMethod();
                    String uri = null;
                    RuntimeValue<Object> runtimeUriOrEndpoint = null;
                    final ClassInfo declaringClass = methodInfo.declaringClass();
                    String beanName = namedValue(declaringClass);
                    if (beanName == null) {
                        beanName = ConsumeProcessor.uniqueBeanName(declaringClass);
                    }
                    if (annot.value() != null) {
                        uri = annot.value().asString();
                    } else if (annot.value("property") != null) {
                        runtimeUriOrEndpoint = recorder.getEndpointUri(
                                camelContext.getCamelContext(),
                                beanName,
                                findEndpointMethodName(annot.value("property").asString(), declaringClass, new ArrayList<>()));
                    } else {
                        runtimeUriOrEndpoint = recorder.getEndpointUri(
                                camelContext.getCamelContext(),
                                beanName,
                                findEndpointMethodName(methodInfo.name(), declaringClass, new ArrayList<>()));
                    }
                    if (uri == null && runtimeUriOrEndpoint == null) {
                        throw new IllegalStateException("@" + Consume.class.getName() + " on " + methodInfo + " in "
                                + declaringClass.name()
                                + " requires to specify a Camel Endpoint or endpoint URI through one of the following options:\n"
                                + " * via @Consume value, e.g. @Consume(\"direct:myDirect\")\n"
                                + " * via explicit @Consume property parameter, e.g. @Consume(property = \"myUriProperty\") and getMyUriProperty() or getMyUriPropertyEndpoint() in the same class must exist and return a String or org.apache.camel.Endpoint\n"
                                + " * via naming convention: if your @Consume method is called myEvent or onMyEvent then getMyEvent() or getMyEventEndpoint() must exist in the same class and return a String or org.apache.camel.Endpoint\n"
                                + "See https://camel.apache.org/manual/latest/pojo-consuming.html for more details");
                    }
                    if (!beanCapabilityAvailable) {
                        throw new IllegalStateException(
                                "Add camel-quarkus-bean dependency to be able to use @" + Consume.class.getName()
                                        + " on method:"
                                        + methodInfo
                                        + " in " + declaringClass.name());
                    }
                    recorder.addConsumeRoute(camelContext.getCamelContext(), routesDefinition, uri, runtimeUriOrEndpoint,
                            beanName, methodInfo.name());
                    break;
                }
                default:
                    throw new IllegalStateException("Expected method, got " + target.kind() + ": " + target);
                }
            }
            recorder.addConsumeRoutesToContext(camelContext.getCamelContext(), routesDefinition);
        }
    }