You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Baltej Singh <bs...@ra.rockwell.com> on 2017/01/03 23:30:28 UTC

RE: logging/incrementing simple counter

Dear Quinn
Yes - what you proposed works, but not if you substitute a property for the file path.
Seems like a defect with substituting properties.


1. Following snippet works correctly:  	 
	<from uri="file:c:/temp/in?move=done/${bean:inboundCounter.incrementAndGet}-finished.txt"/>
Copy file testNaming.xml to file:c:/temp/in
Correctly produces file called:  C:\temp\in\done\2-finished.txt


2. But using property: in.path=c:/temp/in
Using DSL:  
       	<from uri="file:{{in.path}}?move=done/${bean:inboundCounter.incrementAndGet}-finished.txt"/>

This produces a folder called:  
	C:\temp\in\done\inboundCounter.incrementAndGet-finished.txt
With file:  testNaming.xml




-----Original Message-----
From: Quinn Stevenson [mailto:quinn@pronoia-solutions.com] 
Sent: Friday, December 30, 2016 9:05 AM
To: users@camel.apache.org
Subject: Re: logging/incrementing simple counter

Can you be a little more specific on how it isn’t working?  I tried a simplified form of your file uri, and it seemed to work fine.

<route>
    <from uri="file:target/data?move=done/${bean:inboundCounter.incrementAndGet}-finished.txt"/>
    <to uri="mock://complete" />
</route>

> On Dec 29, 2016, at 5:42 PM, Baltej Singh <bs...@ra.rockwell.com> wrote:
> 
> Quinn,
> 
> Works great  on its own, but not in the file components move attribute!
>          <from id="_id2" uri="file:{{in.path}}?moveFailed=.failed/$simple{file:onlyname}&amp;move={{archive-from-erp.path}}/${bean:inboundCounter.incrementAndGet}-{{common.fname.pattern}}"/>
> 
> 
> -----Original Message-----
> From: Quinn Stevenson [mailto:quinn@pronoia-solutions.com] 
> Sent: Thursday, December 29, 2016 2:36 PM
> To: users@camel.apache.org
> Subject: Re: logging/incrementing simple counter
> 
> I’d probably use and AtomicLong for this specific use case
> 
> <bean id="execCounter" class="java.util.concurrent.atomic.AtomicLong" />
> 
> <camelContext xmlns="http://camel.apache.org/schema/spring">
>    <route>
>        <from uri="direct://trigger" />
>        <log message="Exec Counter: ${bean:execCounter.incrementAndGet}" />
>    </route>
> </camelContext>
> 
>> On Dec 29, 2016, at 2:49 PM, Baltej Singh <bs...@ra.rockwell.com> wrote:
>> 
>> Following code works, but is there a better way to define the constant 1L in Spring DSL Camel context?
>> 
>> 	<bean class="java.lang.Long" id="longOne">
>> 		<constructor-arg index="0" value="1" />
>> 	</bean>
>> 	<bean class="java.lang.Long" id="execCount">
>> 		<constructor-arg index="0" value="1" />
>> 	</bean>
>> 
>> 
>> 	<log id="_id1"   message="${bean:execCount?method=sum(${bean:execCount.longValue}, ${bean:longOne.longValue})}" />
>> 
>> 
>> 
>> -----Original Message-----
>> From: Baltej Singh 
>> Sent: Thursday, December 29, 2016 12:08 PM
>> To: users@camel.apache.org
>> Subject: RE: logging/incrementing simple counter
>> 
>> Thanks Quin - worked like a charm!
>> 
>> What the recommended way to set the value on this bean?  
>> What are the advantages/disadvantages of using groovy VS ${bean:..} syntax?
> 


RE: logging/incrementing simple counter

Posted by Baltej Singh <bs...@ra.rockwell.com>.
Quinn,

I am using Camel 2.18.1 - 
Here is a simple example that shows the issues with various {{}}, =$simple{file:onlyname} and ${bean:...} combinations

------------fileNaming.properties ------------
trace=false
in.path=c:/temp/in
in.path0=c:/temp/test/in0
in.path1=c:/temp/test/in1
in.path2=c:/temp/test/in2
in.path3=c:/temp/test/in3
archive.path=c:/temp/test/archive/
common.fname.pattern=$simple{file:onlyname}
datetime.fname.pattern=$simple{date:now:yyyy-MM-dd_hh-mm-ss.SSS}-$simple{file:onlyname}
incounter.datetime.fname.pattern=${bean:inboundCounter.incrementAndGet}-$simple{date:now:yyyy-MM-dd_hh-mm-ss.SSS}

----------End fileNaming.properties ------------




<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:camel="http://camel.apache.org/schema/spring" xmlns:p="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
	<bean class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer"
		id="bridgePropertyPlaceholder">
		<p:property name="location" value="classpath:fileNaming.properties" />
	</bean>
	
	<bean class="java.util.concurrent.atomic.AtomicLong" id="inboundCounter" />
	  
	<camelContext id="testFileNamingContext" trace="{{trace}}"
		xmlns="http://camel.apache.org/schema/spring">
		<route id="workingRoute">
			<camel:description>This route produces: C:\temp\test\in\done\0-workingRoute-testNaming.xml</camel:description>
			<from
				uri="file:c:/temp/test/in?moveFailed=.failed/$simple{file:onlyname}&amp;move=done/${bean:inboundCounter.getAndIncrement}-workingRoute-$simple{file:onlyname}" />
			<log message="workingRoute" />
			<to id="_toW" uri="mock://complete" />
		</route>
		<route id="errorRoute0">
			<camel:description>This route produces: C:\temp\test\in0\done\inboundCounter.getAndIncrement-errorRoute0-testNaming.xml </camel:description>
			<from
				uri="file:c:/temp/test/in0?move=done/${bean:inboundCounter.getAndIncrement}-errorRoute0-{{common.fname.pattern}}" />
			<log message="errorRoute0" />
			<to id="_to0" uri="mock://complete" />
		</route>
		
		<route id="errorRoute1">
			<camel:description>This route produces:  C:\temp\test\archive\inboundCounter.getAndIncrement-errorRoute1-testNaming.xml </camel:description>
			<from
				uri="file:{{in.path1}}?moveFailed=.failed/$simple{file:onlyname}&amp;move={{archive.path}}/${bean:inboundCounter.getAndIncrement}-errorRoute1-$simple{file:onlyname}" />
			<log message="errorRoute1" />
			<to id="_to1" uri="mock://complete" />
		</route>
		<route id="errorRoute2">
			<camel:description>This route produces:  C:\temp\test\in2\done\inboundCounter.getAndIncrement-errorRoute2-testNaming.xml</camel:description>
			<from
				uri="file:{{in.path2}}?move=done/${bean:inboundCounter.getAndIncrement}-errorRoute2-{{common.fname.pattern}}" />
			<log message="errorRoute2" />
			<to id="_to2" uri="mock://complete" />
		</route>
				<route id="errorRoute3">
			<camel:description>This route produces: C:\temp\test\archive\inboundCounter.getAndIncrement-errorRoute3-testNaming.xml </camel:description>
			<from
				uri="file:{{in.path3}}?move={{archive.path}}/${bean:inboundCounter.getAndIncrement}-errorRoute3-{{common.fname.pattern}}" />
			<log message="errorRoute3" />
			<to id="_to3" uri="mock://complete" />
		</route>
	</camelContext>
</beans>





-----Original Message-----
From: Quinn Stevenson [mailto:quinn@pronoia-solutions.com] 
Sent: Wednesday, January 04, 2017 9:12 AM
To: users@camel.apache.org
Subject: Re: logging/incrementing simple counter

Can you provide a simple (complete) example?  When I try the following XML with Camel 2.17.3, I get an IllegalArgumentException - so I can’t reproduce your results.


Re: logging/incrementing simple counter

Posted by Quinn Stevenson <qu...@pronoia-solutions.com>.
Can you provide a simple (complete) example?  When I try the following XML with Camel 2.17.3, I get an IllegalArgumentException - so I can’t reproduce your results.

<bean id="bridgePropertyPlaceholder" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
    <property name="location" value="classpath:route-invocation-counter.properties"/>
</bean>

<camelContext xmlns="http://camel.apache.org/schema/spring">

    <route>
        <from uri="file:{{in.path}}?move=done/${bean:inboundCounter.incrementAndGet}-finished.txt"/>
        <to uri="mock://complete"/>
    </route>

</camelContext>


> On Jan 3, 2017, at 4:30 PM, Baltej Singh <bs...@ra.rockwell.com> wrote:
> 
> Dear Quinn
> Yes - what you proposed works, but not if you substitute a property for the file path.
> Seems like a defect with substituting properties.
> 
> 
> 1. Following snippet works correctly:  	 
> 	<from uri="file:c:/temp/in?move=done/${bean:inboundCounter.incrementAndGet}-finished.txt"/>
> Copy file testNaming.xml to file:c:/temp/in
> Correctly produces file called:  C:\temp\in\done\2-finished.txt
> 
> 
> 2. But using property: in.path=c:/temp/in
> Using DSL:  
>       	<from uri="file:{{in.path}}?move=done/${bean:inboundCounter.incrementAndGet}-finished.txt"/>
> 
> This produces a folder called:  
> 	C:\temp\in\done\inboundCounter.incrementAndGet-finished.txt
> With file:  testNaming.xml
> 
> 
> 
> 
> -----Original Message-----
> From: Quinn Stevenson [mailto:quinn@pronoia-solutions.com] 
> Sent: Friday, December 30, 2016 9:05 AM
> To: users@camel.apache.org
> Subject: Re: logging/incrementing simple counter
> 
> Can you be a little more specific on how it isn’t working?  I tried a simplified form of your file uri, and it seemed to work fine.
> 
> <route>
>    <from uri="file:target/data?move=done/${bean:inboundCounter.incrementAndGet}-finished.txt"/>
>    <to uri="mock://complete" />
> </route>
> 
>> On Dec 29, 2016, at 5:42 PM, Baltej Singh <bs...@ra.rockwell.com> wrote:
>> 
>> Quinn,
>> 
>> Works great  on its own, but not in the file components move attribute!
>>         <from id="_id2" uri="file:{{in.path}}?moveFailed=.failed/$simple{file:onlyname}&amp;move={{archive-from-erp.path}}/${bean:inboundCounter.incrementAndGet}-{{common.fname.pattern}}"/>
>> 
>> 
>> -----Original Message-----
>> From: Quinn Stevenson [mailto:quinn@pronoia-solutions.com] 
>> Sent: Thursday, December 29, 2016 2:36 PM
>> To: users@camel.apache.org
>> Subject: Re: logging/incrementing simple counter
>> 
>> I’d probably use and AtomicLong for this specific use case
>> 
>> <bean id="execCounter" class="java.util.concurrent.atomic.AtomicLong" />
>> 
>> <camelContext xmlns="http://camel.apache.org/schema/spring">
>>   <route>
>>       <from uri="direct://trigger" />
>>       <log message="Exec Counter: ${bean:execCounter.incrementAndGet}" />
>>   </route>
>> </camelContext>
>> 
>>> On Dec 29, 2016, at 2:49 PM, Baltej Singh <bs...@ra.rockwell.com> wrote:
>>> 
>>> Following code works, but is there a better way to define the constant 1L in Spring DSL Camel context?
>>> 
>>> 	<bean class="java.lang.Long" id="longOne">
>>> 		<constructor-arg index="0" value="1" />
>>> 	</bean>
>>> 	<bean class="java.lang.Long" id="execCount">
>>> 		<constructor-arg index="0" value="1" />
>>> 	</bean>
>>> 
>>> 
>>> 	<log id="_id1"   message="${bean:execCount?method=sum(${bean:execCount.longValue}, ${bean:longOne.longValue})}" />
>>> 
>>> 
>>> 
>>> -----Original Message-----
>>> From: Baltej Singh 
>>> Sent: Thursday, December 29, 2016 12:08 PM
>>> To: users@camel.apache.org
>>> Subject: RE: logging/incrementing simple counter
>>> 
>>> Thanks Quin - worked like a charm!
>>> 
>>> What the recommended way to set the value on this bean?  
>>> What are the advantages/disadvantages of using groovy VS ${bean:..} syntax?
>> 
>