Search code examples
apache-camelspring-camelapache-camel-3

Exchange.NOTIFY_EVENT exchange option deprecated in camel 3.4 and looking for alternative


I have been using the Exchange.NOTIFY_EVENT option in the producer template as below within the exchange create event under event notifier to not to call the exchange create event again and it was working fine when i was using camel 2.24 core but now since i upgraded to camel 3.4.0, its no more working. looks like Exchange.NOTIFY_EVENT option is deprecated.

String response = (String) producerTemplate.sendBodyAndProperty("event",
                        ExchangePattern.InOut, inputPayload, Exchange.NOTIFY_EVENT, Boolean.TRUE);

can someone please let me know what is alternative in camel 3.4 which is equivalent to Exchange.NOTIFY_EVENT? It would be really appreciated if someone provide some insight on this!..

Updated:10/28/2020:

I see that Exchange.NOTIFY_EVENT has been deprecated and moved this to new exchange called ExtendedExchange. now this exchange can be adapted to ExtendedExchange and can set the notifyEvent method as below.

exchange.adapt(ExtendedExchange.class).setNotifyEvent(true);

but problem is not yet solved. here is the current code.

CamelContext context = exchange.getContext();
ProducerTemplate producerTemplate = context.createProducerTemplate();
Object obj = producerTemplate.sendBodyAndProperty("event",
                        ExchangePattern.InOut, inputPayload, Exchange.NOTIFY_EVENT, Boolean.TRUE);

I am already inside the exchangeCreated notification by using EventNotifierSupport and i want to call another route which should not create notification again. Thats why i used to call this way by setting exchange.NOTIFY_EVENT property. Since sendBodyAndProperty method created new exchange and set the property to not to notify.

but now document says, we need to adapt the exchange to extendedExchange and set notifyEvent to true in it. My question here is, since exchange is created internally if we used sendBodyAndProperty method, how can we adapt for extendedExchange.

how can we do it? can someone please help me to solve this? do we have any alternate approach to do this?


Solution

  • Finally i found one solution to solve this issue but not sure whether we have any other easy way to solve it. However, i would go with this for time being.

    we just need to set this flag to not to notify but this method is in extendedContext which is newly introduced as part of camel 3 and above. I am using camel 3.4

    camelContextExtended.setEventNotificationApplicable(false);

    Below is the full code

    CamelContext context = exchange.getContext();
    
    ModelCamelContext camelContext = context.adapt(ModelCamelContext.class);
    ExtendedCamelContext camelContextExtended =context.adapt(ExtendedCamelContext.class);
    
    camelContextExtended.setEventNotificationApplicable(false);
    
    ProducerTemplate producerTemplate = context.createProducerTemplate();
    Object obj = producerTemplate.sendBodyAndProperty("event",
                            ExchangePattern.InOut, inputPayload, Exchange.NOTIFY_EVENT, Boolean.TRUE);
    
    camelContextExtended.setEventNotificationApplicable(true);
    

    Hope this would help to someone in future.