5.1. Creating and Closing Clients and Sessions
All of the examples in this section have been written using the Apache Qpid C++ API, which is the C++ API for MRG Messaging. The examples use the same skeleton code to initialize the program, create a session, and clean up before exiting:
#include <qpid/client/Dispatcher.h>
#include <qpid/client/Connection.h>
#include <qpid/client/Session.h>
#include <qpid/client/Message.h>
#include <qpid/client/MessageListener.h>
#include <unistd.h>
#include <cstdlib>
#include <iostream>
using namespace qpid::client;
using namespace qpid::framing;
int main() {
Connection connection;
Message msg;
try {
connection.open("127.0.0.1", 5672);
Session session = connection.newSession();
//--------- Main body of program --------------------------------------------
//--------- Cleanup ------------ --------------------------------------------
connection.close();
return 0;
} catch(const std::exception& error) {
std::cout << error.what() << std::endl;
}
return 1;
}