Hi Petr, just a guess: aren't you destroying instance of your class meantime? I.e. having declared in a block and trying to use its Session outside the block or so?
Can you access the instance of your class and its connection at the place when calling Send() method for the second time? Btw. you can even optimize our (currently not working) approach by sharing Sender object, instead of Session (until you need to send to various addresses). Kind regards, Pavel ----- Original Message ----- > From: "Petr Parýzek" <[email protected]> > To: [email protected] > Sent: Thursday, June 27, 2013 3:37:28 PM > Subject: C++ client question > > Hi, > I was try to encapsulate qpid client into this simple class > > class MySender > { > private: > Connection *pConn; > > public: > MySender() {pConn = NULL;} > ~MySender() { if (pConn != NULL) delete pConn;} > > void Send(const char *Addr, const char *Msg) > {if (pConn == NULL) pConn = new Connection(URL); > > try > {if (!pConn->isOpen()) pConn->open(); > > Session session = pConn->createSession(); > qpid::messaging::Sender sender = session.createSender(Addr); > > sender.send(Message(Msg)); > } > catch(const std::exception& error) > {std::cerr << error.what() << std::endl; > pConn->close(); > } > } > }; > > In my program I have one global instance of this class and use its method > Send(). It's simple and it works. However, it is not very effective. I would > like to don't always create a new instance of Session and its Sender. But > when I create a Session only once and save pointer to it in some member > variable, it stop working. Second call of Send() method throws an exception. > So I ask, how to keep one instance of a Session between calls? > > Thanks > > Petr > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
