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 » General Discussion » problem in sending data

Post new topic  Reply to topic
 problem in sending data « View previous topic :: View next topic » 
Author Message
vivekkooks
PostPosted: Tue Jul 22, 2003 6:56 am    Post subject: problem in sending data Reply with quote

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
View user's profile Send private message
mrlinux
PostPosted: Tue Jul 22, 2003 7:11 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
vivekkooks
PostPosted: Tue Jul 22, 2003 8:30 am    Post subject: Reply with quote

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
View user's profile Send private message
vivekkooks
PostPosted: Tue Jul 22, 2003 8:38 am    Post subject: Reply with quote

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
View user's profile Send private message
mrlinux
PostPosted: Tue Jul 22, 2003 9:45 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
vivekkooks
PostPosted: Tue Jul 22, 2003 10:03 am    Post subject: Reply with quote

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
View user's profile Send private message
Ratan
PostPosted: Tue Jul 22, 2003 11:03 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
mrlinux
PostPosted: Tue Jul 22, 2003 11:38 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
jefflowrey
PostPosted: Tue Jul 22, 2003 1:29 pm    Post subject: Reply with quote

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
View user's profile Send private message
vivekkooks
PostPosted: Wed Jul 23, 2003 12:29 am    Post subject: Reply with quote

Voyager

Joined: 11 Jun 2003
Posts: 91

yes, so can I write objects as bytes to MQSeries?
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Wed Jul 23, 2003 5:13 am    Post subject: Reply with quote

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
View user's profile Send private message
psanders
PostPosted: Wed Jul 23, 2003 6:44 am    Post subject: Reply with quote

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
View user's profile Send private message
psanders
PostPosted: Wed Jul 23, 2003 6:47 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » General Discussion » problem in sending data
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.