participate


Java Message Service (JMS) - JMS Standalone Remote Client. Ho to connect to remote JMS Provider?
This question is answered.

<<   Back to Forum  |   Give us Feedback
This topic has 8 replies on 1 page.
Foli
Posts:9
Registered: 5/30/07
JMS Standalone Remote Client. Ho to connect to remote JMS Provider?   
Apr 7, 2008 5:57 AM
 
 
Hi all. :)

I have on remote PC a GlassFish server.
How to connect from my remote PC in internet to GlassFish?

//[1] Create a JNDI API InitialContext object.
            Hashtable properties = new Hashtable(2);
            properties.put(Context.PROVIDER_URL,"iiop://REMOTE PC:3700");
            properties.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.appserv.naming.S1ASCtxFactory");
            jndiContext = new InitialContext(properties);
                                            
            //[2] Look up connection factory and queue.
            connectionFactory = ConnectionFactory)jndiContext.lookup("jms/tConnectionFactory");
            queue = (Queue)jndiContext.lookup("jms/tQueue");
        
            //[3]
            // - Create connection
            // - Create session from connection; false means session is not transacted.
            // - Create sender and text message.
            // - Send messages, varying text slightly.
            connection = connectionFactory.createConnection("guest", "guest");
            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            messageProducer = session.createProducer(queue);
            TextMessage message = session.createTextMessage("Hello World");
            messageProducer.send(message);


Best Regards
Mike
 
jwenting
Posts:9,735
Registered: 4/17/98
Re: JMS Standalone Remote Client. Ho to connect to remote JMS Provider?   
Apr 7, 2008 7:36 AM (reply 1 of 8)  (In reply to original post )
 
 
yup, something like that.
Check your server docs for more details.
 
Foli
Posts:9
Registered: 5/30/07
Re: JMS Standalone Remote Client. Ho to connect to remote JMS Provider?   
Apr 8, 2008 6:45 AM (reply 2 of 8)  (In reply to #1 )
 
 
Hi guys.

I solved it. :)
I can make a connection to remote JMS Server.

A Client must have:
* glassfish_home/lib/appserv-rt.jar
* glassfish_home/lib/javaee.jar
* glassfish_home/lib/install/applications/jmsra/jmsra.jar
* glassfish_home/lib/install/applications/jmsra/imqbroker.jar
* glassfish_home/imq/lib/imq.jar
* glassfish_home/lib/appserv-admin.jar
* glassfish_home/imq/lib/jms.jar
* glassfish_home/lib/j2ee.jar


a server GlassFish must have a next file:
* glassfish_home/domains/domain1/config/sun-acc.xml
 
<target-server name="PCNameJMSWebServer" address="10.0.0.26" port="3700"/>
In address must be IP address of JMS Server.



Example for send message to remote JMS Server:
Context                  jndiContext = null;
ConnectionFactory   connectionFactory = null;
Connection             connection = null;
Session                  session = null;
Queue                    queue = null;
MessageProducer     messageProducer = null;   
 
try
{
    //[1] Create a JNDI API InitialContext object.
    Hashtable properties = new Hashtable(2);
    properties.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.appserv.naming.S1ASCtxFactory");
    properties.put(Context.PROVIDER_URL, "iiop://10.0.0.26:3700"); *//FOR EACH SERVER MUST BE HIS OWN PROVIDER. The iiop provider is for GlassFish.*
    jndiContext = new InitialContext(properties);
            
    //[2] Look up connection factory and queue.
    connectionFactory = (ConnectionFactory)jndiContext.lookup("jms/ConnectionFactory");
    queue = (Queue)jndiContext.lookup("jms/Queue");
        
    //[3]
    // - Create connection
    // - Create session from connection; false means session is not transacted.
    // - Create sender and text message.
    // - Send messages, varying text slightly.
    connection = connectionFactory.createConnection();
    session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    messageProducer = session.createProducer(queue);
 
   //[3.1] send a message
   TextMessage message = session.createTextMessage(this.jTextSend.getText()); 
   messageProducer.send(message); 
 
   //[3.2] example for send some object
   //ObjectMessage message = session.createObjectMessage();
   //Cards cards = new Cards(11, "Pupkin"); //this class must be serializable 
   //message.setObject(cards);
   //messageProducer.send(message);
}
catch(Exception ex)
{
   Logger.getLogger(JFrameMain.class.getName()).log(Level.SEVERE, null, e);
}
finally
{
     //[3.1]
     if(connection !=null)
     {
         try
         {
             connection.close();
         }
         catch(JMSException e)
         {
             Logger.getLogger(JFrameMain.class.getName()).log(Level.SEVERE, null, e);
         }
     }
}
 
TravelEntity
Posts:178
Registered: 13/05/05
Re: JMS Standalone Remote Client. Ho to connect to remote JMS Provider?   
Apr 8, 2008 7:10 AM (reply 3 of 8)  (In reply to #2 )
 
 
Nice to know you worked it out!

Just a few added details here....

appserv-rt.jar,javaee.jar, appserv-admin.jar, j2ee.jar are needed for your app server based JNDI lookup.

imq.jar, jms.jar (needed for the client library. imqutil.jar is missing)

jmsra.jar (not needed, probably added because you're missing imqutil.jar)
imqbroker.jar (not needed)

target-server name="PCNameJMSWebServer" address="10.0.0.26" port="3700"/>
In address must be IP address of JMS Server.

Actually, since this is the RMI port (3700), the address is the one from the app server. It just so happens that in your installation, the IP address is the same one as the JMS broker.

Try it with the different jar files (this will make your client installation smaller...)

HTH
TE
 
Foli
Posts:9
Registered: 5/30/07
Re: JMS Standalone Remote Client. Ho to connect to remote JMS Provider?   
Apr 8, 2008 7:41 AM (reply 4 of 8)  (In reply to #3 )
 
 
Thnx a lot for more detailed explanation. :)

Regards
Michael
Prague
 
jett
Posts:13
Registered: 5/8/08
Re: JMS Standalone Remote Client. Ho to connect to remote JMS Provider?   
May 18, 2008 9:53 PM (reply 5 of 8)  (In reply to #4 )
 
 
Hello.

I am trying to do this from within a servlet but I am getting an error when I the connection object is being created:

javax.jms.Connection connection = connectionFactory.createConnection();


java.lang.NullPointerException
at com.sun.enterprise.resource.PoolManagerImpl.getResourceFromPool(PoolManagerImpl.java:248)
at com.sun.enterprise.resource.PoolManagerImpl.getResource(PoolManagerImpl.java:176)
at com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(ConnectionManagerImpl.java:337)
at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:189)
at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:165)
at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:158)
at com.sun.messaging.jms.ra.DirectConnectionFactory._allocateConnection(DirectConnectionFactory.java:569)
at com.sun.messaging.jms.ra.DirectConnectionFactory.createConnection(DirectConnectionFactory.java:262)
at com.ipc.sendMessage.processRequest(sendMessage.java:71)
at com.ipc.sendMessage.doGet(sendMessage.java:126)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:718)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:317)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:288)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)

Am I doing something wrong?
 
TravelEntity
Posts:178
Registered: 13/05/05
Re: JMS Standalone Remote Client. Ho to connect to remote JMS Provider?   
May 23, 2008 8:59 AM (reply 6 of 8)  (In reply to #5 )
 
 
Sounds like you didn't define your JMS resources in the application server... Or the JNDI name (or the jms names) are not the ones the application is using...

TE
 
RyanFrost
Posts:2
Registered: 5/19/09
Re: JMS Standalone Remote Client. Ho to connect to remote JMS Provider?   
Jun 2, 2009 10:38 AM (reply 7 of 8)  (In reply to #5 )
 
 
Did you ever figure this out? I am running into a similar situation and would interested to know what was wrong. I have checked my jms names million times.

Thanks.
 
UFO_techno
Posts:3
Registered: 6/5/09
Re: JMS Standalone Remote Client. Ho to connect to remote JMS Provider?   
Jun 5, 2009 3:00 AM (reply 8 of 8)  (In reply to #3 )
 
 
TravelEntity,

what is the purpose of sun-acc.xml file? Does it play role if I am running client and server on the same machine? My practice shows that probably not...

* glassfish_home/domains/domain1/config/sun-acc.xml

<target-server name="PCNameJMSWebServer" address="10.0.0.26" port="3700"/>
In address must be IP address of JMS Server.

I installed glasfish server and I have in address the same like in name so name="WIN" address="WIN"...

Thanks
 
This topic has 8 replies on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 25
  • Guests : 132

About Sun forums
  • Oracle Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Oracle Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums