0

以前、いくつかのプロジェクトで activemqcpp API を使用したことがありますが、メッセージのタイプが事前にわかっていたので、対応するメッセージ サブクラスへの動的キャストは安全でした。

現在、MQ ライブラリのラッパーを構築していますが、ベース メッセージ ポインター (受信によって返される) から、それに応じてキャストするために一致するメッセージ サブクラスを認識する方法が見つかりません。

4

1 に答える 1

1

If you want to do things the pure C++ way then you can play around with using the typeid operator from C++ RTTI to inspect the object to see what it is.

A simpler way is to cast to the underlying message type that all CMS Message instances are derived from:

activemq::core::commands::Message

This class offers a method getDataStructureType() methods that returns the type via an assigned ID used in the OpenWire protocol:

    const unsigned char ID_ACTIVEMQBLOBMESSAGE = 29;
    const unsigned char ID_ACTIVEMQBYTESMESSAGE = 24;
    const unsigned char ID_ACTIVEMQMAPMESSAGE = 25;
    const unsigned char ID_ACTIVEMQMESSAGE = 23;
    const unsigned char ID_ACTIVEMQOBJECTMESSAGE = 26;
    const unsigned char ID_ACTIVEMQSTREAMMESSAGE = 27;
    const unsigned char ID_ACTIVEMQTEXTMESSAGE = 28;

Or you can just try a dynamic cast to each type until the result is non-null.

于 2014-03-06T15:56:28.970 に答える