I am trying to use camel-sql component with the option of useIterator=true but the result still gets loaded in one single big list. I have 2 million records to be processed and getting the resultset in one list is not an option. Below is the route configuration:
<route id="sql_route">
<from uri="activemq:MW_SQL"/>
<to uri="sql:SELECT ID, MSGID_PROD FROM amq.activemq_msgs?useIterator=true"/>
<log message="This data is = ${body}"/>
</route>
From sourcecode it is clear that camel takes the whole resultset in list and then creates iterator of the same. Wrong design.
The option useIterator is only for the consumer, eg when you use sql in the <from>. The sql component on the producer side do not support a iterative based.
You can use the JDBC component instead that supports this by setting OutputType=StreamList: http://camel.apache.org/jdbc
I logged a ticket to add support for this in the future in the SQL component: https://issues.apache.org/jira/browse/CAMEL-9849
Related
I want to log the select query before calling database for better readability of log for reference. I am using mybatis component. I want to know, if there is any inbuilt camel header or mybatis component header can be used log the query.
**CAMEL ROUTE**
from("timer://pollTheDatabase?delay=50s")
.routeId("db-pooling-route")
.to("mybatis:queryToSelectData?statementType=SelectOne");
**MAPPER**
#Mapper
public interface DBMapper{
public void queryToSelectData();
}
**MAPPER XML**
<select id="queryToSelectData" resultMap="Result">
SELECT * FROM ACCOUNT AND ROWNUM =1
</select>
I have a very brief knowledge of the mybatis component, so my answer might not be exact! Camel does not give an inbuilt option to capture the mybatis query. You only have an option to get the statement name. However, could you please log the body just before sending the query and check?
If the body doesn't have the query string, this is how I would do it. In order to get the query string, you could implement a bean where you would need to import the mybatis mapper file and extract the information you require. You could then write it to the log from the bean itself, or you could add it to the Exchange properties.
I have a Camel route which calls a web service, and one of the parameters this service expects is a URL parameter containing a list of values, ie. p1 in myhost/myuri?p1=foo&p1=bar.
I am putting that in a toD URI, as the parameter values need to be dynamic, ie. <camel:toD uri="http4://myhost/myuri?p1=foo&p1=bar" > (omitted Camel parameters and variables for brevity's sake).
Camel is converting this to p1=%5Bfoo%2C+bar%5D (url-encoded p1=[foo, bar]), which is not accepted by the backend service. I have no control over this backend service and cannot expect its interface to change in the future.
Is there any way I can force Camel to call the backend service the way I want to, instead of it collecting the parameter with multiple values into an array-like format?
Another approach would be to use CamelHttpQuery header to along with to, not toD endpoint
<setHeader headerName="CamelHttpQuery"><simple>p1=foo&p1=bar</simple></setHeader>
<to uri="http4://myhost/myuri">
For example, I have a query component as below.
<Query query={GET_ALL_TYPES}>
// some code here
</QUERY>
And in another component I also have a query component but I want to use the data which from the GET_ALL_TYPES query as a variable.
<QUERY query={GET_LIST} variable={data}>
// some code here.
</QUERY>
How can I do this? wait a query data come back and make another query in different component?
By the way, i am using Apollo client version 2.1
Thanks.
You can access earlier readed data from cache:
https://www.apollographql.com/docs/react/advanced/caching.html#direct
I want to route the messages to different routes based on the data coming in header parameters.
rest()
.tag("API")
.id("eventRest")
.post("/data").description("Post a new settlement data record")
.consumes("application/json")
.param().type(RestParamType.header).name("channelID").endParam().to("direct:customRoute")
Here If I've the different param then this one should bypass and continue the rest of the flow in my program.
We are building file processing system (web application + stateful) using camel, jms and rest. Multiple user can upload files. There is requirement to show min, max, mean time taken, average no of hits and etc specific to user. This almost inline with route metrics provided by camel. Is there way to collect this route metrics at user level? or should we extended metrics components and its registry to meet our needs.
Added below changes to code to collect metrics.
<!--added to bean context -->
<bean id="policy" class="org.apache.camel.component.metrics.routepolicy.MetricsRoutePolicy"/>
<!-- below changes done to route -->
<route id="prefRate" routePolicyRef="policy">
<from uri="cxfrs://bean://prefRateService?bindingStyle=SimpleConsumer"/>
<log message="Processing username:${headers.username}"/>
<setHeader headerName="HEADER_METRIC_NAME">
<simple>${headers.username}</simple>
</setHeader>
<to uri="log:body?level=INFO"/>
<to uri="bean:fxPrefRateProcessor" />
<to uri="metrics:meter:prefRateCounter"/>
</route>
You can overwrite the name of a metric in the route by setting the MetricsConstants.HEADER_METRIC_NAME header. To get a unique metric per user, just include the unique user name in the metric name. You could do something like this:
.setHeader(MetricsConstants.HEADER_METRIC_NAME, simple("your.metric.name.for.user.${body.user}"))
.to("metrics:meter:your.metric.name");
This would give you per-user metrics. There's some documentation on the apache site that covers the metrics component and how to set variables/values