Folder usr coming in the message body - ibm-mq

Using IIB 10 and MQ 9.
The problem is that when you add the mqrfh2 header, its part appears in the body:
SET OutputRoot.MQMD.CodedCharSetId = InputRoot.Properties.CodedCharSetId;
SET OutputRoot.MQMD.Format = 'MQRFH2';
SET OutputRoot.MQMD.Version = MQMD_VERSION_2;
SET OutputRoot.MQRFH2.(MQRFH2.Field)Format = 'MQRFH2';
SET OutputRoot.MQRFH2.(MQRFH2.Field)Version = MQRFH_VERSION_2;
SET OutputRoot.MQRFH2.(MQRFH2.Field)NameValueCCSID = InputRoot.Properties.CodedCharSetId;
SET OutputRoot.MQRFH2.usr.errorDescription = FIELDVALUE(Environment.Variables.exceptionMsg);

I think you need to read the documentation for an MQRFH2 message. All folders and the header of an MQRFH2 message are in the MQ message body. If the receiving application cannot handle an MQRFH2 message then treat it as a JMS message or a plain message with named properties.
In case you did not know:
MQRFH2 message == JMS message == plain message with named properties (aka message properties)
Updated:
I just noticed this line:
SET OutputRoot.MQRFH2.(MQRFH2.Field)Format = 'MQRFH2';
This is probably your problem. You are embedding an MQRFH2 message within an MQRFH2 message. Change to it the following:
SET OutputRoot.MQRFH2.(MQRFH2.Field)Format = 'MQSTR ';
This says that the message data for the MQRFH2 message is to be considered to be string data (i.e. JMSTextMessage).

Related

XMS.NET - Error while sending response back to reply queue/out queue

Regarding: “Sending response back to the out/reply queue.”
There is a requirement to send the response back to a different queue (reply queue).
While sending the response, we have to use the correlation and message id from the request message and pass it to the reply queue as header. I suspect the format of correlation/message id is wrong.
While reading the message, the correlation id and message id format are as below:
MessageId = “ID:616365323063633033343361313165646139306638346264”
CorrelationId = “ID:36626161303030305f322020202020202020202020202020”
While sending the back to out/reply queue, we are passing these ids as below:
ITextMessage txtReplyMessage = sessionOut.CreateTextMessage();
txtReplyMessage.JMSMessageID = “616365323063633033343361313165646139306638346264”;
txtReplyMessage.JMSCorrelationID = “36626161303030305f322020202020202020202020202020”;
txtReplyMessage.Text = sentMessage.Contents;
txtReplyMessage.JMSDeliveryMode = DeliveryMode.NonPersistent;
txtReplyMessage.JMSPriority = sentMessage.Priority;
messagePoducerOut.Send(txtReplyMessage);
Please note:
With the XMS.NET library, we need to pass the correlation and message id in string format as per shown above
With MQ API’s (which we were using earlier) passing the correlation and message ids we use to send in bytes format like below:
MQMessage queueMessage = new MQMessage();
string[] parms = document.name.Split('-');
queueMessage.MessageId = StringToByte(parms[1]);
queueMessage.CorrelationId = StringToByte(parms[2]);
queueMessage.CharacterSet = 1208;
queueMessage.Encoding = MQC.MQENC_NATIVE;
queueMessage.Persistence = 0; // Do not persist the replay message.
queueMessage.Format = "MQSTR ";
queueMessage.WriteString(document.contents);
queueOut.Put(queueMessage);
queueManagerOut.Commit();
Please help to troubleshoot the problem.
Troubleshooting is a bit difficult because you haven’t clearly specified the trouble (is there an exception, or is the message just not be correlated successfully?).
In your code you have missed to add the “ID:” prefix. However, to address the requirements, you should not need to bother too much about what is in this field, because you simply need to copy one value to the other:
txtReplyMessage.JMSCorrelationID = txtRequestMessage.JMSMessageID
A bit unclear what the issue is. Are you able to run the provided examples in the MQ tools/examples? This approach uses tmp queues(AMQ.*) as JMSReplyTo
Start the "server" application first.
Request/Response Client: "SimpleRequestor"
Request/Response Server: "SimpleRequestorServer"
You can find the exmaples at the default install location(win):
"C:\Program Files\IBM\MQ\tools\dotnet\samples\cs\xms\simple\wmq"
The "SimpleMessageSelector" will show how to use the selector pattern.
Note the format on the selector: "JMSCorrelationID = '00010203040506070809'"
IBM MQ SELECTOR

XMS IBytesMessage causing problems with split ZIP file

Since upgrading MQ to "IBM MQ Explorer V9.1", the XMS libraries that always worked in previous versions have started behaving differently.
Essentially, the code still recognises the messages as IBytesMessage type, and successfully writes them to file via a Byte array, but the file itself, which is a split zip file, fails to reconstitute itself.
Here's the lions share of that code:
Dim FactoryFactory As XMSFactoryFactory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ)
'Create a ConnectionFactory Object
cfConnectionFactory = FactoryFactory.CreateConnectionFactory()
'this variable will contain the full path of any file downloaded from MQ
Dim strMQMessageOutputFileDestinationFilePath As String = ""
'This variable will be used to evaluate whether the MQ Message Output file exists
Dim fiMQMessageOutputFile As FileInfo = Nothing
'Set various Connection Factory properties
cfConnectionFactory.SetStringProperty(XMSC.WMQ_HOST_NAME, Me.HostName)
cfConnectionFactory.SetIntProperty(XMSC.WMQ_PORT, 1414)
cfConnectionFactory.SetStringProperty(XMSC.WMQ_CHANNEL, "SYSTEM.DEF.SVRCONN")
cfConnectionFactory.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, 1)
cfConnectionFactory.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, Me.QueueManager)
cfConnectionFactory.SetIntProperty(XMSC.WMQ_BROKER_VERSION, 0)
'Create a new Iconnection object via the Connection Factory
connection = cfConnectionFactory.CreateConnection()
'Create a sesion via the Connection Object, using ClientAcknowledge mode
'ClientAcknowledge is being used because it allows us to control precisely
'when a message should be removed from the queue
session = connection.CreateSession(False, AcknowledgeMode.ClientAcknowledge)
'Create a destination using the Session Object
destination = session.CreateQueue(Me.mstrDestinationURI)
destination.SetIntProperty(XMSC.DELIVERY_MODE, 1)
'Create a consumer using the Session & Destination Objects
Consumer = session.CreateConsumer(destination)
connection.Start()
'IMessage is the base class that is returned from the Consumer's Receive method
Dim recvMsg As IMessage = Nothing
' Retrieve message from Queue
recvMsg = Consumer.ReceiveNoWait
strFileNameFromMsg = If(Not recvMsg.PropertyExists("fileName"), "",
recvMsg.GetStringProperty("fileName"))
If TypeOf (recvMsg) Is IBytesMessage Then
'Binary Message
Dim msg As IBytesMessage = CType(recvMsg, IBytesMessage)
Dim buffer(msg.BodyLength) As Byte
msg.ReadBytes(buffer)
Dim content As String = Text.Encoding.UTF8.GetString(buffer)
'The PrepareDestinationFile Function will generate a unique file name for the new file
'and ensure that the file does not already exist on the drive
strMQMessageOutputFileDestinationFilePath = PrepareDestinationFile(strFileNameFromMsg)
'A FileStream object is needed to write a binary array to a file
Dim fsZipFile As FileStream = New FileStream(strMQMessageOutputFileDestinationFilePath, FileMode.Create)
'Write the contents of the Byte Array to the File via the FileStream object
fsZipFile.Write(buffer, 0, buffer.Length)
fsZipFile.Close()
End If
So, the code doesn't throw any kind of exception - the code still recognises the messages as IBytesMessage, but the files won't unzip correctly.
Oddly, If we use rfhutilc.exe, we can manually pull files provided we set the Write options as No Headers and not Include MQMD - but the code above always worked in the previous version of MQ / XMS
Any assistance you can provide would be very much appreciated.

What is the correct way of adding RFH2 header to IBM MQ message

I have recently started working with IBM MQ (v7.5) and currently working on a bridge like service for 2 way data transfer between MQ & another REST service I have.
By using standard APIs I am able to read and write messages without any issue.
But the problem I am facing came when I started setting up MQRFH2 header to my messages. I must be doing some mistake while writing data with header because every time I am getting "End of file exception ('MQMessage.seek()')." error while reading those messages.
This is my code snippet while putting the message into MQ:
//Constructing message
MQMessage sendmsg = new MQMessage();
sendmsg.characterSet = 1208;
sendmsg.format = MQC.MQFMT_STRING;
sendmsg.feedback = MQC.MQFB_NONE;
sendmsg.messageType = MQC.MQMT_DATAGRAM;
sendmsg.replyToQueueName = outputBackupQueueName;
sendmsg.replyToQueueManagerName = queueManager;
//Constructing header
MQRFH2 rfh2 = new MQRFH2();
rfh2.setEncoding(MQConstants.MQENC_NATIVE);
rfh2.setCodedCharSetId(MQConstants.MQCCSI_INHERIT);
rfh2.setFormat(MQConstants.MQFMT_STRING);
rfh2.setNameValueCCSID(1208);
//adding message to header
rfh2.write(sendmsg);
//payload is the actual data which we want to send
byte[] messageBytes = payload.getBytes("UTF-8");
sendmsg.write(messageBytes);
//putting message to MQ
MQPutMessageOptions outputMsgOpt = new MQPutMessageOptions();
outputMsgOpt.options = MQConstants.MQPMO_FAIL_IF_QUIESCING |
MQConstants.MQPMO_DEFAULT_CONTEXT |
MQConstants.MQPMO_SYNCPOINT;
outputQueue.put(sendmsg, outputMsgOpt);
queueManager.commit();
And this is how I am trying to retrieve it later:
MQMessage incomingMessage = new MQMessage();
byte[] incomingMessageId = incomingMessage.messageId;
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = MQConstants.MQGMO_FAIL_IF_QUIESCING |
MQConstants.MQGMO_CONVERT |
MQConstants.MQGMO_SYNCPOINT |
MQConstants.MQGMO_LOGICAL_ORDER |
MQConstants.MQGMO_ALL_MSGS_AVAILABLE |
MQConstants.MQGMO_WAIT;
inputQueue.get(incomingMessage, gmo);
MQRFH2 myRfh2 = new MQRFH2(incomingMessage); //this statement throws error with headers
Complete error message is:
com.ibm.mq.headers.MQDataException: MQJE001: Completion Code '2', Reason '2195'.
at com.ibm.mq.headers.MQDataException.getMQDataException(MQDataException.java:317)
at com.ibm.mq.headers.internal.Header.read(Header.java:620)
at com.ibm.mq.headers.MQRFH2.<init>(MQRFH2.java:113)
at com.simility.util.MQRfh2HeaderHelper.getMsgByteArray(MQRfh2HeaderHelper.java:16)
at com.simility.mq.SimilityMQBridge.main(SimilityMQBridge.java:182)
Caused by: com.ibm.mq.headers.MQDataException: MQJE001: Completion Code '2', Reason '6114'.
at com.ibm.mq.headers.MQDataException.getMQDataException(MQDataException.java:314)
at com.ibm.mq.headers.MQRFH2.read(MQRFH2.java:184)
at com.ibm.mq.headers.internal.Header.read(Header.java:639)
at com.ibm.mq.headers.internal.Header.read(Header.java:617)
... 3 more
Caused by: java.io.EOFException: MQJE086: End of file exception ('MQMessage.seek()').
at com.ibm.mq.MQMessage.seek(MQMessage.java:716)
at com.ibm.mq.headers.internal.store.MQMessageStore.readFrom(MQMessageStore.java:274)
at com.ibm.mq.headers.internal.Header.read(Header.java:661)
at com.ibm.mq.headers.MQRFH2.read(MQRFH2.java:181)
Another thing I verified is message length by "TotalMessageLength", and that matches between reading and writing the messages, but still the failure happens.
Can anyone please help me out or point me in right direction related to adding and retrieving messages with RFH2 header ?
Another thing I verified is message length by "TotalMessageLength",
and that matches between reading and writing the messages, but still
the failure happens.
Does the method "getMessageLength()" of MQMessage return the data length of the payload?
Why don't you try (in the sender):
byte[] messageBytes = payload.getBytes();
If your data is not the same codepage or encoding then let MQ do the work rather than you doing getBytes("UTF-8").
i.e. Set the Encoding and CCSID to what the data is.
rfh2.setEncoding(???);
rfh2.setCodedCharSetId(???);

How to set message bus message type to JSON?

I am using the HelloTextGoogleCast sample's receiver.html. But I need to set the message bus's message type to JSON.
Here is part of it.
// create a CastMessageBus to handle messages for a custom namespace
window.messageBus =
window.castReceiverManager.getCastMessageBus(
'urn:x-cast:com.google.cast.sample.helloworld');
I tried this right after the above code. But it does not work:
window.messageBus = window.castReceiverManager.getCastMessageBus(cast.receiver.CastMessageBus.MessageType.JSON);
Use
window.messageBus =
window.castReceiverManager.getCastMessageBus(
'urn:x-cast:com.google.cast.sample.helloworld', cast.receiver.CastMessageBus.MessageType.JSON);

MAPI Control Multiple attachments

I am trying to send an email with multiple attachments using the VB6 MAPIMessages control.
1) I am able to use this control to send a single attachment but it displays an error saying "Attachment not found", if I try to send more than one file.
2) I also need to suppress the warning message when I try to send an email
Any ideas?
Here's the code:
MAPISession1.SignOn
MAPIMessages1.SessionID = MAPISession1.SessionID
MAPIMessages1.Compose
MAPIMessages1.RecipDisplayName = "abbid_siddiqui#hotmail.com"
MAPIMessages1.MsgSubject = "MAPI subject with attachments"
MAPIMessages1.MsgNoteText = "This is atest"
MAPIMessages1.AttachmentIndex = 0
MAPIMessages1.AttachmentName = "test.csv"
MAPIMessages1.AttachmentPathName = "C:\test.csv"
MAPIMessages1.AttachmentIndex = 1
MAPIMessages1.AttachmentName = "holidays_2013.xls"
MAPIMessages1.AttachmentPathName = "E:\holidays_2013.xls"
MAPIMessages1.ResolveName
'Send the e-mail message to the Recipient
MAPIMessages1.Send
Try setting the AttachmentPosition property to the same value as the AttachmentIndex

Resources