activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <>
Subject Re: Using ActiveMQ embedded sever for Testing
Date Tue, 06 Jun 2006 15:41:57 GMT
If you want to run your same code on lots of different JMS providers
then sure using JNDI is one way to solve this. Another is to use a
Spring XML config file to abstract away how you get the

Typically folks seem to have lots of problems using JNDI - which is
why I was recommending you use 1 line of Java code which just works
and solves your problem. You were writing in Java code the code to
create a JNDI context anyway - so really you were already using
ActiveMQ specific Java code to make your ConnectionFactory - which is
why I suggested the one liner that will just work.

But by all means keep on trucking with JNDI - but if you really want
your Java code to not have any runtime dependency on any specific JMS
provider then I'd recommend using a file on the
classpath then just constructing the InitialContext.

There's an example here:

On 6/6/06, drystone <> wrote:
> Maybe I am going about this in the wrong manner but the code that I am trying
> to test is vendor neutral  JMS code.  I am trying to test code that will
> send and receive messages for different implementations of the JMS spec:
> Example of code that I am trying to test:
> Properties properties = could equal JBoss/MQSeries/ActiveMQ properties
> InitialContext initialContext = new InitialContext( properties );
> Queue queue = (Queue) initialContext.lookup( queueName );
> QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory)
>            initialContext.lookup( JBoss/MQSeries/ActiveMQ 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 );
> ...
> similar for receiving JMS messages
> ....
> I do not want to add any ActiveMQ specific code for the above. I was hoping
> that I would be able to build a configuration object, one for each of the
> JMS implementations JBoss/MQSeries/ActiveMQ. These objects would be used
> within the generic JMS code to set the correct values in the JMS objects and
> they would use the configured resources present.  The generic JMS code that
> I have works for both JBoss and QSeries, I would just like a way of testing
> it. I thought that if there was this BrokerService present that would get
> picked up and would be used.
> If I used ConnectionFactory connectionFactory = new
> ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");  this
> would be a different way that I would be accessing a JMS resource instead of
> the generic code above, and by passing the code that my application uses
> therefore not fully testing it.
> I am sorry if I am being stupid but I am new to ActiveMQ and do not fully
> understand how it should work. Should I be swapping out my generic JMS code
> for ActiveMQ code when I am testing application sections that use JMS?
> Thanks for your help.
> D
> --
> View this message in context:
> Sent from the ActiveMQ - User forum at



View raw message