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 » Java Prog to read msg

Post new topic  Reply to topic
 Java Prog to read msg « View previous topic :: View next topic » 
Author Message
asudhakar
PostPosted: Mon Jul 27, 2009 3:48 am    Post subject: Java Prog to read msg Reply with quote

Centurion

Joined: 12 May 2007
Posts: 116
Location: Bangalore

Hi 2 All,

Im planning to write a java program to read a msg from queue...

I am trying with pkg : com.ibm.mq PKg....

Can we write same thing in PCF commands. Can any one give suggestion how to use PCF commands...

Thanks

//Get msg

import com.ibm.mq.*;
import java.io.*;

public class GetMsg {
public static void main(String[] args) {
try
{
GetMessage gett= new GetMessage();
gett.Get();
}
catch(Exception e)
{
System.out.println("Error Msg"+e.getMessage());
}
}
}
class GetMessage
{
public void Get()
{
try{

System.out.println( "Getting Messages from the the Queues" );
MQQueueManager qmgr1=null;
MQQueue que=null;
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF ;
qmgr1 = new MQQueueManager("SUDHA");
que = qmgr1.accessQueue("QIN",openOptions,null,null,null);
MQMessage out=new MQMessage();
out.format = MQC.MQFMT_REF_MSG_HEADER;
que.get(out);
FileOutputStream fos = new FileOutputStream("c:\\mqout.dat");
DataOutputStream dos = new DataOutputStream(fos);
dos.writeBytes(out.readStringOfByteLength(out.getMessageLength()));
System.out.println( "Successful : CHECK c:\\mqout.dat FILE for msg" );
}
catch(Exception e)
{
e.printStackTrace(System.err);
}
}

}
_________________
WebSphere MQ, MB Support and Admin


Last edited by asudhakar on Mon Jul 27, 2009 3:59 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
asudhakar
PostPosted: Mon Jul 27, 2009 3:51 am    Post subject: Re: Java Prog to read msg Reply with quote

Centurion

Joined: 12 May 2007
Posts: 116
Location: Bangalore

import com.ibm.mq.*;
import java.io.*;

public class PutMsg {
public static void main(String[] args) {
try
{
//Queue Manager properties
MQEnvironment.hostname = "localhost";
MQEnvironment.port = 5555;
MQEnvironment.channel = "SYSTEM.DEF.SVRCONN";
String qName = "QIN";

MQQueueManager qmgr = new MQQueueManager("SUDHA");
System.out.println("\n\t\tQueue Manager Name : "+qmgr.name);
System.out.println("\t\t----------------------------");

int openOptions = MQC.MQOO_SET|MQC.MQOO_INQUIRE;
MQQueue queue = qmgr.accessQueue(qName, openOptions);
System.out.print("\nCurrent Depth before put message : "+queue.getCurrentDepth());


MQMessage mes=new MQMessage();
mes.writeBytes(new String("Sudhakar from middleware"));
qmgr.put(qName,mes);

System.out.print("\nCurrent Depth after put message : "+queue.getCurrentDepth());


qmgr.close();
}
catch(Exception e)
{
System.out.println("Error Msg"+e.getMessage());
}
}
}
_________________
WebSphere MQ, MB Support and Admin
Back to top
View user's profile Send private message Send e-mail
smdavies99
PostPosted: Mon Jul 27, 2009 6:12 am    Post subject: Reply with quote

Jedi Council

Joined: 10 Feb 2003
Posts: 6076
Location: Somewhere over the Rainbow this side of Never-never land.

Take a look at the sample apps that get supplied with WMQ.

These are very useful to use as the basis of some 'quick & dirty' apps to help in dev/test
_________________
WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995

Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions.
Back to top
View user's profile Send private message
asudhakar
PostPosted: Mon Jul 27, 2009 8:06 pm    Post subject: Reply with quote

Centurion

Joined: 12 May 2007
Posts: 116
Location: Bangalore

smdavies99 wrote:
Take a look at the sample apps that get supplied with WMQ.

These are very useful to use as the basis of some 'quick & dirty' apps to help in dev/test


Thank U smdavies.. I wil look into the samples.
_________________
WebSphere MQ, MB Support and Admin
Back to top
View user's profile Send private message Send e-mail
PeterPotkay
PostPosted: Tue Jul 28, 2009 12:52 pm    Post subject: Re: Java Prog to read msg Reply with quote

Poobah

Joined: 15 May 2001
Posts: 7722

asudhakar wrote:
Can any one give suggestion how to use PCF commands...

There is a whole manual dedicated to PCF commands in the MQ Info Centers.
_________________
Peter Potkay
Keep Calm and MQ On
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 Java / JMS » Java Prog to read msg
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.