• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Connecting to MQ Series from a java app

 
Ranch Hand
Posts: 271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I have this simple java program (code shown below) to connect and get message from an mq series queue.When I run it I get the exception shown below .The message , however disappears from the queue which means the getting is working.I debugged and realize the code is failing on the line "System.out.println("Received message : "+ testRes.readLine()); "
java.io.UnsupportedEncodingException: Cp437
at sun.io.Converters.getConverterClass(Converters.java:121)
at sun.io.Converters.newConverter(Converters.java:152)
at sun.io.ByteToCharConverter.getConverter(ByteToCharConverter.java:81)
at java.io.InputStreamReader.<init>(InputStreamReader.java:93)
at com.ibm.mq.MQMessage.readConvertedLine(MQMessage.java:626)
at com.ibm.mq.MQMessage.readLine(MQMessage.java:475)
at SCVDirect.<init>(SCVDirect.java:52)
at Receiver.main(Receiver.java:18)

Here is the code :
import com.ibm.mq.*;
import java.io.*;
/**
* @author mutuj
*
* To change this generated comment edit the template variable "typecomment":
* Window>Preferences>Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
public class Receiver {
private String qManager = "COFQM1";
private MQQueueManager qMgr;

public static void main(String[] args) {
new Receiver();
}
public Receiver() {
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
MQQueue qsres = null;
try {
//create connection to queue manager
qMgr = new MQQueueManager(qManager);
qsres = qMgr.accessQueue("QSRES", openOptions);
MQMessage testRes = new MQMessage();

while (true) {
qsres.get(testRes);
System.out.println("Received message : "+ testRes.readLine());
}
} catch (MQException mqex) {
System.out.println(
"A websphere error occured : Completion code "
+ mqex.completionCode
+ "Reason code "
+ mqex.reasonCode);
mqex.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
qsres.close();
qMgr.disconnect();
} catch (MQException mqex) {
System.out.println(
"A websphere error occured : Completion code "
+ mqex.completionCode
+ "Reason code "
+ mqex.reasonCode);
mqex.printStackTrace();
} catch (Exception ex) {
}
}
}
}

jeff
 
jeff mutonho
Ranch Hand
Posts: 271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just realized now that when I put more than one message I get the following error message
MQJE001: Completion Code 2, Reason 2033
A websphere error occured : Completion code 2Reason code 2033
com.ibm.mq.MQException: MQJE001: Completion Code 2, Reason 2033
at com.ibm.mq.MQQueue.get(MQQueue.java:822)
at com.ibm.mq.MQQueue.get(MQQueue.java:1006)
at SCVDirect.<init>(SCVDirect.java:51)
at Receiver.main(Receiver.java:18)
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, I tink you need to set the MQGetMessageOptions before doing the get.

Error code 2033 means the Queue is empty.

Try this
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options= MQC.MQGMO_NO_SYNCPOINT; //Set no sync point
gmo.options= MQC.MQGMO_CONVERT; //Handles ASCII/EBCDIC
gmo.options= MQC.MQGMO_WAIT;//Wait until message arrives
gmo.waitInterval= 30000;

this will allow you to wait for the queue.

Also you might want to put in a while(i<5) ie. loop for 5 times
and slap the readString inbetwn that...

Hope this helps....
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic