activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <james.strac...@gmail.com>
Subject Properties URI available for configuring brokers (was Re: spring package problem)
Date Thu, 15 Mar 2007 14:12:36 GMT
On 3/9/07, James Strachan <james.strachan@gmail.com> wrote:
> BTW I'm replying but taking future discussions over to the dev list...
>
>
> On 3/9/07, Javier Leyba <xleyba@gmail.com> wrote:
> > On 3/8/07, James Strachan <james.strachan@gmail.com> wrote:
> > >
> > > BTW it would be pretty useful to have a pure properties files based
> > > way to configure the broker! Fancy starting it off and we can improve
> > > it?
> > >
> >
> >
> > James
> >
> > Well, I need to do it for me so, if it could be useful for others...
> >
> > I know how load properties (grin) could you give some ideas  about how
> > should be the best way to wire properties with Broker setter methods ?
> > Is there an ActiveMQ class to be extended or something else ?
>
> A good class to look at is DefaultBrokerFactory which shows how the
> default URI based configuration works...
>
> http://activemq.apache.org/broker-configuration-uri.html
>
> So if there was a class like that which implements
> BrokerFactoryHandler but then rather than taking the URI as the
> configuration, it took the URI as a location of a properties file (or
> a URL to a properties file such as http://foo.com/my.properties), then
> read it and did some introspection on it.
>
> The code would end up being kinda similar to DefaultBrokerFactory.
>
> Notice this code...
>
>         IntrospectionSupport.setProperties(brokerService, params);
>
> which does the introspection for you. Notice this only works for
> primitive types. So for nested types we often write code like this...
>
>             Map childOptions =
> IntrospectionSupport.extractProperties(options, "memoryManager.");
>             IntrospectionSupport.setProperties(brokerService.getMemoryManager(),
> childOptions);
>
> To allow nesting of properties using dot notation. (We use this all
> over the place when supporting configuration by URI throughout
> ActiveMQ). Then the properties file could include a line...
>
> memoryManager.limit = 10 Mb
>
> Note that we could always just enhance
> IntrospectionSupport.setProperties() to deal with being able to
> auto-detect dot notations and navigate into beans setting properties
> etc. (Please be hour guest if you fancy the challenge) - or failing
> that you could just explicitly configure some complex bean properties
> on BrokerService like consumerUsageManager, memoryManager and so
> forth.
>
> We could add some complex logic for dealing with lists of things. e.g.
>
> transportConnectors.0 = ...
> transportConnectors.1 = ...
> transportConnectors.2 = ...
>
>
> Finally the past piece of the puzzle is the BrokerFactory which has a
> helper method...
>
> BrokerService broker = BrokerFactory.createBroker(someURI);
>
> To wire into that one (we support xbean: and broker: so far as
> schemes), we could add properties as a scheme.
>
> Then folks could do...
>
> BrokerService broker = BrokerFactory.createBroker(new
> URI("properties:somedir/foo.properties");
>
> To add this we just need to add a file called properties in this location...
>
> https://svn.apache.org/repos/asf/activemq/trunk/activemq-core/src/main/resources/META-INF/services/org/apache/activemq/broker/
>
> (if you look in the other files or the BrokerFactory code you'll see
> how it all works)
>
>
> Do let us know if you need any help!

There's not actually very much code required to do this so I went
ahead and did it for you :)

You can now use the URI

properties:foo.properties

where foo.propertes can be a file, a classpath resource or a URL which
is then loaded and used to configure the broker.

Here's a test case...
http://svn.apache.org/repos/asf/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/config/BrokerPropertiesTest.java

Here's an example properties file...
http://svn.apache.org/repos/asf/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/config/broker.properties


More documentation here...
http://cwiki.apache.org/ACTIVEMQ/broker-properties-uri.html
-- 


James
-------
http://radio.weblogs.com/0112098/

Mime
View raw message