Author |
Message
|
vivekkooks |
Posted: Tue Jul 22, 2003 6:56 am Post subject: problem in sending data |
|
|
 Voyager
Joined: 11 Jun 2003 Posts: 91
|
Hello,
Can I pass the data structures using mqseries?
e.g:
Struct s{
int x;
char y;
string z;
}; |
|
Back to top |
|
 |
mrlinux |
Posted: Tue Jul 22, 2003 7:11 am Post subject: |
|
|
 Grand Master
Joined: 14 Feb 2002 Posts: 1261 Location: Detroit,MI USA
|
yes _________________ Jeff
IBM Certified Developer MQSeries
IBM Certified Specialist MQSeries
IBM Certified Solutions Expert MQSeries |
|
Back to top |
|
 |
vivekkooks |
Posted: Tue Jul 22, 2003 8:30 am Post subject: |
|
|
 Voyager
Joined: 11 Jun 2003 Posts: 91
|
But how do I construct the same object at receiver end?
The problem is I have to put the data into character buffer which I can send using mqseries. But when I retrieve the message , I cannot parse it correctly as size of(struct) != buffer size. |
|
Back to top |
|
 |
vivekkooks |
Posted: Tue Jul 22, 2003 8:38 am Post subject: |
|
|
 Voyager
Joined: 11 Jun 2003 Posts: 91
|
But how do I construct the same object at receiver end?
The problem is I have to put the data into character buffer which I can send using mqseries. But when I retrieve the message , I cannot parse it correctly as size of(struct) != buffer size. |
|
Back to top |
|
 |
mrlinux |
Posted: Tue Jul 22, 2003 9:45 am Post subject: |
|
|
 Grand Master
Joined: 14 Feb 2002 Posts: 1261 Location: Detroit,MI USA
|
Well it should be equal, post/email your code for both ends and I will look at it. if you post more eyes will see it. _________________ Jeff
IBM Certified Developer MQSeries
IBM Certified Specialist MQSeries
IBM Certified Solutions Expert MQSeries |
|
Back to top |
|
 |
vivekkooks |
Posted: Tue Jul 22, 2003 10:03 am Post subject: |
|
|
 Voyager
Joined: 11 Jun 2003 Posts: 91
|
#include <iostream>
#include <string>
#include <cstdio>
#include <sstream>
using namespace std;
struct s
{
int x;
char y;
string str;
};
int main()
{
s st ;
st.x = 100;
st.y = 'y';
st.str = "Hello";
ostringstream ostr;
ostr<<st.x<<st.y<<st.str<<endl; // copy the struct data
(now ostr will contain "100yHello". this is < size of struct)
ImqQueueManager mgr; // Queue manager
ImqQueue queue; // Queue
ImqMessage msg; // Data message
mgr.setName( "testMQM" )
mgr.connect( )
queue.setConnectionReference( mgr );
queue.setName("TESTQUEUE")
// Open the target message queue for output
queue.setOpenOptions( MQOO_OUTPUT /* open queue for output */
+ MQOO_FAIL_IF_QUIESCING ); /* but not if MQM stopping */
queue.open( );
msg.setFormat( MQFMT_STRING );
msg.write(ostr.str(),strlen((ostr.str()).c_str());
queue.put( msg );
Now If I use queue.get(msg) then I wont be able to parse the message to again form the struct object.
i.e. I cant read first 4 bytes for st.x (int) as it occupied only 3 bytes("100"). |
|
Back to top |
|
 |
Ratan |
Posted: Tue Jul 22, 2003 11:03 am Post subject: |
|
|
 Grand Master
Joined: 18 Jul 2002 Posts: 1245
|
I am not an expert of MQSeries, but I suppose you can use a delimiter to parse it. Better yet, use XML. _________________ -Ratan |
|
Back to top |
|
 |
mrlinux |
Posted: Tue Jul 22, 2003 11:38 am Post subject: |
|
|
 Grand Master
Joined: 14 Feb 2002 Posts: 1261 Location: Detroit,MI USA
|
Well Iam not C++ expert but it looks like when you are building the
message it is converting the number to a string, which is not what you want, can you view the message in hex while it is on the queue ????
if not checkout this software
http://www.mqseries.net/pafiledb203/pafiledb.php?PHPSESSID=955c0219422f0e9863fbe35351ec7953&action=viewfile&fid=52&id=8
If the first 3 bytes in the message in hex are 31 30 30 then your c++ code
is converting your data to strings. _________________ Jeff
IBM Certified Developer MQSeries
IBM Certified Specialist MQSeries
IBM Certified Solutions Expert MQSeries |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue Jul 22, 2003 1:29 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Your C code is writing out a string representation of your struct. If you then want to read that back off the queue and convert it back into your struct, you will need to explicitly take the first set of characters off the string and convert them to an integer, and then take the next character and then take the rest and use them as a string.
But actually,you probably want to write out your struct as bytes, and then you can read the bytes on the other end and cast that back into your struct.
This is similar to what's done with Java objects. |
|
Back to top |
|
 |
vivekkooks |
Posted: Wed Jul 23, 2003 12:29 am Post subject: |
|
|
 Voyager
Joined: 11 Jun 2003 Posts: 91
|
yes, so can I write objects as bytes to MQSeries? |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Jul 23, 2003 5:13 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
vivekkooks wrote: |
yes, so can I write objects as bytes to MQSeries? |
Yes.
The message buffer is just that, a buffer. You'll want to set the format to MQFT_NONE, though. |
|
Back to top |
|
 |
psanders |
Posted: Wed Jul 23, 2003 6:44 am Post subject: |
|
|
Apprentice
Joined: 02 Apr 2002 Posts: 27
|
I like to place message data in character format so if I want to change platforms I don't get into trouble. XML is even better! |
|
Back to top |
|
 |
psanders |
Posted: Wed Jul 23, 2003 6:47 am Post subject: |
|
|
Apprentice
Joined: 02 Apr 2002 Posts: 27
|
I like to place message data in character format so if I want to change platforms I don't get into trouble. XML is even better! |
|
Back to top |
|
 |
|