Topic
  • No replies
Annavajjala
Annavajjala
1 Post

Pinned topic Remote client for JMS deployed in Webshphere application server 8

‏2013-06-27T22:11:31Z | 8 client jms remote was websphere

XXXTopicFactory and XXXTopic has been added in websphere application server , published and subscribed in the websphere local in the following way

 private void updateCache(Serializable obj) throws JMSException
    {
        TopicConnection con = null;
        TopicSession ssn = null;
        TopicPublisher publisher = null;
        try
        {
            con = tcf.createTopicConnection();
            ssn = con.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
            publisher = ssn.createPublisher(topic);

            ObjectMessage objectMessage = ssn.createObjectMessage();
            objectMessage.setObject(obj);
            publisher.publish(objectMessage);
        }
        finally
        {
            if (ssn != null)
            {
                ssn.close();
            }
            if (con != null)
            {
                con.close();
            }
        }
    }

private Serializable subscribe(long millis) throws JMSException
    {
        TopicConnection con = null;
        TopicSession ssn = null;
        Serializable object = null;
        TopicConnection con1 = null;
        TopicSession ssn1 = null;
        try
        {
            con = tcf.createTopicConnection();
            ssn = con.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
            TopicSubscriber subscriber = ssn.createSubscriber(topic);
            con1 = tcf.createTopicConnection();
            ssn1 = con1.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
            TopicSubscriber subscriber1 = ssn1.createSubscriber(topic);
            con.start();
            con1.start();
            ObjectMessage m = (ObjectMessage) subscriber.receive(millis);
            if (m != null)
            {
                object = m.getObject();
            }
            m = (ObjectMessage) subscriber1.receive(millis);
            if ( null != m)
            {
                System.out.println("message from d1000c");
                //object = m.getObject();
            }
        }
        finally
        {
            if (ssn1 != null)
            {
                ssn1.close();
            }
            if (con1 != null)
            {
                con1.close();
            }
        }
        return object;
    }

I want to create a remote client in the following way

 

    public void someMethod()
    {    

        java.io.Serializable object = null;
        try {
        /**
        * Lookup connection factory object using jndi
        */
        System.out.println("* Looking up CF in jndi...");
        Hashtable<String, String> env = new Hashtable<String, String>();
       // Runtime.getRuntime().exec("C:\\Program Files (x86)\\IBM\\WebSphere\\AppServer\\bin\\setupCmdLine.bat");

        //env.put(Context.PROVIDER_URL, "iiop://137.136.204.9:17311");
        env.put(Context.PROVIDER_URL, "iiop://136.240.211.45:2809");
        env.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
        //System.out.println(url);
        //JMXConnector jmxc = JMXConnectorFactory.connect(url, env);*/
        //jmxc.
       // Socket so = new Socket("app-ehs-d1000c.cs.boeing.com", 17311);
        Context ctx = new InitialContext(env);

        TopicConnectionFactory fact=(TopicConnectionFactory)ctx.lookup("jms/XXXTopicConnectionFactory");
        TopicConnection connect = fact.createTopicConnection();
        TopicSession session=connect.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        
        Topic topic=null;
        
        try
        {
            topic =(Topic) ctx.lookup("jms/XXXTopic");
            System.out.println(topic.getTopicName());

        }catch (Exception e){
            e.printStackTrace();
        }
        TopicSubscriber subscribe =  session.createSubscriber(topic);
        connect.start();
        while(true)
        {
                ObjectMessage m = (ObjectMessage) subscribe.receive(2000);
                Thread.sleep(2000);
                if (m != null)
                {
                    Hashtable<String, String> latestHash = (Hashtable<String, String>) m.getObject();
                     Enumeration<String > itr = latestHash.keys();
                     while(itr.hasMoreElements())
                     {
                         String str = itr.nextElement();
                         System.out.println(str + "      "  +latestHash.get(str));
                     }
                    //return;
                }
        }
    }catch(Exception e)
    {
        e.printStackTrace();
    }

}

but i am not able to get the topic factory and topic instances,

1. what is the JNDI for the topics

2. what could be the better way to get the references

 

I am trying to create a remote client for a topic with name same what i have in my local

i.e., i have a local topic XXXTopic and remote topic XXXTopic i need to access these two topics

thanks in advance