如何将参数从骆驼路线传递到命名的名称?

发布于 2025-01-28 14:44:02 字数 876 浏览 3 评论 0原文

我在Spring-Boot上有一个运行骆驼的应用程序。 我想从骆驼路线中将被重试的参数重试。

名字Query:

@NamedQuery(name = "findFailedMessages", query = RawMessageTx.HQL_FIND_FAILED_MESSAGES)
public class RawMessageTx extends BaseEntityWithTransmitStatus implements Serializable {

public static final String HQL_FIND_FAILED_MESSAGES = "SELECT x from RawMessageTx x WHERE x.status = 'FAILED' and x.tryAgain = 1 and x.retriesAttempted <= :retriesAllowed ORDER BY x.created ";

路线:

from("seda:retry_poll_failed_messages").routeId("retry_poll_failed_messages")
    .setHeader("retriesAllowed", constant(retriesAllowed)) 
    .toF("jpa:%s?namedQuery=findFailedMessages&maximumResults=%d", RawMessageTx.class.getName(), 
     maxMessagesPerPollAttempt)
       .split(body())
       .to("direct:anotherEndpoint");

我尝试了不同的事情,它无法正常工作,在此上找不到一个很好的示例。

I have an application running camel on spring-boot.
I want to pass a parameter retriesAllowed to a namedQuery from a camel route.

namedQuery:

@NamedQuery(name = "findFailedMessages", query = RawMessageTx.HQL_FIND_FAILED_MESSAGES)
public class RawMessageTx extends BaseEntityWithTransmitStatus implements Serializable {

public static final String HQL_FIND_FAILED_MESSAGES = "SELECT x from RawMessageTx x WHERE x.status = 'FAILED' and x.tryAgain = 1 and x.retriesAttempted <= :retriesAllowed ORDER BY x.created ";

Route:

from("seda:retry_poll_failed_messages").routeId("retry_poll_failed_messages")
    .setHeader("retriesAllowed", constant(retriesAllowed)) 
    .toF("jpa:%s?namedQuery=findFailedMessages&maximumResults=%d", RawMessageTx.class.getName(), 
     maxMessagesPerPollAttempt)
       .split(body())
       .to("direct:anotherEndpoint");

I tried different things and it does not work and I can't find a good example online on this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤单情人 2025-02-04 14:44:02

这在JPA组件的文档中进行了解释:

参数:此键/值映射用于构建查询
参数。预计将是通用类型的java.util.map
键是给定JPA查询的命名参数

这意味着您必须做类似的事情:

to("jpa:...?parameters=#myMap")

where“ mymap ”是'可提供骆驼注册表。

(除其他)注册这种豆的一种可能是骆驼处理器(当然要在JPA端点之前调用)

public void process(Exchange exchange) throws Exception {
    Map<String, Object> params = Map.of("status", "demo");
    exchange.getContext().getRegistry().bind("myMap", params); 
}

This is explained in the doc of JPA component:

parameters: This key/value mapping is used for building the query
parameters. It is expected to be of the generic type java.util.Map
where the keys are the named parameters of a given JPA query

This means that you have to do something like:

to("jpa:...?parameters=#myMap")

Where "myMap" is the name of a bean of type 'java.util.Map' that is available in Camel registry.

One possible way (among others) to register such bean could be a Camel Processor (to invoke before the jpa endpoint of course)

public void process(Exchange exchange) throws Exception {
    Map<String, Object> params = Map.of("status", "demo");
    exchange.getContext().getRegistry().bind("myMap", params); 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文