activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Torsten Mielke <>
Subject Re: Enterprise application throws unknown protocol tcp exception
Date Mon, 06 Feb 2012 09:27:50 GMT

I have not used Glassfish yet but can provide some pointers.
First of all there is no need to create queues or topics upfront in ActiveMQ. But it does
not harm either. Destinations get created automatically by the broker on first usage.  
Then you use

> props.setProperty(Context.PROVIDER_URL,"tcp://");

Rather than using for the hostname, specify the real hostname where the broker runs,
e.g. localhost (in case it runs locally). 

Although you set
> props.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.apache.activemq.jndi.ActiveMQInitialContextFactory");

this does not seem to be picked up correctly at runtime, given the error msg and the 
> com.sun.jndi.cosnaming

stack trace. 
Did you already have a look at 
It mentions that you need a file on your client side classpath.

In case you don't really need to use JNDI, you could simplify your code to

javax.jms.ConnectionFactory connectionFactory = new org.apache.activemq.ActiveMQConnectionFactory("tcp://localhost:61616");
javax.jms.TopicConnection conn = factory.createTopicConnection();
javax.jms.TopicSession session =

javax.jms.Destination mytopic = session.createTopic("ActiveMQ.Test.VRMTopic");

MessageProducer producer = session.createProducer(mytopic);
TextMessage mesg = session.createTextMessage("Text message!");

This example got rid of all JNDI code. 

Hope this helps.

Torsten Mielke

On Feb 3, 2012, at 7:03 PM, shamilds wrote:

> Hi all,
> Im new to ActiveMQ and glassfish configurations. Im trying to run ActiveMQ
> as a separate application and listening to tcp:// connections.
> The use an ejb application to connect to tcp:// url and send
> messages to myTopic.
> First i started the activeMQ. it starts successfully, then login to admin
> panel and created a topic call myTopic. The im trying to send messages to
> this topic using an ejb. Here is my ejb code:
> Properties props = new Properties();           
> props.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
> props.setProperty(Context.PROVIDER_URL,"tcp://");
> javax.naming.Context ctx = new InitialContext(props);
> javax.jms.TopicConnectionFactory factory =
> (javax.jms.TopicConnectionFactory)ctx.lookup("ConnectionFactory");
> javax.jms.TopicConnection conn = factory.createTopicConnection();
> javax.jms.Topic mytopic =
> (javax.jms.Topic)ctx.lookup("ActiveMQ.Test.VRMTopic");
> javax.jms.TopicSession session =
> conn.createTopicSession(false,TopicSession.AUTO_ACKNOWLEDGE);
> producer = session.createProducer(mytopic);
> TextMessage mesg = session.createTextMessage("Text message!");
> producer.send(mesg);
> When i try to call this function it throws me following exception:
> Caused by: javax.naming.ConfigurationException: Invalid URL:
> tcp:// [Root exception is
> Unknown protocol: tcp]
>        at com.sun.jndi.cosnaming.CNCtx.getStringifiedIor(
>        at
> com.sun.jndi.cosnaming.CNCtx.initOrbAndRootContext(
>        at com.sun.jndi.cosnaming.CNCtx.<init>(
>        at
> com.sun.jndi.cosnaming.CNCtxFactory.getInitialContext(
> I tried this one with file as well. but same result.
> Im using glassfish 3.0.1 as ejb container
> java 1.6
> ActiveMQ 5.4.3
> can anybody help me..
> many thanks
> --
> View this message in context:
> Sent from the ActiveMQ - User mailing list archive at

View raw message