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 API Support » java pgm to turn msg's in a Queue to a file and vice versa

Post new topic  Reply to topic
 java pgm to turn msg's in a Queue to a file and vice versa « View previous topic :: View next topic » 
Author Message
ping master
PostPosted: Mon Jun 16, 2003 7:28 am    Post subject: java pgm to turn msg's in a Queue to a file and vice versa Reply with quote

Centurion

Joined: 20 Sep 2002
Posts: 116
Location: USA

Anyone know of a Java program that can go to a queue and turn the messages into a .dat file and that can turn the .dat file back into msgs to be put in a queue as if they never left. didnt see in repository


thanks

$PM
Back to top
View user's profile Send private message
brgmo
PostPosted: Mon Jun 16, 2003 8:46 am    Post subject: file transfer program Reply with quote

Master

Joined: 03 Jun 2002
Posts: 227

well i have downloaded one from net:

package nbo.mqseries;

import com.ibm.mq.MQC;
import com.ibm.mq.MQQueueManager;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQPutMessageOptions;
import com.ibm.mq.MQException;

import java.io.File;
import java.io.FileInputStream;

class FileTransfer
{

public static void main(String[] args)

{

String lFileName = args[0] ;
String lQName = args[1] ;
String lQMName = args[2] ;


System.err.println( "File name ........... : " + lFileName );
System.err.println( "Queue name .......... : " + lQName );
System.err.println( "Queue manager name .. : " + lQMName );

try
{
// Open input file
File lFile = new File(lFileName);
FileInputStream lFileInput = new FileInputStream(lFile);

// Connect to queue manager
MQException.log = null;
MQQueueManager lQM = new MQQueueManager(lQMName);

// Open target queue
MQQueue lQueue = lQM.accessQueue(lQName, MQC.MQOO_OUTPUT);

// Create message
MQMessage lMessage = new MQMessage();
lMessage.format = MQC.MQFMT_STRING;
lMessage.persistence=MQC.MQPER_PERSISTENT;

// Write file to message
String lShortFileName = lFile.getName();
lMessage.writeInt(lShortFileName.length());
lMessage.writeString(lShortFileName);
int lCharacter = 0;
while ((lCharacter = lFileInput.read()) != -1)
{
lMessage.write(lCharacter);
}
System.out.println("Message read");
// Send message
MQPutMessageOptions lPMO = new MQPutMessageOptions();
lPMO.options = MQC.MQPMO_NEW_MSG_ID;
System.out.println("Putting Message on queue");
lQueue.put(lMessage,lPMO);
System.out.println("Message put on queue");
// Close queue
lQueue.close();

// Disconnect from queue manager
lQM.disconnect();

// Close file
lFileInput.close();
}
catch(MQException e)
{
System.err.println("MQ Series error: cc=" + e.completionCode + ", reason=" + e.reasonCode);
e.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}


Regards
brgmo
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 » IBM MQ API Support » java pgm to turn msg's in a Queue to a file and vice versa
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.