PDA

View Full Version : Set concurrency from a variable


keenan
08-29-2008, 04:51 AM
Is there a way to use the short-hand notation for a listener container, ex:


<nms:listener-container>
<nms:listener destination="queue.orders" ref="OrderService" method="PlaceOrder"/>
<nms:listener destination="queue.confirmations" ref="ConfirmationLogger" method="Log"/>
</nms:listener-container>


But to set the concurrency value indirectly (from a variable)? I tried the following:

@(appSettingsSource).ResolveVariable('queue.concur rency')
${queue.concurrency}

but neither worked because it seems the value is being treated as a literal and parsed into an integer.

If not, then it's OK. We will continue to use the full object definition of SimpleMessageListenerContainer. I thought I'd ask because the compact notation is certainly easier on the eyes, even more so when using PONOs because you have to use the full notation for the adapter as well.

Mark Pollack
09-02-2008, 10:48 AM
Hi,
Check the ref docs for VariableSource/VariablePlaceholderConfigurer and PropertyPlaceholderConfigurer. These will let you replace values with 'nant' ${foo} style notation. There are some examples of this in the quickstarts apps I believe.

FYI, I've been thinking to support a short-hand to <property name="foo" expression="SpEL expression"/> which is <property name="foo" expression="%{Spel}"/> so that we can put the use of SpEL everywhere, not just in property values, which is what will be done in Spring Java 3.0 as they are introducing an expression language.

Cheers,
Mark

keenan
09-02-2008, 02:45 PM
Hi,
Check the ref docs for VariableSource/VariablePlaceholderConfigurer and PropertyPlaceholderConfigurer. These will let you replace values with 'nant' ${foo} style notation. There are some examples of this in the quickstarts apps I believe.


Yes, I've used these successfully for other parts of our configuration but I think this might be a special case.

For example, when I look at the RemotingNamespaceParser.cs class, many of the methods end with:


IConfigurableObjectDefinition cod = parserContext.ReaderContext.ObjectDefinitionFactor y.CreateObjectDefinition(
typeName, null, parserContext.ReaderContext.Reader.Domain);
cod.PropertyValues = properties;
return cod;


where properties is of Type MutablePropertyValues and is populated with the attribute values of the element in question. Without diving into the code I assume that the CreateObjectDefinition method works in conjunction with a property placeholder instance (if one is configured) to resolve the value of the properties.

However, for MessageListenerContainerObjectDefinitionParser.cs the ParseConcurrency method is:


private int[] ParseConcurrency(XmlElement ele, ParserContext parserContext)
{
string concurrency = ele.GetAttribute(CONCURRENCY_ATTRIBUTE);
if (!StringUtils.HasText(concurrency))
{
return null;
}
try
{
return new int[] {1, Int32.Parse(concurrency)};
}
catch (FormatException ex)
{
parserContext.ReaderContext.ReportException(ele, CONCURRENCY_ATTRIBUTE,
"Invalid concurrency value [" + concurrency + "]: only " +
"integer (e.g. \"5\") values upported.", ex);
return null;
}
}


I believe this means that whatever literal text is the value of the concurrency attribute will end up in the Int32.Parse statement, with no variable resolution. Is that correct?


FYI, I've been thinking to support a short-hand to <property name="foo" expression="SpEL expression"/> which is <property name="foo" expression="%{Spel}"/> so that we can put the use of SpEL everywhere, not just in property values, which is what will be done in Spring Java 3.0 as they are introducing an expression language.


I think this is an excellent idea and would prove useful!

Mark Pollack
09-03-2008, 09:39 PM
Hi,
Yup, you are correct about the property placeholder not working with the nms namespace parser. Funny that this didn't come up in the Java version. I've created a JIRA issue (http://jira.springframework.org/browse/SPRNET-1019) for it so it gets addressed for the RC1 release and will also raise this to get it included in the Java version.
Cheers,
Mark