Author |
Message
|
mathilda |
Posted: Wed May 16, 2007 9:25 am Post subject: Recieved message characterSet? |
|
|
 Novice
Joined: 16 May 2007 Posts: 16 Location: Sofia, Bulgaria
|
Hello,
I try this simple example to send and receive message from Queue ( code bellow) . Everything is OK, but when receiver get message maybe try to write to file.
If i send Cyrillic or Chinese symbols in message (for example: Send Chinese symbols and set 950 for CCSID) receiver must know what character encoding is used to get bytes for example to write to file.
Is there any chance receiver to know CCSID of message?
BR
to send :
........
Code: |
MQQueueConnectionFactory connectionFactory = null;
QueueConnection connection = null;
QueueSession session = null;
QueueSender sender = null;
QueueReceiver receiver = null;
Queue myQueue = null;
try {
connectionFactory = new MQQueueConnectionFactory();
connectionFactory.setHostName(hostName);
connectionFactory.setQueueManager("QM_manager");
//connectionFactory.setChannel(channelName); //?????????
connectionFactory.setPort(port);
connectionFactory.setTransportType(JMSC.MQJMS_TP_BINDINGS_MQ);
connectionFactory.setCCSID(ccsid);
connection = connectionFactory.createQueueConnection();
session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
myQueue = session.createQueue(queueName);
((MQQueue) myQueue).setTargetClient(1);
sender = session.createSender(myQueue);
TextMessage message = session.createTextMessage();
//System.out.println("ddd: " + message.CHARSET_PROPERTY); message.setStringProperty("JMS_IBM_Character_Set",String.valueOf(1200));
String text = "Some text";
message.setText(text);
sender.send(message);
}
catch (Exception ex) {
ex.printStackTrace();
}
finally {
try {
if ( sender != null ) {
sender.close();
}
if ( receiver != null ) {
receiver.close();
}
if ( session != null ) {
session.close();
}
if ( connection != null ) {
connection.close();
}
}
catch (Exception ex) {
}
}
}
...................
|
to Receive :
Code: |
MQQueueConnectionFactory connectionFactory = null;
QueueConnection connection = null;
QueueSession session = null;
QueueSender sender = null;
QueueReceiver receiver = null;
Queue myQueue = null;
try {
connectionFactory = new MQQueueConnectionFactory();
connectionFactory.setHostName(hostName);
connectionFactory.setQueueManager("QM_manager");
//connectionFactory.setChannel(channelName); //?????????
connectionFactory.setPort(port);
connectionFactory.setTransportType(JMSC.MQJMS_TP_BINDINGS_MQ);
connectionFactory.setCCSID(ccsid);
connection = connectionFactory.createQueueConnection();
session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
myQueue = session.createQueue(queueName);
((MQQueue) myQueue).setTargetClient(1);
receiver = session.createReceiver(myQueue);
JMSTextMessage recMsg = (JMSTextMessage )receiver.receive(1);
String recString = recMsg.getText();
}
catch (Exception ex) {
ex.printStackTrace();
}
finally {
try {
if ( sender != null ) {
sender.close();
}
if ( receiver != null ) {
receiver.close();
}
if ( session != null ) {
session.close();
}
if ( connection != null ) {
connection.close();
}
}
catch (Exception ex) {
}
}
}
...................
|
_________________ On any given Sunday you're gonna win or you're gonna lose. The point is
- can you win or lose like a man? |
|
Back to top |
|
 |
marcin.kasinski |
Posted: Wed May 16, 2007 10:18 am Post subject: Re: Recieved message characterSet? |
|
|
Sentinel
Joined: 21 Dec 2004 Posts: 850 Location: Poland / Warsaw
|
You dont need to know remote application CCSID.
When you get message in your application just set CONVERT option.
In this situation QMGR you are connected to convert input message into your application CCSID. _________________ Marcin |
|
Back to top |
|
 |
mathilda |
Posted: Wed May 16, 2007 10:26 am Post subject: |
|
|
 Novice
Joined: 16 May 2007 Posts: 16 Location: Sofia, Bulgaria
|
To set CONVERT on channel? _________________ On any given Sunday you're gonna win or you're gonna lose. The point is
- can you win or lose like a man? |
|
Back to top |
|
 |
marcin.kasinski |
Posted: Wed May 16, 2007 10:44 am Post subject: |
|
|
Sentinel
Joined: 21 Dec 2004 Posts: 850 Location: Poland / Warsaw
|
mathilda wrote: |
To set CONVERT on channel? |
You can do it on channel. _________________ Marcin |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed May 16, 2007 7:47 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
OK guys get real....
Mathilda is talking about JMS so here it goes...
a) set the CCSID x on the qcf object. So the qmgr will know you are sending textmessages in CCSID x which may be different from the ccsid of the qmgr...
b) on the receiving qmgr do nothing. JMS TextMessage does automatically a get with Convert... The user has nothing to do....
If the receiving app has a different CCSID than the receiving qmgr see point a...
c) make sure there is a default translation existing between the receiving qmgr CCSID and the message CCSID.
d) as a word of caution: make sure you have the full client installed and the library/jar files being pointed at are the original ones in their respective original directory otherwise you might get a CCSID conversion not supported...
Enjoy
 _________________ MQ & Broker admin |
|
Back to top |
|
 |
mathilda |
Posted: Wed May 16, 2007 11:43 pm Post subject: |
|
|
 Novice
Joined: 16 May 2007 Posts: 16 Location: Sofia, Bulgaria
|
Thanks guys
If i understand correctly, when use TextMessage and send message - i set CCSID x of message and problem maybe is the conversion between CCSID of message and CCSID of QMNGR?
When receive message i set CCSID z on MQQueueConnectionFactory - problem maybe is conversion between CCSID on connectionFactory and CCSID on QMNGR?
And last - because for the moment i don't need to use channel, but only on channel properties i find property CONVERTED - when i use TextMessage (MQSTR) is always have CONVERTED is ON or is another way to switch on/of of this property?
Thanks _________________ On any given Sunday you're gonna win or you're gonna lose. The point is
- can you win or lose like a man? |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu May 17, 2007 5:30 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
If you want not to convert use a bytes message....  _________________ MQ & Broker admin |
|
Back to top |
|
 |
|