ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » Clustering » Clustering Queue Java program

Post new topic  Reply to topic
 Clustering Queue Java program « View previous topic :: View next topic » 
Author Message
tumstech
PostPosted: Fri Nov 06, 2009 1:34 am    Post subject: Clustering Queue Java program Reply with quote

Newbie

Joined: 04 Nov 2009
Posts: 7

Hi,
Need help in Java Client connecting to Queue Cluster
Here is my Configuration

My Cluster Name : "MyCluster"

QMGW - Full Repository (Default Q Manager) - localhost(1414)
QM1 - Full Repos - localhost(1415)
QM2 - Partial Repos connected to QMGW - localhost(1416)

Have a Queue named "Q1" on all the Queue Manager

CLWSUSEQ = "Any" on all the Queue and Queue manager
Default Bind type = "Not Fixed"

After this setup, if i use the

amqsput Q1
or
amqsput Q1 QMGW

i get the message getting distributed among the Q's in the other Queue Manager

same settings if i try to use a java client to connect using sun's default java messaging api with
Context.PROVIDER_URL = "localhost:1414/SYSTEM.DEF.SVRCONN"
Context.INITIAL_CONTEXT_FACTORY="com.ibm.mq.jms.context.WMQInitialContextFactory"
i am using the generic JMS Java Client and not the API's provided by MQ.

The source code ihave taken is at this place
http://java.sun.com/products/jms/tutorial/1_3_1-fcs/doc/client_samples.html#1006838

all messages are going only to QMGW, and not getting distributed.

what should i do for my messages to be replicated..?
and change in client conf..? or client java code..? or any change on the cluster environment..?
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Fri Nov 06, 2009 3:49 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20696
Location: LI,NY

Show us the JNDI or URI used for the Destination definition.
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
tumstech
PostPosted: Fri Nov 06, 2009 3:56 am    Post subject: Reply with quote

Newbie

Joined: 04 Nov 2009
Posts: 7

i do not have any extra conf appart from what i have mentioned.
Did i miss any configuration that i have done and forgot..?

i think i dont have any configuration other than this..
no jndi.properties
i am using

Context.PROVIDER_URL = "localhost:1414/SYSTEM.DEF.SVRCONN"
Context.INITIAL_CONTEXT_FACTORY="com.ibm.mq.jms.context.WMQInitialContextFactory"
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Fri Nov 06, 2009 3:46 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20696
Location: LI,NY

tumstech wrote:
i do not have any extra conf appart from what i have mentioned.
Did i miss any configuration that i have done and forgot..?

i think i dont have any configuration other than this..
no jndi.properties
i am using

Context.PROVIDER_URL = "localhost:1414/SYSTEM.DEF.SVRCONN"
Context.INITIAL_CONTEXT_FACTORY="com.ibm.mq.jms.context.WMQInitialContextFactory"


You are starting with a handicap. This version of interactive JNDI should only be used for demo purposes...

Try and use the file based JNDI ...

Also you will have a hard time controlling your destinations with the version of JNDI you used... file based JNDI is the way to go.

I suspect your troubles have something to do with the way your destination is defined. The URI form of the destination you are using would tell me a little more....

Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
tumstech
PostPosted: Sun Nov 08, 2009 10:15 pm    Post subject: Reply with quote

Newbie

Joined: 04 Nov 2009
Posts: 7

can you please help me in doing the same.. please..

My JMS Utility file is as follows

Code:

package com.vis.jms.sun.example;
/*
 *
 * Copyright 2002 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or
 * without modification, are permitted provided that the following
 * conditions are met:
 *
 * - Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * - Redistribution in binary form must reproduce the above
 *   copyright notice, this list of conditions and the following
 *   disclaimer in the documentation and/or other materials
 *   provided with the distribution.
 *
 * Neither the name of Sun Microsystems, Inc. or the names of
 * contributors may be used to endorse or promote products derived
 * from this software without specific prior written permission.
 *
 * This software is provided "AS IS," without a warranty of any
 * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
 * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
 * DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR
 * RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE OR
 * ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE
 * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
 * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
 * THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS
 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 *
 * You acknowledge that this software is not designed, licensed or
 * intended for use in the design, construction, operation or
 * maintenance of any nuclear facility.
 *
 */
import java.util.Hashtable;

import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueReceiver;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;
import javax.jms.TopicConnectionFactory;
import javax.jms.TopicSession;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class SampleUtilities {
    public static String  QUEUECONFAC = "QM1";
    public static String  TOPICCONFAC = "TopicConnectionFactory";
   
    public static Hashtable<String, String> env = new Hashtable<String, String>();
    public static Context jndiContext = null;
   
    /**
     * Returns a QueueConnectionFactory object.
     *
     * @return    a QueueConnectionFactory object
     * @throws    javax.naming.NamingException (or other
     *            exception) if name cannot be found
     */
    public static QueueConnectionFactory
            getQueueConnectionFactory() throws Exception {
        return (QueueConnectionFactory) jndiLookup(QUEUECONFAC);
    }
   
    /**
     * Returns a TopicConnectionFactory object.
     *
     * @return    a TopicConnectionFactory object
     * @throws    javax.naming.NamingException (or other
     *            exception) if name cannot be found
     */
    public static TopicConnectionFactory
            getTopicConnectionFactory() throws Exception {
        return (TopicConnectionFactory) jndiLookup(TOPICCONFAC);
    }
   
    /**
     * Returns a Queue object.
     *
     * @param name       String specifying queue name
     * @param session    a QueueSession object
     *
     * @return           a Queue object
     * @throws           javax.naming.NamingException (or other
     *                   exception) if name cannot be found
     */
    public static Queue getQueue(String name,
            QueueSession session) throws Exception {
        return (Queue) jndiLookup(name);
    }
   
    /**
     * Returns a Topic object.
     *
     * @param name       String specifying topic name
     * @param session    a TopicSession object
     *
     * @return           a Topic object
     * @throws           javax.naming.NamingException (or other
     *                   exception) if name cannot be found
     */
    public static Topic getTopic(String name,
            TopicSession session) throws Exception {
        return (Topic) jndiLookup(name);
    }
   
    /**
     * Creates a JNDI API InitialContext object if none exists
     * yet. Then looks up the string argument and returns the
     * associated object.
     *
     * @param name    the name of the object to be looked up
     *
     * @return        the object bound to name
     * @throws        javax.naming.NamingException (or other
     *                exception) if name cannot be found
     */
    public static Object jndiLookup(String name)
        throws NamingException {
        Object    obj = null;

        if (jndiContext == null) {
            try {
               if(env.containsKey(Context.INITIAL_CONTEXT_FACTORY) == false)
                  env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.mq.jms.context.WMQInitialContextFactory");
               if(env.containsKey(Context.PROVIDER_URL) == false)
                  env.put(Context.PROVIDER_URL, "localhost:1540/SYSTEM.DEF.SVRCONN");

               jndiContext = new InitialContext(env);
            } catch (NamingException e) {
                System.err.println("Could not create JNDI API " +
                    "context: " + e.toString());
                throw e;
            }
        }
        try {
           obj = jndiContext.lookup(name);
        } catch (NamingException e) {
            System.err.println("JNDI API lookup failed: " +
                e.toString());
            throw e;
        }
        return obj;
    }
     
    /**
     * Waits for 'count' messages on controlQueue before
     * continuing.  Called by a publisher to make sure that
     * subscribers have started before it begins publishing
     * messages.
     *
     * If controlQueue does not exist, the method throws an
     * exception.
     *
     * @param prefix    prefix (publisher or subscriber) to be
     *                  displayed
     * @param controlQueueName  name of control queue
     * @param count     number of messages to receive
     */
    public static void receiveSynchronizeMessages(String prefix,
            String controlQueueName, int count)
            throws Exception {
        QueueConnectionFactory  queueConnectionFactory = null;
        QueueConnection         queueConnection = null;
        QueueSession            queueSession = null;
        Queue                   controlQueue = null;
        QueueReceiver           queueReceiver = null;

        try {
            queueConnectionFactory =
                SampleUtilities.getQueueConnectionFactory();
            queueConnection =
                queueConnectionFactory.createQueueConnection();
            queueSession =
                queueConnection.createQueueSession(false,
                    Session.AUTO_ACKNOWLEDGE);
            controlQueue = getQueue(controlQueueName,
                queueSession);
            queueConnection.start();
        } catch (Exception e) {
            System.err.println("Connection problem: " +
                e.toString());
            if (queueConnection != null) {
                try {
                    queueConnection.close();
                } catch (JMSException ee) {}
            }
            throw e;
        }

        try {
            System.out.println(prefix +
                "Receiving synchronize messages from " +
                controlQueueName + "; count = " + count);
            queueReceiver =
                queueSession.createReceiver(controlQueue);
            while (count > 0) {
               TextMessage msg = (TextMessage)queueReceiver.receive();
                count--;
                System.out.println(prefix +
                    "Received synchronize message; " +
                    " expect " + count + " more : " + msg.getText());
            }
        } catch (JMSException e) {
            System.err.println("Exception occurred: " +
                e.toString());
            throw e;
        } finally {
            if (queueConnection != null) {
                try {
                    queueConnection.close();
                } catch (JMSException e) {}
            }
        }
    }

    /**
     * Sends a message to controlQueue.  Called by a subscriber
     * to notify a publisher that it is ready to receive
     * messages.
     * <p>
     * If controlQueue doesn't exist, the method throws an
     * exception.
     *
     * @param prefix    prefix (publisher or subscriber) to be
     *                  displayed
     * @param controlQueueName  name of control queue
     */
    public static void sendSynchronizeMessage(String prefix,
            String controlQueueName)
            throws Exception {
        QueueConnectionFactory  queueConnectionFactory = null;
        QueueConnection         queueConnection = null;
        QueueSession            queueSession = null;
        Queue                   controlQueue = null;
        QueueSender             queueSender = null;
        TextMessage             message = null;

        try {
            queueConnectionFactory =
                SampleUtilities.getQueueConnectionFactory();
            queueConnection =
                queueConnectionFactory.createQueueConnection();
            queueSession =
                queueConnection.createQueueSession(false,
                    Session.AUTO_ACKNOWLEDGE);
            controlQueue = getQueue(controlQueueName,
                queueSession);
        } catch (Exception e) {
            System.err.println("Connection problem: " +
                e.toString());
            if (queueConnection != null) {
                try {
                    queueConnection.close();
                } catch (JMSException ee) {}
            }
            throw e;
        }

        try {
            queueSender =
                queueSession.createSender(controlQueue);
            message = queueSession.createTextMessage();
            message.setText("synchronize");
            System.out.println(prefix +
                "Sending synchronize message to " +
                controlQueueName);
            queueSender.send(message);
        } catch (JMSException e) {
            System.err.println("Exception occurred: " +
                e.toString());
            throw e;
        } finally {
            if (queueConnection != null) {
                try {
                    queueConnection.close();
                } catch (JMSException e) {}
            }
        }
    }

    /**
     * Monitor class for asynchronous examples.  Producer signals
     * end of message stream; listener calls allDone() to notify
     * consumer that the signal has arrived, while consumer calls
     * waitTillDone() to wait for this notification.
     */
    static public class DoneLatch {
        boolean  done = false;

        /**
         * Waits until done is set to true.
         */
        public void waitTillDone() {
            synchronized (this) {
                while (! done) {
                    try {
                        this.wait();
                    } catch (InterruptedException ie) {}
                }
            }
        }
       
        /**
         * Sets done to true.
         */
        public void allDone() {
            synchronized (this) {
                done = true;
                this.notify();
            }
        }
    }
}



My Main File is as follows

Code:

package com.vis.jms.sun.example;

import javax.naming.Context;

public class SunExampleRun {

   public static void main(String args[]){
      try {
         SampleUtilities.env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.mq.jms.context.WMQInitialContextFactory");

         SampleUtilities.QUEUECONFAC = "QMGW";
         SampleUtilities.env.put(Context.PROVIDER_URL, "localhost:1414/SYSTEM.DEF.SVRCONN");
         
            SampleUtilities.sendSynchronizeMessage("publisher", "Q1");
      } catch (Exception e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
   }
}


so what modification do i need to do here to use file jndi..
============================================
i also tried with the below configuration

Used JMSAdmin to create the ".binding" at location c:\JNDI
and used the following Code
DELETE QCF(MyQCF)
DEFINE QCF(MyQCF) QMGR(QMGW) tran(client) chan(SYSTEM.ADMIN.SVRCONN) host(127.0.0.1) port(1414)
DEFINE Q(Q1) QUEUE(Q1) QMGR(QMGW)
end
jndi.properties file is as follows

java.naming.factory.initial = com.sun.jndi.fscontext.RefFSContextFactory
java.naming.provider.url = file:///C:/JNDI
SECURITY_AUTHENTICATION=none


This also dint work.. they were also doing the putting in the message in the Queue inside the QMGW and not distributing it into any other queuemanager
===============================================
Back to top
View user's profile Send private message
mqjeff
PostPosted: Mon Nov 09, 2009 5:24 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

The Q definition is doing exactly what you have told it to do.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » Clustering » Clustering Queue Java program
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.