You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by apara <ap...@standardset.com> on 2015/08/18 23:12:16 UTC

Not sure why I get DirectConsumerNotAvailableException: No consumers available on endpoint

So, I essentially have two RouteBuilders.  The MainRouteBuilder uses the
services of the PipelineRouteBuilder to create the routes.  RouteInitializer
is a Spring bean which acts as a controller mainly interfacing with spring
and issuing a new on MainRouteBuilder.

Everything works fine and the application initializes and runs.  At a later
time, however, I want to use the PipelineRouteBuilder directly to create a
route at runtime and configure a ProducerTemplate to point to this new
route.

So, I do something like this:

    public ProducerTemplate newSyncProducerTemplate() {
        try {
            final String
                endpointName =
                    "direct://sync.handle.event" +
syncHandleEndpointCounter++;

            //Add the route to the context
            //
            camelContext
                .addRoutes(
                    new PipelineRouteBuilder(
                        camelContext,
                        order--,
                        endpointName,
                        MainRouteBuilder.DIRECT_ERROR_QUEUE_ENDPOINT_NAME,
                        getPipelineBeanCollection()
                    )
                );

            final ProducerTemplate
                producerTemplate =
                    DefaultProducerTemplate
                        .newInstance(
                            camelContext,
                            endpointName
                        );

            producerTemplate.start();

            return
                producerTemplate;
        }
        catch (final Exception e) {
            throw
                new RuntimeException("Unexpected exception during starting
of producer", e);
        }
    }

The PipelineRouteBuilder has a configure method which looks like this (it
just builds the route from endpointName passed in):

    @Override
    public void configure() throws Exception {
        final RouteDefinition
            routeDefinition =
                from(endpointName)
                .routeId(endpointName)
                .startupOrder(order)
                .errorHandler(
                    deadLetterChannel(
                        deadLetterEndpointName
                    )
                    .useOriginalMessage()
                    .maximumRedeliveries(0)
                );

        //Add the beans
        //
        for (final Object bean : beans)
            routeDefinition.bean(bean);
    }


However, when ever I issue a template.sendBody():

    return
            (EventData)
            template
                .sendBody(
                    producer.getDefaultEndpoint(),
                    ExchangePattern.InOut,
                    data
                );

I always get a:
org.apache.camel.component.direct.DirectConsumerNotAvailableException: No
consumers available on endpoint: Endpoint[direct://sync.handle.event0].  So,
somehow creating a route definition from(endpointName) does not attach the
route to the direct endpoint.

I stepped through the code to see that this occurs inside DirectProducer
when a call on endpoint.getConsumers() returns null, because the key
(direct://sync.handle.event0) is not in the map of consumers for the
endpoint.

Again, using the PipelineRouteBuilder, from within MainRouteBuilder seems to
be working just fine, so I am not sure why it's not working when I just want
to use the PipelineRouteBuilder to create a dynamic route at a later time.

In the MainBuilder, I use the same method to build routes from a vm:// which
are then added to a collection of endpoints and are used in a load balancer
definition:

            for (int i = 0; i < pipelinesCount; i++) {
                //Get the definition
                //
                final String
                    pipelineEndpointDefinition =
                        String
                            .format(
                               
"vm://%s?size=%d&blockWhenFull=true&pollTimeout=%d",
                                newEndpointName(name, i),
                                queueSize,
                                pollTimeout
                            );

                //Define a route for the endpoint
                //
                getContext()
                    .addRoutes(
                        new PipelineRouteBuilder(
                            getContext(),
                            order(),
                            pipelineEndpointDefinition,
                            DIRECT_ERROR_QUEUE_ENDPOINT_NAME,
                            pipelineBeansSupplier.get()
                        )
                    );

                //Add endpoint to our result of pipelines
                //
                result
                    .add(
                        endpoint(pipelineEndpointDefinition)
                    );
            }

The only difference I see is that here, I am using vm:// while in another
case, I am using direct:// I really don't need all the workings of vm:// in
the case where things are failing, so I wanted to use a simple direct://  .  

Any hints of where to look or what I am missing would be greatly
appreciated.

Thanks.
-AP_





--
View this message in context: http://camel.465427.n5.nabble.com/Not-sure-why-I-get-DirectConsumerNotAvailableException-No-consumers-available-on-endpoint-tp5770808.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Not sure why I get DirectConsumerNotAvailableException: No consumers available on endpoint

Posted by apara <ap...@standardset.com>.
So, after reading some more, I decided to add a manual start:

            //Add the route to the context
            //
            camelContext
                .addRoutes(
                    new PipelineRouteBuilder(
                        camelContext,
                        order,
                        endpointName,
                        MainRouteBuilder.DIRECT_ERROR_QUEUE_ENDPOINT_NAME,
                        getPipelineBeanCollection()
                    )
                );

            camelContext.startRoute(endpointName);


Things are working now and in-fact, I see that my context is setup with
autoStartup false:

    <camel:camelContext id="handler-b7cd7848-9cc8-11e4-89d3-123b93f75cba"
autoStartup="false">
    ...

However, I don't recall having to start up the initial set of routes.  I
simply add them to the context and they start up automatically.  Is there
something I am missing?  This seems a bit inconsistent?

Thanks.
-AP_



--
View this message in context: http://camel.465427.n5.nabble.com/Not-sure-why-I-get-DirectConsumerNotAvailableException-No-consumers-available-on-endpoint-tp5770808p5770810.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Not sure why I get DirectConsumerNotAvailableException: No consumers available on endpoint

Posted by apara <ap...@standardset.com>.
When I change the direct:// to vm:// I don't get an error right away, but in
30 seconds I get:

ExchangeTimedOutException: The OUT message was not received within: 30000
millis

So, somehow the route is not attaching to the end point?


Here is the code as it stands now:

    public ProducerTemplate newSyncProducerTemplate() {
        try {
            final String
                endpointName =
                    "vm://sync.handle.event" + syncHandleEndpointCounter++;

            camelContext
                .addRoutes(
                    new PipelineRouteBuilder(
                        camelContext,
                        order--,
                        endpointName,
                        MainRouteBuilder.DIRECT_ERROR_QUEUE_ENDPOINT_NAME,
                        getPipelineBeanCollection()
                    )
                );

            final ProducerTemplate
                producerTemplate =
                    DefaultProducerTemplate
                        .newInstance(
                            camelContext,
                            endpointName
                        );

            producerTemplate.start();

            return
                producerTemplate;


-AP_



--
View this message in context: http://camel.465427.n5.nabble.com/Not-sure-why-I-get-DirectConsumerNotAvailableException-No-consumers-available-on-endpoint-tp5770808p5770809.html
Sent from the Camel - Users mailing list archive at Nabble.com.