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
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