activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From szeldon <szel...@o2.pl>
Subject Re: How to run ActiveMq server from Java code.
Date Fri, 30 Jul 2010 15:59:26 GMT

Thanks, this works great. Nonetheless I have a problem. Problem with
connecting to a queue that was created from the code. How to achieve this?
My code looks like this and it throws Exception in thread "main"
javax.naming.NameNotFoundException: queueName in line with context lookup of
queue:


        BrokerService brokerService = new BrokerService();
        brokerService.addConnector("tcp://localhost:61616");
        brokerService.setBrokerName("Broker");
        brokerService.setUseJmx(true);
        brokerService.start();
        
        brokerService.getAdminView().addQueue("queueName");

        Context jndiContext = new InitialContext();
        jndiContext.addToEnvironment(Context.INITIAL_CONTEXT_FACTORY,
                "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
        jndiContext.addToEnvironment(Context.PROVIDER_URL,
"tcp://localhost:61616");
        QueueConnectionFactory queueConnectionFactory =
(QueueConnectionFactory) jndiContext
                .lookup("QueueConnectionFactory");
        Queue queue = (Queue) jndiContext.lookup("queueName");
        QueueConnection queueConnection =
queueConnectionFactory.createQueueConnection();
        QueueSession queueSession =
queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        QueueSender queueSender = queueSession.createSender(queue);
        TextMessage textMessage =
queueSession.createTextMessage("requestContent");



Johan Edstrom-3 wrote:
> 
> BrokerService broker = new BrokerService();
>         // configure the broker
>         broker.addConnector("tcp://localhost:61616");
>         broker.setBrokerName("Broker1");
>         broker.setUseJmx(false);
>         broker.start();
> 
> On Jul 27, 2010, at 2:51 PM, szeldon wrote:
> 
>> 
>> Hi,
>> 
>> I'm working on an application that uses JMS among other transport
>> technologies. There are TestNG tests for much of the code. I want to
>> create
>> unit tests for JMS invocations. For this, I need to start a JMS server
>> inside my unit tests. How to achieve this using ActiveMq? I was looking
>> for
>> an answer for two days and I couldn't find anything appropriate.
>> 
>> Best regards,
>> szeldon
>> -- 
>> View this message in context:
>> http://old.nabble.com/How-to-run-ActiveMq-server-from-Java-code.-tp29280567p29280567.html
>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>> 
> 
> Johan Edstrom
> 
> joed@opennms.org
> 
> They that can give up essential liberty to purchase a little temporary
> safety, deserve neither liberty nor safety.
> 
> Benjamin Franklin, Historical Review of Pennsylvania, 1759
> 
> 
> 
> 
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/How-to-run-ActiveMq-server-from-Java-code.-tp29280567p29307537.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Mime
View raw message