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 » Setting the message id in a VB.NET application

Post new topic  Reply to topic Goto page 1, 2  Next
 Setting the message id in a VB.NET application « View previous topic :: View next topic » 
Author Message
Brody
PostPosted: Wed Mar 16, 2005 10:33 am    Post subject: Setting the message id in a VB.NET application Reply with quote

Novice

Joined: 16 Mar 2005
Posts: 12

Hello all!

My co-worker and I are unfortunately new to MQ and also coding with .NET. We have made a lot of progress, but we have hit a wall the last 2 days. We have been attempting to put our own value into the MQMD MessageId on a message. Our sample program is below. At first it appeared that we were having type issues being that we were trying to assign the message id a string value, but we did a lot of searches and figured out how to convert the string to the byte array type it was looking for. This still isn't working, and now we don't know where to go from here. As far as we can tell, only the first character of the string is being assigned to the message id. So, in the case of the code below, we are trying to assign the message id a value of "testid1". When we look at the message id after putting a message on a queue with this application, it only shows a "t". Any help would be greatly appreciated. Thanks!

**************************

Imports System
Imports IBM.WMQ
Imports System.Text

Module TestPut

Sub main()

Dim qMgr As MQQueueManager 'MQQueueManager instance
Dim mqQueue As MQQueue 'MQQueue instance
Dim Msg As MQMessage 'MQMessage instance
Dim pmo As MQPutMessageOptions 'MQPutMessageOptions instance
Dim qName As String 'Name of queue to use
Dim qManager As String 'Name of the queue manager
Dim message As String 'Message buffer
Dim openOptions As Integer 'Open Options
Dim strTest As String

strTest = "6789"

'set Environmental variables in order to connect to the MQ server
MQEnvironment.Hostname = "<hostname>"
MQEnvironment.Channel = "CHANNEL1"
MQEnvironment.Port = 1415

qManager = "<queuemanager name>"
qName = "<queue name>"

'Try to create an instance of the qMgr
Try
qMgr = New MQQueueManager(qManager)
Catch mqe As IBM.WMQ.MQException
'stop if failed
System.Console.WriteLine("create of MQQueueManager ended with {0}", mqe.Message)
'Return (mqe.Reason)
End Try

'Try to open the queue
Try
openOptions = MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING
mqQueue = qMgr.AccessQueue(qName, openOptions) 'open queue for output but not if MQM stopping
Catch mqe As IBM.WMQ.MQException
'stop if failed
System.Console.WriteLine("MQqManager::AccessQueue ended with {0}", mqe.Message)
'Return (mqe.Reason)
End Try

'put the message to the queue
message = "Hellow World!"
Msg = New MQMessage
Msg.MessageId = StringToByteArray(strTest)
Msg.WriteString(message)
Msg.Format = MQC.MQFMT_STRING
pmo = New MQPutMessageOptions
Try
mqQueue.Put(Msg, pmo)
mqQueue.Close()
qMgr.Disconnect()
Catch mqe As IBM.WMQ.MQException
'report the error
System.Console.WriteLine("MQQueue::Put ended with {0}", mqe.Message)
End Try

End Sub

Public Function StringToByteArray(ByVal stringToConvert As String) As Byte()
Return (New UnicodeEncoding).GetBytes(stringToConvert)
End Function


End Module


Brody
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Wed Mar 16, 2005 10:39 am    Post subject: Re: Setting the message id in a VB.NET application Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Brody wrote:
We have been attempting to put our own value into the MQMD MessageId on a message.


Everyone who has ever tried this has run into pain and suffering, in my experience.

Message Ids are supposed to be unique.

What are you doing to verify the ID after it's been put on the queue? What does amqsbcg show for the messages you created? What do you get back from the PUT call for the MsgID in the returned MQMD?
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
Brody
PostPosted: Tue Mar 22, 2005 1:15 pm    Post subject: Re: Setting the message id in a VB.NET application Reply with quote

Novice

Joined: 16 Mar 2005
Posts: 12

jefflowrey wrote:
Everyone who has ever tried this has run into pain and suffering, in my experience.


Is this only in attempting to set the value of the message id or correlation id using .NET, or setting the value in any language?
Back to top
View user's profile Send private message
PeterPotkay
PostPosted: Tue Mar 22, 2005 4:18 pm    Post subject: Re: Setting the message id in a VB.NET application Reply with quote

Poobah

Joined: 15 May 2001
Posts: 7722

Brody wrote:
jefflowrey wrote:
Everyone who has ever tried this has run into pain and suffering, in my experience.


Is this only in attempting to set the value of the message id or correlation id using .NET, or setting the value in any language?


Any language....why do you want to make your own Message ID. the Queue Manager will create one for you that will be unique, guaranteed, and you will know what that value is after the MQPUT returns.
_________________
Peter Potkay
Keep Calm and MQ On
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Wed Mar 23, 2005 5:44 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

The pain and suffering usually comes not from the code to set the message Id or Correl ID.

It comes from the design behind the desire to set the message id or correl ID.

That way leads to dragons... so turn back now. Or at least tread VERY CAREFULLY.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Wed Mar 23, 2005 1:23 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

jefflowrey wrote:
The pain and suffering usually comes not from the code to set the message Id or Correl ID.

It comes from the design behind the desire to set the message id or correl ID.

That way leads to dragons... so turn back now. Or at least tread VERY CAREFULLY.

If you choose to continue on this way a little piece of advice as the minstrel says:
Beware of the dragons. They gard the treasures in their keep with a jalousy that some consider touched by evil.
Purity of intention alone will get you slain.
You need to add fortitude and purity of spirit to gain the most meager chance of returning from this your hardest of journeys.

Many have tried. Neary a one has returned.... ever!

Back to top
View user's profile Send private message Send e-mail
PeterPotkay
PostPosted: Wed Jun 22, 2005 5:01 pm    Post subject: Reply with quote

Poobah

Joined: 15 May 2001
Posts: 7722

<sigh>
Ok, I feel dumb asking this, but I have wasted an hour trying to figure it out. The .NET sample programs do not show how to do this.

A developer is asking my help on setting the CorrelID of the message in VB.NET. (Lets put aside the validity of the design for the sake of arguement - right now I just want to figure it out!)

How in the world do I get the value "Peter Potkay" into the MQMD's CorrelID field?

This is the last thing I tried (the last thing I found in .NET Help Center), and still it yells at me about "Value of type byte cannot be converted to a '1 dimensional array of byte'"
Code:

            Dim MyNewCorrelID As String = "Peter Potkay"
            Dim MyByte As Byte
            MyByte = CByte(MyNewCorrelID)
            myMsg.CorrelationId = MyByte


In the Java sample code, I found the following sample code, but it does not apply to .NET. No such method of .getBytes on the string object:
Code:

      String correlationId = "CorrelationId goes here.";
      hello_world.correlationId = correlationId.getBytes();

_________________
Peter Potkay
Keep Calm and MQ On
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Thu Jun 23, 2005 3:30 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

I think String.toCharArray and then a loop to convert each Char to a byte...
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
klamerus
PostPosted: Thu Jun 23, 2005 4:47 am    Post subject: Samples Reply with quote

Disciple

Joined: 05 Jul 2004
Posts: 199
Location: Detroit, MI

Although I'm still wondering why we want to set these IDs, I think we've hit on the "nut" of the issue - the samples and examples and documentation on all of this is very lacking.

It seems like there are two types of APIs into products: those that have an extensive set of functions/procedures with very specific parameters (like most OS APIs); and those that have a limited set of APIs, with a broad range of parameters (like SQL, Documentum, etc.).

In the second case, there is seldom enough documentation on which all parameters to use to accomplish what you need (and examples). The providers generally document the API itself, but not the specifics to the parameters you need to do what you want with it.

Anyway, it's a personal SOAP box having just struggled to try and do RESETS. IBM really needs to expand upon its documentation.
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
PeterPotkay
PostPosted: Thu Jun 23, 2005 6:34 am    Post subject: Reply with quote

Poobah

Joined: 15 May 2001
Posts: 7722

Finally got it!


Code:

Imports System.Text '<----- You need this at the top of your app to get the Encoding to work
.
.
Private msgBuffer As String = "Ba-Ba-Booey"
myMsg = New MQMessage
myMsg.WriteString(msgBuffer)
myMsg.Format = MQC.MQFMT_STRING
myMsg.Expiry = 999999
Dim MyNewCorrelID As String = "Peter Potkay"
myMsg.CorrelationId = Encoding.ASCII.GetBytes(MyNewCorrelID)

_________________
Peter Potkay
Keep Calm and MQ On
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Thu Jun 23, 2005 12:52 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

Peter,

If you remember well the reason for this is that in .NET the string representation is really Unicode 2 byte...

So before transforming into a byte array your need to transform to ASCII or UTF8 or something...

I might have tried the approach of a writer class.... but yours is probably more semantically correct for the .NET environment !

Enjoy
Back to top
View user's profile Send private message Send e-mail
PeterPotkay
PostPosted: Thu Jun 23, 2005 2:03 pm    Post subject: Reply with quote

Poobah

Joined: 15 May 2001
Posts: 7722

I coded this, and did the MQPUT:
Code:

Private msgBuffer As String = "ABCDEF"
myMsg = New MQMessage
myMsg.WriteString(msgBuffer)
Dim MyNewCorrelID As String = "ABCDEF"
myMsg.CorrelationId = Encoding.ASCII.GetBytes(MyNewCorrelID)


Using QAPSA, I went to browse the message.
The payload showed this in Hex:
41 00 42 00 43 00 44 00 45 00 46 00
And this in the text window:
A.B.C.D.E.F.

I then used QPASA's nifty feature of translating the Correl ID.
The Correl ID in Hex looked like this:
414243444546000000000000000000000000000000000000
The Correl ID in ASCII loooked like this:
ABCDEF..................

Hmmm. The payload ABCDEF was captured as UniCode, but the CorrelID ABCDEF was not. Looks like the conversion of a plain string value to a Unicode array is over ridden when I did the convert to bytes prior to using it for the Correl ID?
_________________
Peter Potkay
Keep Calm and MQ On
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Thu Jun 23, 2005 2:28 pm    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

PeterPotkay wrote:
Looks like the conversion of a plain string value to a Unicode array is over ridden when I did the convert to bytes prior to using it for the Correl ID?


Well, you explicitly asked for the ASCII representation - which is not Unicode.

So.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
PeterPotkay
PostPosted: Thu Jun 23, 2005 5:07 pm    Post subject: Reply with quote

Poobah

Joined: 15 May 2001
Posts: 7722

A-ha. When I did this:
Code:

Dim msgBuffer As String = "ABCDEF"   '* Message buffer
myMsg.CharacterSet = 437
myMsg.WriteString(msgBuffer)

The payload showed this in Hex:
41 42 43 44 45 46
And this in the text window:
ABCDEF

Makes plain sense now.

Question. If a .NET app is going to send a message to an unknown platform, is it OK to send as the default Unicode (CCSID 1200), or would it be wise to convert it to Windows ASCII first (CCSID 437)? Can Java apps running on Solaris or Cobol apps running on z/OS convert from 1200?

I though this was an interesting read:
http://www.unicode.org/standard/WhatIsUnicode.html
http://www.unicode.org/standard/principles.html

Makes me wonder, why isn't every MQ message passed around in Unicode?
_________________
Peter Potkay
Keep Calm and MQ On
Back to top
View user's profile Send private message
PeterPotkay
PostPosted: Thu Jun 23, 2005 5:14 pm    Post subject: Reply with quote

Poobah

Joined: 15 May 2001
Posts: 7722

Just found my own answer. In the Application Programming Reference, there is Appendix H, with a section titled Unicode Conversion Support, and it list all the CCSIDs that can be converted to and from Unicode.

500 and 37 are listed for z/OS, and 819 is listed for Solaris.

Still wonder if Unicode is so great, why isn't everything using it? Or is that the direction apps are slowly going to? WB-IMB uses Unicode internally, correct? UTF-8, or UTF16?
_________________
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 Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » IBM MQ API Support » Setting the message id in a VB.NET application
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.