当前位置:首页 > activemq-cpp开发手册
6 消息类型
CMS支持TextMessage, MapMessage, ByteMessage, ObjectMessage四种消息类型,其都继承自cms::Message类型。
以上几个消息类都是抽象类,不能直接实例化。在实际使用中通常以指针形式出现,指向由调用Session类的方法创建的具体实类。
指向具体消息类的指针在消息发送时向上转换成基类指针Message*, 接收又将基类指针强制向下转换成具体的消息类型指针。如
发送时:
TextMessage* txt=session.createTextMessage(); txt->setText(“hello world\\n”);
sender.send(txt); // send参数是Message* 做向上转换 接收时:
virtual void onMessage(const Message* msg){ // 强制向下转换
TextMessage* txt=dynamic_cast
6.1 cms::Message 6.1.1 概述
cms::Message是cms中所有消息的抽象基类,包含三部分:消息头,消息体,用户定义属性。 详情参考http://activemq.apache.org/cms/api_docs/activemqcpp-2.1/classcms_1_1_message.html
6.1.2 接口
6.1.2.1 virtual cms::Message::~Message ( ) [inline, virtual] 6.1.2.2 virtual Message* cms::Message::clone () const [pure
virtual]
Clone this message exactly, returns a new instance that the caller is required to delete. Returns:
new copy of this message
6.1.2.3 virtual void cms::Message::acknowledge () const throw
( CMSException ) [pure virtual]
Acknowledges all consumed messages of the session of this consumed message.
All consumed CMS messages support the acknowledge method for use when a client has specified that its CMS session's consumed messages are to be explicitly acknowledged. By invoking acknowledge on a consumed message, a client acknowledges all messages consumed by the session that the message was delivered to.
Calls to acknowledge are ignored for both transacted sessions and sessions specified to use implicit acknowledgement modes.
A client may individually acknowledge each message as it is consumed, or it may choose to acknowledge messages as an application-defined group (which is done by calling acknowledge on the last received message of the group, thereby acknowledging all messages consumed by the session.)
Messages that have been received but not acknowledged may be redelivered.
6.1.2.4 virtual void cms::Message::clearBody () [pure virtual]
Clears out the body of the message.
This does not clear the headers or properties.
6.1.2.5 virtual void cms::Message::clearProperties () [pure
virtual]
Clears out the message body.
Clearing a message's body does not clear its header values or property entries.
If this message body was read-only, calling this method leaves the message body in the same state as an empty body in a newly created message.
6.1.2.6 Virtual std::vector
cms::Message::getPropertyName () const [pure virtual]
Retrieves the propery names.
Returns:
The complete set of property names currently in this message.
6.1.2.7 virtual bool cms::Message::propertyExists ( const
std::string & name) const [pure virtual]
Indicates whether or not a given property exists.
Parameters: name The name of the property to look up.
Returns:
True if the property exists in this message.
6.1.2.8 virtual bool cms::Message::getBooleanProperty (const
std::string & name) const throw ( CMSException ) [pure virtual]
Gets a boolean property.
Parameters: name The name of the property to retrieve.
Returns:
The value for the named property.
Exceptions: CMSException if the property does not exist.
6.1.2.9 virtual unsigned char cms::Message::getByteProperty
( const std::string & name) const throw ( CMSException ) [pure virtual]
Gets a byte property.
Parameters: name The name of the property to retrieve.
Returns:
The value for the named property.
Exceptions: CMSException if the property does not exist.
6.1.2.10 virtual double cms::Message::getDoubleProperty
( const std::string & name) const throw ( CMSException ) [pure virtual]
Gets a double property.
Parameters: name The name of the property to retrieve.
Returns:
The value for the named property.
Exceptions: CMSException if the property does not exist.
共分享92篇相关文档