activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nathan Mittler" <nathan.mitt...@gmail.com>
Subject Re: activemq-cpp getStringProperty
Date Sat, 06 Oct 2007 22:02:31 GMT
Ah - I see what's going on.  Looks like you have a slight programming error
in this line:

char *propValue = textMessage->getStringProperty("session_id").c_str();

You're getting a pointer to the internal char* of a temporary string object
... not a good idea :).  Instead, change the code to this and it should work
fine.

string propValue = textMessage->getStringProperty("session_id");

This worked for me.

Regards,
Nate


On 10/5/07, cmaxo <cmaxo@engineer.com> wrote:
>
>
>
> Hmm ... you certainly should be able to set properties on text
> messages.  If
> you wouldn't mind, it would help us a lot if you could provide a sample
> main
> that demonstrates the problem.
>
> Thanks,
> Nate
>
>
>
> Here is a mockup main.  I'm using gcc 4.1.3 on ubuntu feisty.  Like I said
> the messages come across great and the text is complete.  I just get the
> exception everytime I look for the property.
>
> #include <cms/Connection.h>
> #include <cms/MessageConsumer.h>
> #include <activemq/connector/stomp/commands/CommandConstants.h>
>
> int main(int argc, char *argv[])
> {
>   ActiveMQConnectionFactory* factory = NULL;
>   try
>   {
>      // Create a ConnectionFactory
>      ActiveMQConnectionFactory* factory = new
> ActiveMQConnectionFactory("tcp://127.0.0.1:61613?wireFormat=stomp");
>
>      cleanup();
>
>      Connection *connection = factory->createConnection();
>      connection->start();
>
>      Session *session = connection->createSession(fAckMode);
>      Destination *destination  = session->createQueue("myqueue");
>
>      MessageProducer *producer = session->createProducer(destination);
>
>      TextMessage* textMessage = session->createTextMessage("Hello
> message");
>      textMessage->setStringProperty("session_id", "1234");
>
>      producer->send(textMessage);
>
>      /* cleanup code here */
>    }
> }
>
> The consumer code is very similar except for the lines dealing with the
> TextMessage are replaced with:
> TextMessage *textMessage = dynamic_cast<TextMessage*>(mc->receive(1000));
> if (textMessage)
> {
>   try
>   {
>     char *propValue =
> textMessage->getStringProperty("session_id").c_str();
>     printf("%s", propValue);
>   }
>   catch (CMSException &exception)
>   {
>     printf("%s", exception.getMessage().c_str());
>   }
>   char *message = textMessage->getText().c_str();
>   printf("%s", message);
> }
> --
> View this message in context:
> http://www.nabble.com/activemq-cpp-getStringProperty-tf4576622s2354.html#a13065924
> Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message