Enterprise application throws unknown protocol tcp exception

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Enterprise application throws unknown protocol tcp exception

shamilds
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
Reply | Threaded
Open this post in threaded view
|

Re: Enterprise application throws unknown protocol tcp exception

Torsten Mielke-2
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
[hidden email]
[hidden email]




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.

Reply | Threaded
Open this post in threaded view
|

Re: Enterprise application throws unknown protocol tcp exception

flou@yahoo-inc.com
Did you try to use localhost, or 127.0.0.1 for broker url?
Reply | Threaded
Open this post in threaded view
|

Re: Enterprise application throws unknown protocol tcp exception

shamilds
In reply to this post by shamilds
Hi guys,

thank you very much for the replies. I manage to read activeMQ messages and pass messages to activeMQ by following http://activemq.2283324.n4.nabble.com/Consume-Topic-messages-from-remote-MDB-ActiveMQ-5-5-1-Glassfish-3-1-1-tp4319980p4323048.html link.

Now i can read and pass messages to activeMQ using a ejb. But when i add my ejb application to ear along with my web application, i cannot deploy the whole ear as a one file. Im getting following error:

WARNING: Error in annotation processing: java.lang.NoClassDefFoundError: org/springframework/beans/factory/BeanNameAware
SEVERE: Exception while deploying the app
java.lang.IllegalArgumentException: Referencing error: This bundle has no bean of name [DocumentProductionExecutive]
        at com.sun.enterprise.deployment.EjbBundleDescriptor.getEjbByName(EjbBundleDescriptor.java:279)
        at com.sun.enterprise.deployment.EjbBundleDescriptor.getEjbByName(EjbBundleDescriptor.java:263)
        at com.sun.enterprise.deployment.node.runtime.EjbNode.setElementValue(EjbNode.java:121)
        at com.sun.enterprise.deployment.node.SaxParserHandler.endElement(SaxParserHandler.java:444)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:601)
        at com.sun.org.apache.xerces.internal.impl.dtd.XMLNSDTDValidator.endNamespaceScope(XMLNSDTDValidator.java:263)
        at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleEndElement(XMLDTDValidator.java:2028)
        at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endElement(XMLDTDValidator.java:901)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1782)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2938)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)

but i can deploy my ejb application without any problems, when i add it to the ear im getting this error. i also add the spring.jar file to my classpath which contains org.springframework.beans.factory.BeanNameAware.class but still the same result.
anybody can help me with this?