Hi 

I have created a custom camel compent.

Problem:

I have listed snippets of the relevant code below.  At present, the
first call to the code will return the correct result.   However, on
the second call it seems the Route is not returning i.e the out message
is never sent.  Despite the  asyncCallback.done(false) being completed
as required for a async call.

The diffrence between the first and second call is the below log entry
which only occors on the first call:

27-09-2022 08:29:37.520 [Thread-5] DEBUG route1.log -
dto.EventDto@763c5ea


Configuration of the Route:

@Bean
    public RoutesBuilder ChangeAgentState() {

        return new RouteBuilder() {

            @Override
            public void configure() throws Exception {

                from("direct:webagent")
                        .process(new ChangeAgentStateProcessor())
                        .to("agent-connector:wss://192.168.1.134/agent-
anager/socket.io")
                        .log(LoggingLevel.DEBUG, "${body}");
            }
        };
}

Calling the the route

/**
         * 
         * @param jsonNode
         * @return
         */
        public Mono<JsonNode> changeAgentState(JsonNode jsonNode) {

                //log.debug("parameter in: " + jsonNode);
                Exchange exchange =
ExchangeBuilder                         
.anExchange(producerTemplate.getCamelContext())
                                .withPattern(ExchangePattern.InOut)
                                .withBody(jsonNode)
                                .build();
                

                CompletableFuture<Exchange> future =
producerTemplate.asyncSend("direct:webagent", exchange);

                try {
                        exchange =
CompletableFuture.completedFuture(future.join()).thenApplyAsync(exchnge
-> {

                                log.debug("CompletableFuture
HasBeenSent: " + exchnge.getMessage().getHeader("HasBeenSent"));
                                log.debug("CanonicalName: " +
exchnge.getMessage().getBody().getClass().getCanonicalName());
                                
                                if(log.isDebugEnabled()) {
                                        exchnge.getMessage().getBody(E
ventDto.class).getEvent().forEach( (event,json) -> {
                                                log.debug("EventDto: "
+ event + " " + json);
                                        });
                                }
                
                                if (exchnge.getException() != null) {
                                        log.debug("Exception Message:
" + exchnge.getException().getMessage());
                                        log.debug("Exception Cause" +
exchnge.getException().getCause());
                                }

                                return exchnge;

                        }).get();

                } catch (InterruptedException e) {
                        log.error("InterruptedException: " + e);
                } catch (ExecutionException e) {
                        log.error("ExecutionException: " + e);
                }
                
                JsonNode agent_presence =
exchange.getMessage().getBody(EventDto.class).getEvent().get(AgentSocke
tEvents.AGENT_PRESENCE);
                exchange.setRouteStop(true);

                // Make sure we do no return a null value
                if(agent_presence == null) {                    
                //      exchange.getMessage().getBody(EventDto.class).
getEvent().get(AgentSocketEvents.)
                        agent_presence =
getErrorResponse("Error","Unkmow error occurred");

                }


                return Mono.just(agent_presence);
        }


Thankyou in advance


Reply via email to