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 » IBM MQ Java / JMS » sample java code fro putting the message in the cluster queu

Post new topic  Reply to topic
 sample java code fro putting the message in the cluster queu « View previous topic :: View next topic » 
Author Message
shantha
PostPosted: Mon Feb 09, 2004 4:18 am    Post subject: sample java code fro putting the message in the cluster queu Reply with quote

Apprentice

Joined: 11 Dec 2003
Posts: 41

hi,
Could anybody please give me a sample java code to put the message in the cluster queue and get the message from the cluster queue.
The QMs are running on 2 different m/cs

thanks in advance

shantha
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Mon Feb 09, 2004 4:23 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

There's nothing different between putting and getting to queues that are shared in clusters than queues that are not shared in clusters.

I mean, really, nothing different. All of the same rules apply. You can't get from a queue that is not a qlocal on the QM you are connected to.

There's nothing different about connecting to a QM that is in a cluster.

The sample code you want is the same sample code for putting or getting to any queue on any queue manager.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
shantha
PostPosted: Mon Feb 09, 2004 7:28 am    Post subject: Reply with quote

Apprentice

Joined: 11 Dec 2003
Posts: 41

I have 2 QMs on 2 different m/cs.
they work in round robin fashion.My code is deployed in Applciation server.My problem is what hostname and what QM name should I give in the program to put the message in the Queue.

If I use this following code...this excutes on alternative executions.B'cas I have given ONe QM name and one host name.Where will I specify the other QM name and hostname.I am really confused.Please help me

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";
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;
qManager = "IMVDEAIQM";
qMgr = new MQQueueManager(qManager);
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
RogerLacroix
PostPosted: Mon Feb 09, 2004 8:42 am    Post subject: Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3264
Location: London, ON Canada

Hi shantha,

You should not post the same question in multiple forums.

Now to your problem. First, I think you should review the WMQ Application Programmuing Guide manual to get a better understanding on how WMQ and WMQ clustering works.

The function of a cluster is so that you do not have to connect to multiple queue managers to put messages across different queue managers with the same named queue.

There are 3 WMQ commandments that you need to remember:
(1) You can put to ANY queue but you can ONLY Get from a local queue (local to where your program is connected).
(2) If you want to invoke the workload manager for round-robin distribution of messages then you must use the MQOO_BIND_NOT_FIXED open option.
(3) If the cluster queue exists locally on the queue manager that your program has connected to then ALL messages will ALWAYS be put to the local instance (Commandment #2 is voided / has no effect.).

The best way to use round-robin distribution of messages is to have a queue manager as a front-end for your program that it will connect to. In this queue manager, do not define the queue locally. Therefore, in your program when you connect to the 'front-end' queue manager and open the cluster queue with the open option of MQOO_BIND_NOT_FIXED, your messages will be put equally between the clustered queue managers with the locally defined cluster queue.

I hope that clears up your clustering questions.

Regards,
Roger Lacroix
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » sample java code fro putting the message in the cluster queu
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.