activemq-users mailing list archives

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

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://0.0.0.0:61616");

Rather than using 0.0.0.0 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 http://activemq.apache.org/jndi-support.html? 
It mentions that you need a jndi.properties 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 =
conn.createTopicSession(false,TopicSession.AUTO_ACKNOWLEDGE);

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

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

This example got rid of all JNDI code. 

Hope this helps.

Torsten Mielke
torsten@fusesource.com
tmielke@blogspot.com




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://0.0.0.0:61616 connections.
> The use an ejb application to connect to tcp://0.0.0.0:61616 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://0.0.0.0:61616");
> 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://0.0.0.0:61616 [Root exception is java.net.MalformedURLException:
> Unknown protocol: tcp]
>        at com.sun.jndi.cosnaming.CNCtx.getStringifiedIor(CNCtx.java:436)
>        at
> com.sun.jndi.cosnaming.CNCtx.initOrbAndRootContext(CNCtx.java:227)
>        at com.sun.jndi.cosnaming.CNCtx.<init>(CNCtx.java:87)
>        at
> com.sun.jndi.cosnaming.CNCtxFactory.getInitialContext(CNCtxFactory.java:32)
> 
> 
> I tried this one with jndi.properties 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: http://activemq.2283324.n4.nabble.com/Enterprise-application-throws-unknown-protocol-tcp-exception-tp4355337p4355337.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Mime
View raw message