在 Apache Camel Quarkus 中配置缓存过期时间

问题描述 投票:0回答:1

我正在 quarkus 中使用 apache Camel,并且在一定时间后启用缓存删除,但我无法删除它,即我使用属性camel.component.caffeine-cache.expire-after-access-time 和camel.component。咖啡因 - 在属性中缓存 .expire-after-write-time ,但是我正在测试它,在设置 60 秒的时间后,查询仍然在缓存中完成:

#cache
camel.component.caffeine-cache.expire-after-write-time=60
camel.component.caffeine-cache.expire-after-access-time=60

下午 2:00 进行 1 号测试:

enter image description here

查询缓存:

CamelCaffeineActionHasResult =true

enter image description here

下午 2:04 进行的第 2 次测试,在这种混乱中,自缓存以来已经过去了 240 秒:

enter image description here

继续查询缓存:

CamelCaffeineActionHasResult =true

enter image description here

造成这种行为的原因是什么?难道在过期时间(60秒)之后就不能在缓存之外再次查询服务了吗?

这就是我最终配置 ResRoute 的方式

@ApplicationScoped
public class ResRoute extends RouteBuilder {

    @ConfigProperty(name = "client.findIndividualCustomerByDocId")
    String findIndividualCustomerByDocId;
    @ConfigProperty(name = "client.findOrganizacionCustomerByDocId")
    String findOrganizacionCustomerByDocId;
    @ConfigProperty(name = "path.openapi")
    String pathOpenapi;
    @ConfigProperty(name = "descripcion.servicio")
    String descripcionServicio;
    private ConfigureSsl configureSsl;
    private static final String SALIDA_BSS_EXCEPTION = "Salida del microservicio BSS FindCustomerByDocId ${exchangeProperty[bodyRs]}";
    private static final String MSG_EXCEPTION = "Descripcion de la Exception: ${exception.message}";

    public ResRoute() {
        configureSsl = new ConfigureSsl();
    }

    @Override
    public void configure() throws Exception {

        BeanDate beanDate= new BeanDate();
        getContext().getRegistry().bind("BeanDate",beanDate);
        restConfiguration()
                .bindingMode(RestBindingMode.json)
                .dataFormatProperty("json.in.disableFeatures", "FAIL_ON_UNKNOWN_PROPERTIES")
                .apiContextPath(pathOpenapi)
                .apiProperty("api.title", "FindCustomerByDocId")
                .apiProperty("api.description", descripcionServicio)
                .apiProperty("api.version", "1.0.0")
                .apiProperty("cors", "true");

        rest("customerInformation/v1.4.0/users/")
                .get("/{user_id}/customers").to("direct:/{user_id}/customers")
                .outType(Customer.class)
                .param().name("FindCustomerByDocIdResponse").type(body).description("parametro de salida").required(true)
                .endParam()
                .to("direct:pipeline");

        from("direct:pipeline")
                .doTry()
                .process(new FindCustomerByDocIdProcessorReq())
                .log("\n[${bean:BeanDate.getCurrentDateTime()}] "+"User ID: ${exchangeProperty[userId]}")
                .log("\n[${bean:BeanDate.getCurrentDateTime()}] "+"Correlator ID: ${exchangeProperty[correlatorId]}")
                .log("\n[${bean:BeanDate.getCurrentDateTime()}] "+"Tipo de Documento (Num): ${exchangeProperty[documentTypeNum]}")
                .log("\n[${bean:BeanDate.getCurrentDateTime()}] "+"Tipo de Cliente: ${exchangeProperty[customerType]}")
                .choice()
                .when(simple("${exchangeProperty[customerType]} == 'NATURAL'"))
                .process(new FindIndividualCustomerByDocIdProcessorReq())
                .setHeader(CaffeineConstants.ACTION, constant(CaffeineConstants.ACTION_GET))
                .setHeader(CaffeineConstants.KEY).exchangeProperty("documentNumber")
                .toF("caffeine-cache://%s", "IndividualCache")
                .log("Hay Resultado en Cache de la consulta asociado al siguiente documento: ${exchangeProperty[userId]} ${header.CamelCaffeineActionHasResult}}")
                .log("CamelCaffeineActionSucceeded: ${header.CamelCaffeineActionSucceeded}")
                .choice().when(header(CaffeineConstants.ACTION_HAS_RESULT).isEqualTo(Boolean.FALSE))
                    .to(configureSsl.setupSSLContext(getCamelContext(), findIndividualCustomerByDocId))
                    .setHeader(CaffeineConstants.ACTION, constant(CaffeineConstants.ACTION_PUT))
                    .setHeader(CaffeineConstants.KEY).exchangeProperty("documentNumber")
                    .toF("caffeine-cache://%s", "IndividualCache")
                    .process(new FindIndividualCustomerByDocIdProcessorRes())
                    .log("\n[${bean:BeanDate.getCurrentDateTime()}] "+"Salida del microservicio FindIndividualCustomerByDocId ${exchangeProperty[findIndividualCustomerByDocIdResponse]}")
                    .log("\n[${bean:BeanDate.getCurrentDateTime()}] "+"Salida del microservicio BSS FindCustomerByDocId ${exchangeProperty[findCustomerByDocIdResponse]}")
                .otherwise()
                    .log("Cache is working")
                    .process(new FindIndividualCustomerByDocIdProcessorRes())
                .log("\n[${bean:BeanDate.getCurrentDateTime()}] "+"Salida del microservicio FindIndividualCustomerByDocId ${exchangeProperty[findIndividualCustomerByDocIdResponse]}")
                .log("\n[${bean:BeanDate.getCurrentDateTime()}] "+"Salida del microservicio BSS FindCustomerByDocId ${exchangeProperty[findCustomerByDocIdResponse]}")
                .when(simple("${exchangeProperty[customerType]} == 'JURIDICO'"))
                .process(new FindOrganizationCustomerByDocIdProcessorReq())
                .to(configureSsl.setupSSLContext(getCamelContext(), findOrganizacionCustomerByDocId))
                .process(new FindOrganizationCustomerByDocIdProcessorRes())
                /*.log("\n["+getCurrentDate()+"]"+"Entrada del microservicio FindOrganizationCustomerByDocId ${exchangeProperty[findOrganizationCustomerByDocIdRequest]}") */
                .log("\n[${bean:BeanDate.getCurrentDateTime()}] "+"Salida del microservicio FindOrganizationCustomerByDocId ${exchangeProperty[findOrganizationCustomerByDocIdResponse]}")
                .log("\n[${bean:BeanDate.getCurrentDateTime()}] "+"Salida del microservicio BSS FindCustomerByDocId ${exchangeProperty[findCustomerByDocIdResponse]}")
                .endChoice()
                .endDoTry()
                .doCatch(RequiredValueException.class)
                .process(new FindCustomerByDocIdProcessorInvalidFormatException())
                .log("\n[${bean:BeanDate.getCurrentDateTime()}] "+MSG_EXCEPTION)
                .log("\n[${bean:BeanDate.getCurrentDateTime()}] "+SALIDA_BSS_EXCEPTION)
                .doCatch(HttpHostConnectException.class)
                .process(new FindCustomerByDocIdProcessorHttpHostConectionException())
                .log("\n[${bean:BeanDate.getCurrentDateTime()}] "+MSG_EXCEPTION)
                .log("\n[${bean:BeanDate.getCurrentDateTime()}] "+SALIDA_BSS_EXCEPTION)
                .doCatch(NotFoundDataException.class)
                .process(new FindCustomerByDocIdProcessorInformationSubscriber())
                .log("\n[${bean:BeanDate.getCurrentDateTime()}] "+MSG_EXCEPTION)
                .log("\n[${bean:BeanDate.getCurrentDateTime()}] "+SALIDA_BSS_EXCEPTION)
                .doCatch(UnknownHostException.class)
                .process(new FindCustomerByDocIdProcessorHttpHostConectionException())
                .log("\n[${bean:BeanDate.getCurrentDateTime()}] "+MSG_EXCEPTION)
                .log("\n[${bean:BeanDate.getCurrentDateTime()}] "+SALIDA_BSS_EXCEPTION)
                .doCatch(NoHttpResponseException.class)
                .process(new FindCustomerByDocIdProcessorHttpHostConectionException())
                .log("\n[${bean:BeanDate.getCurrentDateTime()}] "+MSG_EXCEPTION)
                .log("\n[${bean:BeanDate.getCurrentDateTime()}] "+SALIDA_BSS_EXCEPTION)
                .doCatch(Exception.class)
                .process(new FindCustomerByDocIdProcessorException())
                .log("\n[${bean:BeanDate.getCurrentDateTime()}] "+MSG_EXCEPTION)
                .log("\n[${bean:BeanDate.getCurrentDateTime()}] "+SALIDA_BSS_EXCEPTION);
    }
}
caching apache-camel quarkus
1个回答
0
投票

配置选项:

camel.component.caffeine-cache.expire-after-write-time
camel.component.caffeine-cache.expire-after-access-time

仅当

evictionType
选项设置为
TIME_BASED
时适用。默认为
SIZE_BASED
。因此
write-time
access-time
将不起作用。

您可以像这样配置驱逐类型:

camel.component.caffeine-cache.eviction-type = TIME_BASED

请参阅 Camel Caffeine 组件文档:

https://camel.apache.org/components/next/caffeine-cache-component.html#_component_option_evictionType

https://camel.apache.org/components/next/caffeine-cache-component.html#_sb_option_camel_component_caffeine-loadcache_eviction-type

© www.soinside.com 2019 - 2024. All rights reserved.