Why is zero an Invalid MessageWeight on a Quota Policy?

Not applicable

I'm returning the ratelimit.{name}.available.count as a header value on a call, but I want this particular call to not consume from the quota. However, when I set a MessageWeight of zero, I get the error "Invalid message weight value 0.0".

Is there a reason why we can't use a MessageWeight of zero to allow certain calls to not consume from the quota? This would be very helpful.

Thanks!

Solved Solved
0 3 351
1 ACCEPTED SOLUTION

Not applicable

I just figured it out. I was doing:

context.setVariable("zeroWeight", 0);

which doesn't work, but this does:

context.setVariable("zeroWeight", "0");

View solution in original post

3 REPLIES 3

Where do you see the error, i just tried, it seem to work for me

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Quota async="false" continueOnError="false" enabled="true" name="Quota-1" type="calendar">
    <DisplayName>Quota-1</DisplayName>
    <Properties/>
    <Allow count="100" countRef="request.header.allowed_quota"/>
    <Interval ref="request.header.quota_count">1</Interval>
    <MessageWeight ref="request.queryparam.weight"/>
    <Distributed>false</Distributed>
    <Synchronous>false</Synchronous>
    <TimeUnit ref="request.header.quota_timeout">month</TimeUnit>
    <StartTime>2015-7-6 12:00:00</StartTime>
    <AsynchronousConfiguration>
        <SyncIntervalInSeconds>20</SyncIntervalInSeconds>
        <SyncMessageCount>5</SyncMessageCount>
    </AsynchronousConfiguration>
</Quota>

i pass a queryparam called weight - but it could be any flow variable

Can you paste your policy config?

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Quota async="false" continueOnError="false" enabled="true" name="Per-Hour" type="rollingwindow">
    <DisplayName>Per Hour</DisplayName>
    <Identifier ref="signatureResults.requestLimitId"/>
    <Allow countRef="signatureResults.hourlyRequestLimit"/>
    <Interval>1</Interval>
    <TimeUnit>hour</TimeUnit>
    <AsynchronousConfiguration>
        <SyncIntervalInSeconds>20</SyncIntervalInSeconds>
        <SyncMessageCount>5</SyncMessageCount>
    </AsynchronousConfiguration>
    <MessageWeight ref="zeroWeight"/>
</Quota>

I get the error as the response from the API call:

{
  "fault": {
    "faultstring": "Invalid message weight value 0.0",
    "detail": {
      "errorcode": "policies.ratelimit.InvalidMessageWeight"
    }
  }
}

It also shows as en error when tracing in the proxy editor. Interestingly, I just tried setting it to 1 and I still get an error about an invalid message weight ("Invalid message weight value 1.0"). I'm wondering if message weight doesn't work with rollingwindow quotas or maybe it doesn't work with variables set in a Javascript callout?

Not applicable

I just figured it out. I was doing:

context.setVariable("zeroWeight", 0);

which doesn't work, but this does:

context.setVariable("zeroWeight", "0");