On Tue, Jul 8, 2008 at 7:45 PM, yanhongsan <[EMAIL PROTECTED]> wrote:

> Thank you brian! I am very happy to communicate with you! Do you known the
> broker clustering by program not with the  xml file?

Attached is an example of programmatic configuration for ActiveMQ that
I was just doing the other day. Hopefully this is what you're seeking.

Bruce
-- 
perl -e 'print unpack("u30","D0G)[EMAIL 
PROTECTED]&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'

Apache ActiveMQ - http://activemq.org/
Apache Camel - http://activemq.org/camel/
Apache ServiceMix - http://servicemix.org/

Blog: http://bruceblog.org/
package org.bsnyder.amq.config;

import java.io.File;
import java.net.URI;

import junit.framework.TestCase;

import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TransportConnector;
import org.apache.activemq.broker.jmx.ManagementContext;
import org.apache.activemq.store.amq.AMQPersistenceAdapter;
import org.apache.activemq.usage.MemoryUsage;
import org.apache.activemq.usage.StoreUsage;
import org.apache.activemq.usage.SystemUsage;
import org.apache.activemq.usage.TempUsage;

public class AppTest extends TestCase
{
    BrokerService broker = new BrokerService();

    protected void setUp() throws Exception {
        // Create an ActiveMQ broker 
        broker.setBrokerName("test-broker");
        broker.setPersistent(true);
        broker.setDataDirectory("target/test-amq-data");
        
        // Don't start up JMX 
        ManagementContext mgmtCtx = new ManagementContext();
        mgmtCtx.setCreateConnector(false);
        broker.setManagementContext(mgmtCtx);
        
        // Create a transport connector 
        URI brokerUri = new URI("tcp://localhost:41414");
        TransportConnector connector = broker.addConnector(brokerUri);
        connector.setBrokerService(broker);
        connector.setName("openwire");
        connector.setDiscoveryUri(new URI("multicast://default"));
        
        // Create an AMQStore persistence adapter 
        File dataFileDir = new File("target/test-amq-data/amq");
        AMQPersistenceAdapter adaptor = new AMQPersistenceAdapter();
        adaptor.setDirectory(dataFileDir);
        broker.setPersistenceAdapter(adaptor);
        broker.setDeleteAllMessagesOnStartup(true);
        
        // Configure the SystemUsage 
        SystemUsage systemUsage = new SystemUsage();
        MemoryUsage memoryUsage = new MemoryUsage();
        memoryUsage.setLimit(new Long(20).longValue());
        systemUsage.setMemoryUsage(memoryUsage);
        
        StoreUsage storeUsage = new StoreUsage();
        storeUsage.setLimit(new Long(1000).longValue());
        systemUsage.setStoreUsage(storeUsage);
        
        TempUsage tmpUsage = new TempUsage();
        tmpUsage.setLimit(new Long(100).longValue());
        systemUsage.setTempUsage(tmpUsage);
        
        // Start the broker 
        broker.start();
    }

    protected void tearDown() throws Exception {
        if (broker.isStarted()) {
            broker.stop();
        }
    }

    public AppTest( String testName ) {
        super( testName );
    }
    
    public void test() throws Exception {
        // TODO: Add a producer and a consumer to conduct a smoke test
    }
}

Reply via email to