activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From drystone <dryst...@mailinator.com>
Subject Re: Using ActiveMQ embedded sever for Testing
Date Tue, 06 Jun 2006 13:33:56 GMT


Thanks for the help but I am still struggling to get it to work. I have
create an object to act as my broker service:

public class ActiveMqEmbeddedServer {
    public static final String DEFAULT_CONNECTOR_URI =
"vm://localhost:8686";
    private BrokerService brokerService = null;
    public ActiveMqEmbeddedServer( String connectorUri ) {
        brokerService = new BrokerService();
        brokerService.setPersistent( false );
        brokerService.addConnector( connectorUri );
        brokerService.start();
    }
    public void addQueue( String queueName ) {
        // Not sure want I am doing here
        String fullQueueName = ActiveMQDestination.QUEUE_QUALIFIED_PREFIX +
queueName;
        ActiveMQDestination destination =
ActiveMQDestination.createDestination( fullQueueName,       
                  ActiveMQDestination.QUEUE_TYPE );
        PolicyEntry policyEntry = new PolicyEntry();
        //policyEntry.configure( new Queue( destination, null, null, null,
null ) );
        policyEntry.setDestination( destination );
        List<PolicyEntry> policyEntries = new ArrayList<PolicyEntry>();
        policyEntries.add( policyEntry );
        PolicyMap policyMap = new PolicyMap();
        policyMap.setPolicyEntries( policyEntries );
        brokerService.setDestinationPolicy( policyMap );
    }
}

I was hoping that this would act as my jms server. I have a JMS sender
object that does

Properties properties = new Properties();
properties.put( Context.INITIAL_CONTEXT_FACTORY,   
          "org.apache.activemq.jndi.ActiveMQInitialContextFactory" );
properties.put( Context.PROVIDER_URL, "vm://localhost:8686");
InitialContext initialContext = new InitialContext( properties );
Queue queue = (Queue) initialContext.lookup( "TestQueue" );
QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory)
initialContext.lookup(   
          "ConnectionFactory" );
QueueConnection queueConnection =
queueConnectionFactory.createQueueConnection();
QueueSession queueSession = queueConnection.createQueueSession( false,   
          Session.AUTO_ACKNOWLEDGE );
QueueSender queueSender = queueSession.createSender( queue )
Message jmsMessage = queueSession.createTextMessage( message.toString() );
queueSender.send( message );
queueConnection.start();
queueSender.close();
queueConnection.stop();

My test looks like this:

public class JmsSendingAndReceivingTest extends TestCase {
    private static final String TEST_MESSAGE = "This is a test message";
    private static final String TEST_QUEUE_NAME = "TestQueue";
    private ActiveMqEmbeddedServer embeddedServer = null;
    private ActiveMqConfiguration configuration = null;
    protected void setUp() throws Exception {
        super.setUp();
        configuration = new ActiveMqConfiguration( "localhost", "8686",
"TestQueue",        
                 ActiveMqConfiguration.Protocol.VM, null );
        embeddedServer = new ActiveMqEmbeddedServer(
configuration.getProvidorUrl()  );
        embeddedServer.addQueue( TEST_QUEUE_NAME );
    }
    public void testSendAndRecieve() throws JmsException {       
        JmsSender jmsSender = new JmsSender( configuration );
        jmsSender.sendMessage( TEST_MESSAGE );
    }
    protected void tearDown() throws Exception {
        super.tearDown();
        embeddedServer.stopService();
    }
}

I was hoping that I would be able to add queues and topics to the broker
server and use them through the normal JMS manner.  Please can you point me
in the right direction.
Thanks for your help,
D
--
View this message in context: http://www.nabble.com/Using-ActiveMQ-embedded-sever-for-Testing-t1736053.html#a4733351
Sent from the ActiveMQ - User forum at Nabble.com.


Mime
View raw message