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 QMs,using Java

Post new topic  Reply to topic
 Clustering QMs,using Java « View previous topic :: View next topic » 
Author Message
shantha
PostPosted: Mon Feb 09, 2004 12:06 am    Post subject: Clustering QMs,using Java Reply with quote

Apprentice

Joined: 11 Dec 2003
Posts: 41

HI,
I have 2 WAS severs and 2 MQ servers.
The queue mangers are in cluster.
And it works in round robin fashion.As of now I have a coded my application in java.I have a virtual IP address,which connects to 2 different ip address of the mq servers.I have 2 differnt QM.For load balancing and failovers,i should be able to connect to the other QM also.When I execute this program,it works fine in alternate conditions.It works connecting to one QM,but fails while connecting to the other QM.PLease suggest me,if there should be any code change.I am in need of help
Thanks in advance

import com.ibm.mq.*;
import java.io.FileReader;
import java.io.*;
import java.util.*;

public class testsend{

public testsend()

{
String hostname = "172.17.6.23"; //virtual Ip address
String channel = "SYSTEM.DEF.SVRCONN";
String qManager = null;
MQQueueManager qMgr = null;
String outString = null;
String FileName = "ReturnXML.xml";

System.out.println("hello");
MQEnvironment.hostname = hostname;
MQEnvironment.channel = channel;
MQEnvironment.CCSID = 874;
try
{
try
{
qManager = "IMV1DEAIQM";
qMgr = new MQQueueManager(qManager);
}
catch(MQException ex)
{
qManager = "IMV2DEAIQM";
qMgr = new MQQueueManager(qManager);
System.out.println ("hello1 ");
}
int openOptions = MQC.MQOO_OUTPUT;
MQQueue q = qMgr.accessQueue("SAP.MATS.ALE_STATUS",openOptions , null, null, null);
MQMessage msg = new MQMessage();
msg.format = MQC.MQFMT_STRING;
int i = 1;
String s = null;
BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(FileName)));
outString=br.readLine();
while (( s = br.readLine()) != null)
{
if(i==1)
outString = s.trim();
else
outString += s.trim();
i++;
}
br.close();
msg.correlationId = generateMessageId().getBytes();
System.out.println("correlation id =" + new String(msg.correlationId));
msg.writeString(outString);
MQPutMessageOptions pmo = new MQPutMessageOptions();
q.put(msg,pmo);
System.out.println("Message Sent!");
q.close();
qMgr.disconnect();
}//try
catch(MQException ex)
{if (ex.reasonCode != 2058) {
System.out.println("An MQSeries error occurred : Completion code " +
ex.completionCode + " Reason code " + ex.reasonCode);
}
}
catch (java.io.IOException ex)
{
System.out.println("An error occurred while writing to the message buffer: " + ex);
}
}//putMessage()

// Method that returns unique Message ID

public String generateMessageId(){
String MesId = null;
try
{
GregorianCalendar gc = new GregorianCalendar();
MesId = (new Integer(gc.get(Calendar.DATE))).toString();
MesId = MesId + (new Integer(gc.get(Calendar.MONTH))).toString();
MesId = MesId + (new Integer(gc.get(Calendar.YEAR))).toString().substring(2);
MesId = MesId + (new Integer(gc.get(Calendar.HOUR))).toString();
MesId = MesId + (new Integer(gc.get(Calendar.MINUTE))).toString();
MesId = MesId + (new Integer(gc.get(Calendar.SECOND))).toString();
}
catch(Exception e){}
return "18100311122";
}
public static void main(String args[])
{
new testsend();
}
}
Back to top
View user's profile Send private message
vennela
PostPosted: Mon Feb 09, 2004 7:06 am    Post subject: Reply with quote

Jedi Knight

Joined: 11 Aug 2002
Posts: 4055
Location: Hyderabad, India

I am not sure what's going on. But for me to help if you do this then it would be easier.

In your code
Code:

try
{
qManager = "IMV1DEAIQM";
qMgr = new MQQueueManager(qManager);
}
catch(MQException ex)
{
qManager = "IMV2DEAIQM";
qMgr = new MQQueueManager(qManager);
System.out.println ("hello1 ");
}


Add a println statement in your catch block and printout the reason code.
What is the exception that you are getting when you try the above code.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
shantha
PostPosted: Mon Feb 09, 2004 7:16 pm    Post subject: Reply with quote

Apprentice

Joined: 11 Dec 2003
Posts: 41

what I mean is I have Application server WAS1 and Application server WAS2 and MQ server MQ1 and MQ server MQ2.And there are 2 QMS QM1 and QM2,with the same Queue names.
The code is deployed in the WAS1 and WAS2.
it works in round robin fashion.
SO my application has to put the messages to the queue.
Now my problem is ,what hostname and Q manager name should I give in the applcaition to put the messages in the queue and get the messages from the queue. ANd all the four are are in differnt m/cs.
ie WAS1 on differeetn m/c
WAS2 on different m/c
MQ1 on different m/c
MQ2 on different m/c
Hope I was clear in explaining the problem
Thanks for the response
shantha
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Tue Feb 10, 2004 4:18 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

If you want to change the default round-robin behavior of MQSeries clustering, so that messages will get work-load balanced between QMs regardless of whether there is a local instance of a queue or not - which it sounds like you're trying to do - then you should use a cluster workload exit to accomplish this. I seem to remember that there was a sample cluster workload exit that did just this. Maybe it was a support pack?

Using a virtual IP address like you are doing is not the right solution at all. You could create two connections in your app, one to each QM, and then switch which one you are using each time you put a message.
_________________
I am *not* the model of the modern major general.
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 QMs,using Java
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.