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 » General Discussion » Java Program to Get MQ Message from Queue to File

Post new topic  Reply to topic
 Java Program to Get MQ Message from Queue to File « View previous topic :: View next topic » 
Author Message
skal
PostPosted: Mon Nov 11, 2002 6:38 am    Post subject: Java Program to Get MQ Message from Queue to File Reply with quote

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
View user's profile Send private message
rajpath
PostPosted: Thu Dec 05, 2002 11:57 pm    Post subject: Heres ur program. Reply with quote

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
View user's profile Send private message Yahoo Messenger
bduncan
PostPosted: Fri Dec 06, 2002 9:49 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address
RogerLacroix
PostPosted: Fri Dec 06, 2002 11:21 am    Post subject: Reply with quote

Jedi Knight

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

I have a bunch of Java MQ samples post at my site:
http://www.capitalware.biz/sample_mqseries.html#javacode

later
Roger...
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
nimconsult
PostPosted: Mon Dec 09, 2002 1:25 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » General Discussion » Java Program to Get MQ Message from Queue to File
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.