• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 444
  • Last Modified:

PROVIDER_URL cross server

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(FSContext.java:850)
        at com.sun.jndi.fscontext.FSContext.checkIsDirectory(FSContext.java:883)
        at com.sun.jndi.fscontext.FSContext.<init>(FSContext.java:108)
        at com.sun.jndi.fscontext.FSContext.<init>(FSContext.java:81)
        at com.sun.jndi.fscontext.RefFSContext.<init>(RefFSContext.java:97)
        at com.sun.jndi.fscontext.RefFSContextFactory.createContext(RefFSContextFactory.java:42)
        at com.sun.jndi.fscontext.RefFSContextFactory.createContextAux(RefFSContextFactory.java:47)
        at com.sun.jndi.fscontext.FSContextFactory.getInitialContext(FSContextFactory.java:49)
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:674)
        at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:255)
        at javax.naming.InitialContext.init(InitialContext.java:231)

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
            log.info("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

1 Solution
MattBrookAuthor Commented:
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.

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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now