You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by garrydias <ga...@gmail.com> on 2012/03/22 16:37:28 UTC

Throttling: maximumRequestsPerPeriod problem

Hi!

I´m trying to use Throttle in my xml CamelContext under 2.9 Camel version,
but when I set the /maximumRequestsPerPeriod/ property my compilation fails
displaying this message:
*cvc-complex-type.3.2.2: Attribute 'maximumRequestsPerPeriod' is not allowed
to appear in element 
	 'camel:throttle'.*

if I delete the /maximumRequestsPerPeriod/ property my route fails at
runtime displaying this message:
*Caused by: java.lang.IllegalStateException: The maximumRequestsPerPeriod
must be a positive number, was: 0*

I can´t solve this problem.

Please. Help.

Thanx

--
View this message in context: http://camel.465427.n5.nabble.com/Throttling-maximumRequestsPerPeriod-problem-tp5586898p5586898.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Throttling: maximumRequestsPerPeriod problem

Posted by garrydias <ga...@gmail.com>.
Yes. It would be nice. I just have to find a free time =/

thank you too much

--
View this message in context: http://camel.465427.n5.nabble.com/Throttling-maximumRequestsPerPeriod-problem-tp5586898p5628534.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Throttling: maximumRequestsPerPeriod problem

Posted by garrydias <ga...@gmail.com>.
One more!

There´s no need to separate the routes due to a throttle nested in a split.
So my first spring xml works.

Thanx too much

regards

--
View this message in context: http://camel.465427.n5.nabble.com/Throttling-maximumRequestsPerPeriod-problem-tp5586898p5599379.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Throttling: maximumRequestsPerPeriod problem

Posted by Christian Müller <ch...@gmail.com>.
Thanks Garry for pointing this out and also sharing your solution. I opened
a JIRA for it.
Do you consider providing a patch for it? In this case, the pages [2] and
[3] could be helpful for you.

[1] https://issues.apache.org/jira/browse/CAMEL-5126
[2] http://camel.apache.org/contributing.html
[3] http://camel.apache.org/building.html

Best,
Christian

On Wed, Mar 28, 2012 at 4:26 AM, garrydias <ga...@gmail.com> wrote:

> I found the problem.
>
>
> It was caused by /garryHeader /header. It was null.
>
>
> In fact, I was sending my body using ProducerTemplate.sendBody(Endpoint
> endpoint, Object body). So /garryHeader /does not exist. I had to debug
> org.apache.camel.processor.Throttler to discover that [1].
>
>
> I don´t think the throwing of *Caused by: java.lang.IllegalStateException:
> The maximumRequestsPerPeriod must be a positive number, was: 0* is a good
> behavior. Camel could at least throw a NPE or some kind of warning. As you
> could see, find the real cause of the problem is not as obvious as it
> should
> be.
>
>
> To permanently solve my IllegalStateException problem, I´m sending my body
> using ProducerTemplate.sendBodyAndHeader(Endpoint endpoint, Object body,
> Object headerKey, Object headerValue) method.
>
>
>
> [1] check the code bellow. If maximumRequestsPerPeriod is null the
> exception
> is thrown:
>
>
> if (maximumRequestsPerPeriod <= 0) {
>
>        throw new IllegalStateException("The maximumRequestsPerPeriod must
> be a positive number, was: " + maximumRequestsPerPeriod);
>
> }
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Throttling-maximumRequestsPerPeriod-problem-tp5586898p5599362.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Throttling: maximumRequestsPerPeriod problem

Posted by garrydias <ga...@gmail.com>.
I found the problem.


It was caused by /garryHeader /header. It was null.


In fact, I was sending my body using ProducerTemplate.sendBody(Endpoint
endpoint, Object body). So /garryHeader /does not exist. I had to debug
org.apache.camel.processor.Throttler to discover that [1].


I don´t think the throwing of *Caused by: java.lang.IllegalStateException:
The maximumRequestsPerPeriod must be a positive number, was: 0* is a good
behavior. Camel could at least throw a NPE or some kind of warning. As you
could see, find the real cause of the problem is not as obvious as it should
be.


To permanently solve my IllegalStateException problem, I´m sending my body
using ProducerTemplate.sendBodyAndHeader(Endpoint endpoint, Object body,
Object headerKey, Object headerValue) method.



[1] check the code bellow. If maximumRequestsPerPeriod is null the exception
is thrown:


if (maximumRequestsPerPeriod <= 0) {

        throw new IllegalStateException("The maximumRequestsPerPeriod must
be a positive number, was: " + maximumRequestsPerPeriod);

}


--
View this message in context: http://camel.465427.n5.nabble.com/Throttling-maximumRequestsPerPeriod-problem-tp5586898p5599362.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Throttling: maximumRequestsPerPeriod problem

Posted by garrydias <ga...@gmail.com>.
i´ll change the route instead, so I can use the *ref* property.

that´s my xml updated:
http://camel.465427.n5.nabble.com/file/n5596345/throttler-test-context.xml
throttler-test-context.xml 

(I´m still setting up the tests)

regards

--
View this message in context: http://camel.465427.n5.nabble.com/Throttling-maximumRequestsPerPeriod-problem-tp5586898p5596345.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Throttling: maximumRequestsPerPeriod problem

Posted by Christian Müller <ch...@gmail.com>.
Yes, I missed this...

Could you also remove the following definitions because you don't use it:

<camel:endpoint id="myBeanProducer"
uri="bean://myBean?method=garryProducer" />
<camel:endpoint id="myBeanConsumer"
uri="bean://myBean?method=garryConsumer" />

Best,
Christian

On Mon, Mar 26, 2012 at 4:10 PM, garrydias <ga...@gmail.com> wrote:

> These namespaces are already declared. The browser you´re using probably
> hides the namespace declarations. If you right click my attached xml and
> choose "Show Source Code" (or something like, depending on your browser)
> the
> namespace will be shown.
>
> I´ll checkout your test and post the results.
>
> thanx again
>
> regards
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Throttling-maximumRequestsPerPeriod-problem-tp5586898p5595328.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Throttling: maximumRequestsPerPeriod problem

Posted by garrydias <ga...@gmail.com>.
These namespaces are already declared. The browser you´re using probably
hides the namespace declarations. If you right click my attached xml and
choose "Show Source Code" (or something like, depending on your browser) the
namespace will be shown.

I´ll checkout your test and post the results.

thanx again

regards

--
View this message in context: http://camel.465427.n5.nabble.com/Throttling-maximumRequestsPerPeriod-problem-tp5586898p5595328.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Throttling: maximumRequestsPerPeriod problem

Posted by Christian Müller <ch...@gmail.com>.
The test also exists in Camel 2.9.1. Check out [1].
In your spring xml you didn't specify a default or the camel namespace
(only the schema location). This could be the issue. Try adding the
attributes:
xmlns="http://www.springframework.org/schema/beans" xmlns:camel="
http://camel.apache.org/schema/spring"

[1]
https://svn.apache.org/repos/asf/camel/tags/camel-2.9.1/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringThrottlerTest.java

Best,
Christian

On Sun, Mar 25, 2012 at 7:16 PM, garrydias <ga...@gmail.com> wrote:

> Still throwing *Caused by: java.lang.IllegalStateException: The
> maximumRequestsPerPeriod must be a positive number, was: 0*.
>
> Are the namespaces in spring xml correct?
>
> Thanks again
>
> regards
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Throttling-maximumRequestsPerPeriod-problem-tp5586898p5593539.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Throttling: maximumRequestsPerPeriod problem

Posted by garrydias <ga...@gmail.com>.
Still throwing *Caused by: java.lang.IllegalStateException: The
maximumRequestsPerPeriod must be a positive number, was: 0*.

Are the namespaces in spring xml correct?

Thanks again

regards

--
View this message in context: http://camel.465427.n5.nabble.com/Throttling-maximumRequestsPerPeriod-problem-tp5586898p5593539.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Throttling: maximumRequestsPerPeriod problem

Posted by Christian Müller <ch...@gmail.com>.
Could you try to split up your route into two and test whether this works?

<camel:route id="defaultRoute">
    <camel:from uri="bean://myBean?method=garryProducer" />
    <camel:split>
        <camel:method bean="myBean" method="split" />
        <to uri="direct:sub" />
    </camel:split>
</camel:route>

<camel:route id="subRoute">
    <camel:from uri="direct:sub" />
    <camel:throttle id="defaultThrottler" timePeriodMillis="1000" >
        <camel:header>garryHeader</camel:header>
        <camel:to uri="bean://myBean?method=garryConsumer" />
    </camel:throttle>
</camel:route>

May be it's an issue when we define a throttler inside a splitter...

Best,
Christian


On Fri, Mar 23, 2012 at 2:45 PM, garrydias <ga...@gmail.com> wrote:

> thanx Christian
>
> this is my spring xml:
>
> http://camel.465427.n5.nabble.com/file/n5589498/throttler-test-context.xml
> throttler-test-context.xml
>
> About your tests, I couldn´t execute it because the some imports in your
> source code make reference to older camel version. An example, the
> org.apache.camel.processor.ThrottlerTest class does not exist in Camel 2.9.
>
> thanx again
>
>
> regards
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Throttling-maximumRequestsPerPeriod-problem-tp5586898p5589498.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Throttling: maximumRequestsPerPeriod problem

Posted by garrydias <ga...@gmail.com>.
thanx Christian

this is my spring xml:

http://camel.465427.n5.nabble.com/file/n5589498/throttler-test-context.xml
throttler-test-context.xml 

About your tests, I couldn´t execute it because the some imports in your
source code make reference to older camel version. An example, the
org.apache.camel.processor.ThrottlerTest class does not exist in Camel 2.9.

thanx again


regards

--
View this message in context: http://camel.465427.n5.nabble.com/Throttling-maximumRequestsPerPeriod-problem-tp5586898p5589498.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Throttling: maximumRequestsPerPeriod problem

Posted by Christian Müller <ch...@gmail.com>.
Could you please provide the complete route to make sure you didn't use the
wrong namespace?
The unit test in [1] use this expression [2] and the test succeed.

[1]
https://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringThrottlerTest.java
[2]
https://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/throttler.xml

Best,
Christian

On Thu, Mar 22, 2012 at 6:06 PM, garrydias <ga...@gmail.com> wrote:

> Yes!
>
> I´ve tried:
>
>
> *<throttle timePeriodMillis="10000">
>         <constant>20</constant>
>          <to uri="mock:result"/>
> </throttle> *
>
>
> and
>
>
> *<throttle timePeriodMillis="10000">
>         <header>garryHeader</header>
>          <to uri="mock:result"/>
> </throttle> *
>
> both are displaying:
> /Caused by: java.lang.IllegalStateException: The maximumRequestsPerPeriod
> must be a positive number, was: 0/
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Throttling-maximumRequestsPerPeriod-problem-tp5586898p5587237.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Throttling: maximumRequestsPerPeriod problem

Posted by garrydias <ga...@gmail.com>.
Yes!

I´ve tried:


*<throttle timePeriodMillis="10000">
         <constant>20</constant>
         <to uri="mock:result"/>
</throttle> *


and


*<throttle timePeriodMillis="10000">
         <header>garryHeader</header>
         <to uri="mock:result"/>
</throttle> *

both are displaying:
/Caused by: java.lang.IllegalStateException: The maximumRequestsPerPeriod
must be a positive number, was: 0/


--
View this message in context: http://camel.465427.n5.nabble.com/Throttling-maximumRequestsPerPeriod-problem-tp5586898p5587237.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Throttling: maximumRequestsPerPeriod problem

Posted by Marco Westermann <Ma...@gmx.de>.
Hi,

did you see, that the syntax changed with camel 2.8:

see: http://camel.apache.org/throttler.html

<throttle timePeriodMillis="10000">
         <constant>3</constant>
         <to uri="mock:result"/>
     </throttle>


regards, Marco


Am 22.03.2012 16:37, schrieb garrydias:
> Hi!
>
> I´m trying to use Throttle in my xml CamelContext under 2.9 Camel version,
> but when I set the /maximumRequestsPerPeriod/ property my compilation fails
> displaying this message:
> *cvc-complex-type.3.2.2: Attribute 'maximumRequestsPerPeriod' is not allowed
> to appear in element
> 	 'camel:throttle'.*
>
> if I delete the /maximumRequestsPerPeriod/ property my route fails at
> runtime displaying this message:
> *Caused by: java.lang.IllegalStateException: The maximumRequestsPerPeriod
> must be a positive number, was: 0*
>
> I can´t solve this problem.
>
> Please. Help.
>
> Thanx
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Throttling-maximumRequestsPerPeriod-problem-tp5586898p5586898.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>