PROVIDER_URL cross server

Posted on 2006-05-08
Last Modified: 2008-02-01
Afternoon everybody,

The basics of my problem is that I have a clustered env of 2 servers Server1 and Server2 using Websphere 5. Within a few of my J2EE applications I have a singleton cache object caching a load of information from my database. The database I am getting the caching information is not controlled by myself so I have had to add triggers to the tables I have cached to find out when a change is made.

Once a change is made the trigger will write a row to a small table with the tablename and cache key that was updated. I have a small Java application (CachePoller) which runs on Server1 polling this table. As soon as an insert is made in my cache table then my CachePoller creates a simple XML message and publishes it to a queue which my J2EE app picks up and tells the cache to update/delete or insert that row from its Cache.

The root of the problem is that the singleton cache will be initialised on both servers and therefore I would prefer to send the xml message from the one application first to server1 and then to server2 thus updating both caches. Is there any way of doing this from server1 to server2 by changing the PROVIDER_URL - this is currently set to "file:////opt/mqm/java/namespace/jms" which is the location of my .bindings file and is the same on server2. I was hoping I could do something simple like this....


it doesn't seem to like this one and produces a NamingException.....

javax.naming.NameNotFoundException; remaining name '"/SQWAS02D:2414/opt/mqm/java/namespace/jms"'
        at com.sun.jndi.fscontext.FSContext.checkExists(
        at com.sun.jndi.fscontext.FSContext.checkIsDirectory(
        at com.sun.jndi.fscontext.FSContext.<init>(
        at com.sun.jndi.fscontext.FSContext.<init>(
        at com.sun.jndi.fscontext.RefFSContext.<init>(
        at com.sun.jndi.fscontext.RefFSContextFactory.createContext(
        at com.sun.jndi.fscontext.RefFSContextFactory.createContextAux(
        at com.sun.jndi.fscontext.FSContextFactory.getInitialContext(
        at javax.naming.spi.NamingManager.getInitialContext(
        at javax.naming.InitialContext.getDefaultInitCtx(
        at javax.naming.InitialContext.init(

CODE SAMPLE................

I am looking up the queue to send the cache message to using a bindings file on Server1 and so the code I use looks like this :

    protected boolean processCurrentInstance(Object obj) throws ProcessingException
        // Now process the retrieved messages and assemble the XML
        String xmlMessage = "";
        boolean result = true;
        if (obj instanceof GripsMessageVO)
            GripsMessageVO gVO = (GripsMessageVO) obj;
            xmlMessage = assembleXML(gVO);
            ok = JMSUtils.sendTextMessageOutsideJ2EE(xmlMessage, "GRIPS.OUTBOUND.Q", "GRIPS.OUTBOUND.Q", "GRIPS.QCF", this.providerURL);

Once the sendTextMsg is called it does your basic send a msg routine as follows :

      public static boolean sendTextMessageOutsideJ2EE(String messageText, String qNameToSendTo, String replyQName, String qcfName, String jmsProviderURL) throws NamingException, JMSException
  "Sending message outside of J2EE with params of : qToSendTo="+qNameToSendTo+", replyQ="+replyQName+", qcf="+qcfName);
            boolean ok = true;
            String jmsIDString = null;
            Context jndiCtx = null;
            QueueConnection qc = null;
            QueueSession queueSession = null;
            QueueSender queueSender = null;

            Context itx = null;
            Hashtable settings = new Hashtable();
            settings.put(Context.PROVIDER_URL, jmsProviderURL);
            settings.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
                  itx = new InitialContext(settings);
                  MQQueueConnectionFactory qcf = (MQQueueConnectionFactory) itx.lookup(qcfName);
                  QueueConnection jmsConnection = qcf.createQueueConnection();
                  QueueSession session = jmsConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
                  Queue queue = (MQQueue) itx.lookup(qNameToSendTo);
                  Queue replyQ = null;
                  if (replyQName == null || replyQName.trim().equals(""))
                        replyQ = (MQQueue) itx.lookup(replyQName);
                  QueueSender sender = session.createSender(queue);
                  TextMessage message = session.createTextMessage();

            catch (NamingException e)
                  ok = false;
                  throw e;
            catch (JMSException e)
                  ok = false;
                  throw e;
            return ok;

Thanks for any help

Question by:MattBrook

    Author Comment

    Don't worry I have figured it out now. The way to do it was to add the queue and qcf I was trying to reference into the bindings file on Server1 for Server2 but with a different name and then look the queue up on Server2 through Server1 by the new reference.


    Accepted Solution

    Because you have presented a solution to your own problem which may be helpful to future searches, this question is now PAQed and your points have been refunded.


    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    nested class vs inner class 5 38
    copyEvens challenge 6 47
    bunnyEars challenge 6 47
    pairstar challenge 2 26
    Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now