|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
breaking up msg's in queue one at a time then write to file |
« View previous topic :: View next topic » |
Author |
Message
|
ping master |
Posted: Wed Jun 18, 2003 11:10 am Post subject: breaking up msg's in queue one at a time then write to file |
|
|
 Centurion
Joined: 20 Sep 2002 Posts: 116 Location: USA
|
Afternoon all,
I have three messages in a queue, what do you suppose is the best way to separate these messsages with my Java program-
currently I used Roger's mqread pgm(thanks again Roger) and changed it so it pulls in all the data into a byte array and writes it to a file, which works great if there is ONLY 1 message, but what if there are 2 or more?? how would i go about breaking them up so in the future I can put them back in a queue as the same amount exact messages. delimiter??
I would like to have it only write to one file, not a separate file for each message, anyone have any ideas or done this before?
Code: |
int depth = queue.getCurrentDepth();
if (depth == 0)
{
return;
}
MQGetMessageOptions getOptions = new MQGetMessageOptions();
getOptions.options = MQC.MQGMO_NO_WAIT + MQC.MQGMO_FAIL_IF_QUIESCING + MQC.MQGMO_CONVERT;
MQMessage message = new MQMessage();
try
{
File f2 = new File("mqpers.mqi");
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(f2));
queue.get(message, getOptions);
byte[] b = new byte[message.getMessageLength()];
message.readFully(b);
bos.write(b);
//System.out.println("length of the array : " + b.length);
//System.out.println("message : " + new String(b));
bos.flush();
bos.close();
message.clearMessage();
|
thanks |
|
Back to top |
|
 |
brgmo |
Posted: Fri Jun 20, 2003 1:01 am Post subject: file download |
|
|
Master
Joined: 03 Jun 2002 Posts: 227
|
i am sending you the source code of a download program using java which takes in message in the group in the buffer and then subsequently writes it to a file. if you want the upload part of this program also then write to me.
/////////////////////////////////////
FileDownload.java
////////////////////////////////////
package nbo.mqseries;
import com.ibm.mq.*;
/**
* Insert the type's description here.
* Creation date: (6/18/2003 6:06:22 PM)
* @author: Administrator
*/
public class FileDownload {
private com.ibm.mq.MQQueueManager mgr;
private com.ibm.mq.MQQueue queue;
/**
* FileDownload constructor comment.
*/
public FileDownload() {
super();
}
/**
* Insert the method's description here.
* Creation date: (6/18/2003 7:25:16 PM)
* @param mgr java.lang.String
* @param queue java.lang.String
* @param directory java.lang.String
*/
public void downloadFile(String mgr,String queue,String directory,String reply2Q) throws Exception {
try {
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = MQC.MQGMO_FAIL_IF_QUIESCING;
gmo.options = gmo.options + MQC.MQGMO_SYNCPOINT;
gmo.options = gmo.options + MQC.MQGMO_WAIT;
gmo.waitInterval = 5000;
gmo.options =
gmo.options + MQC.MQGMO_ALL_MSGS_AVAILABLE | MQC.MQGMO_ALL_SEGMENTS_AVAILABLE;
gmo.options = gmo.options + MQC.MQGMO_LOGICAL_ORDER;
gmo.matchOptions = MQC.MQMO_MATCH_GROUP_ID;
MQMessage inMsg = new MQMessage();
String fileName = "okbno.java";
String msgData = null;
int nbytes = 0;
byte [] buffer= new byte[500*1024];
setMgr(new MQQueueManager(mgr));
int openOptions = MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING | MQC.MQOO_INPUT_AS_Q_DEF;
setQueue(getMgr().accessQueue(queue, openOptions, null, null, null));
// Process the messages of the group
java.io.FileOutputStream fos = new java.io.FileOutputStream("d:/dataq.dat");
while (true) {
getQueue().get(inMsg, gmo);
int msgLength = inMsg.getMessageLength();
msgData = inMsg.readString(msgLength);
fos.write(msgData.getBytes());
char x = gmo.groupStatus;
// Check for the last message flag
if (x == MQC.MQGS_LAST_MSG_IN_GROUP) {
System.out.println("File Downloaded Successfully");
MQQueue replQ = getMgr().accessQueue(reply2Q, MQC.MQOO_OUTPUT);
MQMessage replyMsg = new MQMessage();
replyMsg.format = MQC.MQFMT_STRING;
replyMsg.writeChars("File downloaded Successfully");
replQ.put(replyMsg);
break;
}
inMsg.clearMessage();
}
getMgr().commit();
fos.close();
}
catch(Exception e){
}
}
/**
* Insert the method's description here.
* Creation date: (6/18/2003 7:39:40 PM)
* @return com.ibm.mq.MQQueueManager
*/
public com.ibm.mq.MQQueueManager getMgr() {
return mgr;
}
/**
* Insert the method's description here.
* Creation date: (6/18/2003 7:39:59 PM)
* @return com.ibm.mq.MQQueue
*/
public com.ibm.mq.MQQueue getQueue() {
return queue;
}
/**
* Starts the application.
* @param args an array of command-line arguments
*/
public static void main(java.lang.String[] args) throws Exception {
// Insert code to start the application here.
FileDownload fd= new FileDownload();
fd.downloadFile("nbo","brgmookbno","d:/dataq.dat","brgmo");
}
/**
* Insert the method's description here.
* Creation date: (6/18/2003 7:39:40 PM)
* @param newMgr com.ibm.mq.MQQueueManager
*/
public void setMgr(com.ibm.mq.MQQueueManager newMgr) {
mgr = newMgr;
}
/**
* Insert the method's description here.
* Creation date: (6/18/2003 7:39:59 PM)
* @param newQueue com.ibm.mq.MQQueue
*/
public void setQueue(com.ibm.mq.MQQueue newQueue) {
queue = newQueue;
}
}
//////////////////////////////////////////////////////////////////
brgmo |
|
Back to top |
|
 |
Mohit Gupta |
Posted: Thu Sep 16, 2004 2:10 am Post subject: File upload -- needed urgetn |
|
|
Apprentice
Joined: 16 Sep 2004 Posts: 34
|
Hi brgmo,
Can you pls send me the upload program . It would be a great help .
Regards,
Mohit |
|
Back to top |
|
 |
vennela |
Posted: Thu Sep 16, 2004 7:00 am Post subject: |
|
|
 Jedi Knight
Joined: 11 Aug 2002 Posts: 4055 Location: Hyderabad, India
|
You can also use Q program for this. Take a look at Support pacs. |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Sep 16, 2004 6:59 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
I don't quite understand what this is all about, call me dumb ....
But if the purpose is just to park messages into a file and reload them exactly the same....
Just receive the message, do not read the message content.
The message should be a serializable object so write the message to your ObjectOutputStream....
Read your object from the ObjectInputStream, cast it to Message and put back on the queue, incidentally with the same identifier etc...
Enjoy |
|
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
|
|
|
|