2014-01-06 01:50:41 +08:00
|
|
|
/**
|
|
|
|
|
* Message.h
|
|
|
|
|
*
|
|
|
|
|
* An incoming message has the same sort of information as an outgoing
|
|
|
|
|
* message, plus some additional information.
|
|
|
|
|
*
|
|
|
|
|
* Message objects can not be constructed by end users, they are only constructed
|
2015-01-26 21:47:30 +08:00
|
|
|
* by the AMQP library, and passed to user callbacks.
|
2014-01-06 01:50:41 +08:00
|
|
|
*
|
|
|
|
|
* @copyright 2014 Copernica BV
|
|
|
|
|
*/
|
|
|
|
|
|
2015-11-01 17:48:13 +08:00
|
|
|
/**
|
|
|
|
|
* Include guard
|
|
|
|
|
*/
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2014-01-06 01:50:41 +08:00
|
|
|
/**
|
|
|
|
|
* Set up namespace
|
|
|
|
|
*/
|
2015-04-28 16:58:49 +08:00
|
|
|
namespace AMQP {
|
2014-01-06 01:50:41 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class definition
|
|
|
|
|
*/
|
|
|
|
|
class Message : public Envelope
|
|
|
|
|
{
|
|
|
|
|
protected:
|
|
|
|
|
/**
|
|
|
|
|
* The exchange to which it was originally published
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
std::string _exchange;
|
2015-04-28 16:58:49 +08:00
|
|
|
|
2014-01-06 01:50:41 +08:00
|
|
|
/**
|
|
|
|
|
* The routing key that was originally used
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
std::string _routingKey;
|
2015-04-28 16:58:49 +08:00
|
|
|
|
2014-01-06 01:50:41 +08:00
|
|
|
protected:
|
|
|
|
|
/**
|
|
|
|
|
* The constructor is protected to ensure that endusers can not
|
|
|
|
|
* instantiate a message
|
|
|
|
|
* @param exchange
|
|
|
|
|
* @param routingKey
|
|
|
|
|
*/
|
2014-01-06 22:49:31 +08:00
|
|
|
Message(const std::string &exchange, const std::string &routingKey) :
|
|
|
|
|
Envelope(nullptr, 0), _exchange(exchange), _routingKey(routingKey)
|
2014-01-06 01:50:41 +08:00
|
|
|
{}
|
2015-04-28 16:58:49 +08:00
|
|
|
|
2014-01-06 01:50:41 +08:00
|
|
|
public:
|
2015-04-28 16:58:49 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Copy constructor
|
|
|
|
|
*
|
|
|
|
|
* @param message the message to copy
|
|
|
|
|
*/
|
|
|
|
|
Message(const Message &message) :
|
|
|
|
|
Envelope(message),
|
|
|
|
|
_exchange(message._exchange),
|
|
|
|
|
_routingKey(message._routingKey)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Move constructor
|
|
|
|
|
*
|
|
|
|
|
* @param message the message to move
|
|
|
|
|
*/
|
|
|
|
|
Message(Message &&message) :
|
|
|
|
|
Envelope(std::move(message)),
|
|
|
|
|
_exchange(std::move(message._exchange)),
|
|
|
|
|
_routingKey(std::move(message._routingKey))
|
|
|
|
|
{}
|
|
|
|
|
|
2014-01-06 01:50:41 +08:00
|
|
|
/**
|
|
|
|
|
* Destructor
|
|
|
|
|
*/
|
|
|
|
|
virtual ~Message() {}
|
|
|
|
|
|
2015-04-28 16:58:49 +08:00
|
|
|
/**
|
|
|
|
|
* Assignment operator
|
|
|
|
|
*
|
|
|
|
|
* @param message the message to copy
|
|
|
|
|
* @return same object for chaining
|
|
|
|
|
*/
|
|
|
|
|
Message &operator=(const Message &message)
|
|
|
|
|
{
|
|
|
|
|
// call the base assignment
|
|
|
|
|
Envelope::operator=(message);
|
|
|
|
|
|
|
|
|
|
// move the exchange and routing key
|
|
|
|
|
_exchange = message._exchange;
|
|
|
|
|
_routingKey = message._routingKey;
|
|
|
|
|
|
|
|
|
|
// allow chaining
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Move assignment operator
|
|
|
|
|
*
|
|
|
|
|
* @param message the message to move
|
|
|
|
|
* @return same object for chaining
|
|
|
|
|
*/
|
|
|
|
|
Message &operator=(Message &&message)
|
|
|
|
|
{
|
|
|
|
|
// call the base assignment
|
|
|
|
|
Envelope::operator=(std::move(message));
|
|
|
|
|
|
|
|
|
|
// move the exchange and routing key
|
|
|
|
|
_exchange = std::move(message._exchange);
|
|
|
|
|
_routingKey = std::move(message._routingKey);
|
|
|
|
|
|
|
|
|
|
// allow chaining
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-06 01:50:41 +08:00
|
|
|
/**
|
|
|
|
|
* The exchange to which it was originally published
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2014-01-06 04:21:09 +08:00
|
|
|
const std::string &exchange() const
|
2014-01-06 01:50:41 +08:00
|
|
|
{
|
|
|
|
|
return _exchange;
|
|
|
|
|
}
|
2015-04-28 16:58:49 +08:00
|
|
|
|
2014-01-06 01:50:41 +08:00
|
|
|
/**
|
|
|
|
|
* The routing key that was originally used
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2014-01-06 04:21:09 +08:00
|
|
|
const std::string &routingKey() const
|
2014-01-06 01:50:41 +08:00
|
|
|
{
|
|
|
|
|
return _routingKey;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* End of namespace
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|