|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Java Program to Get MQ Message from Queue to File |
« View previous topic :: View next topic » |
Author |
Message
|
skal |
Posted: Mon Nov 11, 2002 6:38 am Post subject: Java Program to Get MQ Message from Queue to File |
|
|
Newbie
Joined: 11 Nov 2002 Posts: 1
|
Can some one help to find a sample Java Program to get a Message from MQ and writes to a File ?
skal |
|
Back to top |
|
 |
rajpath |
Posted: Thu Dec 05, 2002 11:57 pm Post subject: Heres ur program. |
|
|
Novice
Joined: 12 Jun 2002 Posts: 12 Location: Mumbai
|
Hello
Its nothing difficult in that.While getting the message cast it to file.Read file in bytes through FileInputStream and same bytes write in other file as FileOutputStream.Hope this will solve ur problem.If u could'nt understand I had pasted the code below.Kindly go through the same.I had written on test MQServer.
import java.io.*; //import classes for IO operation
import com.ibm.mq.*; //import classes for MQSeries
import java.util.*; //import class to store properties
import java.net.*;
public class MQReadTry
{
public static void main(String[] args) throws Exception
{
System.out.println("Hello World!");
String qmgrname=qmgrname;
String qname=qname;
try{
MQEnvironment.hostname = "192.16.20.18";
MQEnvironment.channel = "SVRCONN";
MQEnvironment.port = Integer.parseInt("1717");
MQQueueManager qmgr = new MQQueueManager(qmgrname);
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_INQUIRE;
MQQueue que =qmgr.accessQueue(qname,openOptions,null,null,null);
int depth=que.getCurrentDepth();
int t_dep=depth;
System.out.println(depth);
MQMessage msg=new MQMessage();
// msg.writeString("This is test carried out by raj");
//String message=msg.readLine();
MQGetMessageOptions gmo = new MQGetMessageOptions();
//gmo.options=MQC.MQGMO_MSG_UNDER_CURSOR;
System.out.println("Error ********");
//File fo=new File("filepath");
//while(true)
//{
while(t_dep>0)
{
msg=new MQMessage();
gmo = new MQGetMessageOptions();
//gmo.options=MQC.MQGMO_BROWSE_FIRST;
System.out.println(t_dep);
que.get(msg,gmo);
String msg_str=msg.readLine();
System.out.println(msg_str);
File f=(File)msg.readObject();
String fname=f.getName();
int i=(int)f.length();
byte[] b=new byte[i];
FileInputStream fis=new FileInputStream(f);
fis.read(b,0,i);
FileOutputStream fos=new FileOutputStream(filepath,true);
fos.write(b,0,i);
fos.close();
//f.renameTo(fo);
//FileOutputStream fout=new FileO
System.out.println(fname);
//gmo.options=MQC.MQGMO_BROWSE_NEXT;
t_dep=t_dep-1;
}
//else
//break;
//t_dep--;
//}
qmgr.commit();
}catch(MQException mq){
System.out.println(mq.getMessage());
}
}
} _________________ Raj
Software Engineer
Mahindra Consulting Ltd
Mumbai-101 India |
|
Back to top |
|
 |
bduncan |
Posted: Fri Dec 06, 2002 9:49 am Post subject: |
|
|
Padawan
Joined: 11 Apr 2001 Posts: 1554 Location: Silicon Valley
|
Thanks Raj!
I think a few other people have requested a sample program like this before, would be okay with me adding this to the software repository on this site? (crediting you as the author of course) _________________ Brandon Duncan
IBM Certified MQSeries Specialist
MQSeries.net forum moderator |
|
Back to top |
|
 |
RogerLacroix |
Posted: Fri Dec 06, 2002 11:21 am Post subject: |
|
|
 Jedi Knight
Joined: 15 May 2001 Posts: 3264 Location: London, ON Canada
|
|
Back to top |
|
 |
nimconsult |
Posted: Mon Dec 09, 2002 1:25 am Post subject: |
|
|
 Master
Joined: 22 May 2002 Posts: 268 Location: NIMCONSULT - Belgium
|
Apart from the fact that it does not compile, I do not think that this piece of code does what you expect.
You will find samples that dump the content of the message itself, the issue I have found is retrieving the MQMD (message descriptor) using the java classes. If anyone has a solution I am also interested.
Nicolas _________________ Nicolas Maréchal
Senior Architect - Partner
NIMCONSULT Software Architecture Services (Belgium)
http://www.nimconsult.be |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|