Search in sources :

Example 1 with GroupedExchangeAggregationStrategy

use of org.apache.camel.processor.aggregate.GroupedExchangeAggregationStrategy in project camel by apache.

the class AggregateDefinition method createAggregationStrategy.

private AggregationStrategy createAggregationStrategy(RouteContext routeContext) {
    AggregationStrategy strategy = getAggregationStrategy();
    if (strategy == null && strategyRef != null) {
        Object aggStrategy = routeContext.lookup(strategyRef, Object.class);
        if (aggStrategy instanceof AggregationStrategy) {
            strategy = (AggregationStrategy) aggStrategy;
        } else if (aggStrategy != null) {
            AggregationStrategyBeanAdapter adapter = new AggregationStrategyBeanAdapter(aggStrategy, getAggregationStrategyMethodName());
            if (getStrategyMethodAllowNull() != null) {
                adapter.setAllowNullNewExchange(getStrategyMethodAllowNull());
                adapter.setAllowNullOldExchange(getStrategyMethodAllowNull());
            }
            strategy = adapter;
        } else {
            throw new IllegalArgumentException("Cannot find AggregationStrategy in Registry with name: " + strategyRef);
        }
    }
    if (groupExchanges != null && groupExchanges) {
        if (strategy != null || strategyRef != null) {
            throw new IllegalArgumentException("Options groupExchanges and AggregationStrategy cannot be enabled at the same time");
        }
        if (eagerCheckCompletion != null && !eagerCheckCompletion) {
            throw new IllegalArgumentException("Option eagerCheckCompletion cannot be false when groupExchanges has been enabled");
        }
        // set eager check to enabled by default when using grouped exchanges
        setEagerCheckCompletion(true);
        // if grouped exchange is enabled then use special strategy for that
        strategy = new GroupedExchangeAggregationStrategy();
    }
    if (strategy == null) {
        throw new IllegalArgumentException("AggregationStrategy or AggregationStrategyRef must be set on " + this);
    }
    if (strategy instanceof CamelContextAware) {
        ((CamelContextAware) strategy).setCamelContext(routeContext.getCamelContext());
    }
    return strategy;
}
Also used : CamelContextAware(org.apache.camel.CamelContextAware) GroupedExchangeAggregationStrategy(org.apache.camel.processor.aggregate.GroupedExchangeAggregationStrategy) GroupedExchangeAggregationStrategy(org.apache.camel.processor.aggregate.GroupedExchangeAggregationStrategy) AggregationStrategy(org.apache.camel.processor.aggregate.AggregationStrategy) AggregationStrategyBeanAdapter(org.apache.camel.processor.aggregate.AggregationStrategyBeanAdapter)

Example 2 with GroupedExchangeAggregationStrategy

use of org.apache.camel.processor.aggregate.GroupedExchangeAggregationStrategy in project webcert by sklintyg.

the class NotificationRouteBuilder method configure.

/*
     * The second half of this route, sendNotificationToWS, is supposed to be used with redelivery. The
     * route depends on the MQ provider (currently ActiveMQ) for redelivery. Any temporary exception thrown
     * by any component in this route is NOT handled by the route, but triggers a transaction rollback in the
     * MQ provider. The MQ provider will then, if properly configured, put the message back into the queue after
     * the proper redelivery wait time has passed.
     *
     * Any permanent exception is handled by the route, however, and will NOT trigger a redelivery.
     */
@Override
public void configure() throws JAXBException {
    JaxbDataFormat jaxbMessageDataFormatV3 = initializeJaxbMessageDataFormatV3();
    // Start for aggregation route. All notifications enter this route. Draft saved and signed for non fk7263
    // goes into an aggregation state where we once per minute perform filtering so only the newest ANDRAD per
    // intygsId
    // forwarded to the 'receiveNotificationRequestEndpoint' queue. The others are discarded.
    // Do note that the above only applies to non-fk7263 ANDRAD, all others will be forwarded directly.
    from(notificationForAggregationQueue).routeId("aggregateNotification").onException(Exception.class).to("direct:temporaryErrorHandlerEndpoint").end().transacted().choice().when(header(NotificationRouteHeaders.INTYGS_TYP).isEqualTo(Fk7263EntryPoint.MODULE_ID)).to(notificationQueue).when(directRoutingPredicate()).to(notificationQueue).otherwise().wireTap("direct:signatWireTap").aggregate(new GroupedExchangeAggregationStrategy()).constant(true).completionInterval(batchAggregationTimeout).forceCompletionOnStop().to("bean:notificationAggregator").split(body()).to(notificationQueue).end().end();
    // The wiretap is used to directly forward SIGNAT messages (see INTYG-2744) to the send queue while the original
    // SIGNAT is passed on into the aggregation phase. The aggregation phase never emits any SIGNAT, only ANDRAT.
    from("direct:signatWireTap").choice().when(header(NotificationRouteHeaders.HANDELSE).isEqualTo(HandelsekodEnum.SIGNAT.value())).to(notificationQueue).end();
    // All routes below relate to pre WC 5.0 notification sending, e.g. all that enters
    // 'receiveNotificationRequestEndpoint'
    // should have normal resend semantics etc. Reads from the notificationQueue.
    from("receiveNotificationRequestEndpoint").routeId("transformNotification").onException(TemporaryException.class).to("direct:temporaryErrorHandlerEndpoint").end().onException(Exception.class).handled(true).to("direct:permanentErrorHandlerEndpoint").end().transacted().unmarshal("notificationMessageDataFormat").to("bean:notificationTransformer").choice().when(header(NotificationRouteHeaders.VERSION).isEqualTo(SchemaVersion.VERSION_3.name())).marshal(jaxbMessageDataFormatV3).otherwise().marshal("jaxbMessageDataFormat").end().to("sendNotificationWSEndpoint");
    from("sendNotificationWSEndpoint").routeId("sendNotificationToWS").errorHandler(transactionErrorHandler().logExhausted(false)).onException(TemporaryException.class).to("direct:temporaryErrorHandlerEndpoint").end().onException(Exception.class).handled(true).to("direct:permanentErrorHandlerEndpoint").end().transacted().choice().when(header(NotificationRouteHeaders.VERSION).isEqualTo(SchemaVersion.VERSION_3.name())).unmarshal(jaxbMessageDataFormatV3).to("bean:notificationWSClientV3").otherwise().unmarshal("jaxbMessageDataFormat").to("bean:notificationWSClient").end();
    from("direct:permanentErrorHandlerEndpoint").routeId("errorLogging").log(LoggingLevel.ERROR, LOG, simple("Permanent exception for intygs-id: ${header[intygsId]}, with message: " + "${exception.message}\n ${exception.stacktrace}").getText()).stop();
    from("direct:temporaryErrorHandlerEndpoint").routeId("temporaryErrorLogging").choice().when(header(Constants.JMS_REDELIVERED).isEqualTo("false")).log(LoggingLevel.ERROR, LOG, simple("Temporary exception for intygs-id: ${header[intygsId]}, with message: " + "${exception.message}\n ${exception.stacktrace}").getText()).otherwise().log(LoggingLevel.WARN, LOG, simple("Temporary exception for intygs-id: ${header[intygsId]}, with message: " + "${exception.message}").getText()).stop();
}
Also used : TemporaryException(se.inera.intyg.webcert.common.sender.exception.TemporaryException) GroupedExchangeAggregationStrategy(org.apache.camel.processor.aggregate.GroupedExchangeAggregationStrategy) TemporaryException(se.inera.intyg.webcert.common.sender.exception.TemporaryException) JAXBException(javax.xml.bind.JAXBException) JaxbDataFormat(org.apache.camel.converter.jaxb.JaxbDataFormat)

Aggregations

GroupedExchangeAggregationStrategy (org.apache.camel.processor.aggregate.GroupedExchangeAggregationStrategy)2 JAXBException (javax.xml.bind.JAXBException)1 CamelContextAware (org.apache.camel.CamelContextAware)1 JaxbDataFormat (org.apache.camel.converter.jaxb.JaxbDataFormat)1 AggregationStrategy (org.apache.camel.processor.aggregate.AggregationStrategy)1 AggregationStrategyBeanAdapter (org.apache.camel.processor.aggregate.AggregationStrategyBeanAdapter)1 TemporaryException (se.inera.intyg.webcert.common.sender.exception.TemporaryException)1