[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 428
  • 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....

PROVIDER_URL="file:////SERVER2:2414/opt/mqm/java/namespace/jms"

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");
            try
            {
                  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);
                  jmsConnection.start();
                  TextMessage message = session.createTextMessage();

                  message.setText(messageText);
                  message.setJMSReplyTo(replyQ);
                  sender.send(message);
            }
            catch (NamingException e)
            {
                  ok = false;
                  e.printStackTrace();
                  throw e;
            }
            catch (JMSException e)
            {
                  ok = false;
                  e.printStackTrace();
                  throw e;
            }
            return ok;
      }



Thanks for any help


Matt
0
MattBrook
Asked:
MattBrook
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.

M
0
 
EE_AutoDeleterCommented:
MattBrook,
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.

EE_AutoDeleter
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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