You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by solanki <so...@gps.caltech.edu> on 2010/06/30 01:40:31 UTC

ActiveMQ-CPP Durable Subscriber Not Working.

I have searched through all posts related to the subject. Yet I failed to
find any help. 
Here is the consumer code, and its not able to receive messages as a durable
subscriber. (It does receive messages  when its connected to the Broker but
not the onces that are sent when its not connected). 
I have seen people ask this exact question few times in the forum but NONE
of them received any response regarding ActiveMQ-CPP durable subscriber not
working. Anyone would like to be the first  ?

many thanks



    auto_ptr<cms::ConnectionFactory> connectionFactory(
	  cms::ConnectionFactory::createCMSConnectionFactory( brokerURI ) );
    
    // Create a Connection
    connection = connectionFactory->createConnection();
    connection->start();

    // Create a Session
    session = connection->createSession( cms::Session::AUTO_ACKNOWLEDGE);

      cms::Topic* topic = session->createTopic("test.foo");
      
      // Create a MessageConsumer from the Session to the Topic or Queue
      cms::MessageConsumer *consumer =
session->createDurableConsumer(topic,"mytest","",false);

	cms::Message* cmsmsg = consumer->receive();

//////////////



-- 
View this message in context: http://old.nabble.com/ActiveMQ-CPP-Durable-Subscriber-Not-Working.-tp29029516p29029516.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: ActiveMQ-CPP Durable Subscriber Not Working.

Posted by Timothy Bish <ta...@gmail.com>.
On Tue, 2010-06-29 at 16:40 -0700, solanki wrote:
> I have searched through all posts related to the subject. Yet I failed to
> find any help. 
> Here is the consumer code, and its not able to receive messages as a durable
> subscriber. (It does receive messages  when its connected to the Broker but
> not the onces that are sent when its not connected). 
> I have seen people ask this exact question few times in the forum but NONE
> of them received any response regarding ActiveMQ-CPP durable subscriber not
> working. Anyone would like to be the first  ?
> 
> many thanks
> 
> 
> 
>     auto_ptr<cms::ConnectionFactory> connectionFactory(
> 	  cms::ConnectionFactory::createCMSConnectionFactory( brokerURI ) );
>     
>     // Create a Connection
>     connection = connectionFactory->createConnection();
>     connection->start();
> 
>     // Create a Session
>     session = connection->createSession( cms::Session::AUTO_ACKNOWLEDGE);
> 
>       cms::Topic* topic = session->createTopic("test.foo");
>       
>       // Create a MessageConsumer from the Session to the Topic or Queue
>       cms::MessageConsumer *consumer =
> session->createDurableConsumer(topic,"mytest","",false);
> 
> 	cms::Message* cmsmsg = consumer->receive();
> 
> //////////////
> 
> 
> 

Given the code I'd say the problem lies in the fact that you haven't set
a client ID on the Connection.  

Depending on what version of the CPP client you are using you can set
the client ID either from the createConnection method:

cms::Connection* createConnection( const std::string& username,
                                   const std::string& password,
                                   const std::string& clientId );

if you had no username or password the call would look like

factory->createConnection( "", "", "MyUniqueClientId" );

Each time the client connects it must use that same client ID.

Or you can set the client Id on the URI as follows:

tcp://127.0.0.1:61616?client-id="MyUniqueClientId"

And just to make things even easier he newest ActiveMQ-CPP release
v3.2.0 also added method in the factory to set these values, so you can
now do it this way as well.

Connection* con = factory->createConnection();

con-setClientId("MyUniqueClientId");

Read this for some more info on how Durable Topics work.
http://activemq.apache.org/how-do-durable-queues-and-topics-work.html

If you still have issues you are welcome to open a new Jira issue and
attach a small but complete sample app that demonstrates the problem
along with info on you OS / Compiler / Architecture / Broker Version.

>From Session::createDurableConsumer:

Regards

-- 
Tim Bish

Open Source Integration: http://fusesource.com
ActiveMQ in Action: http://www.manning.com/snyder/

Follow me on Twitter: http://twitter.com/tabish121
My Blog: http://timbish.blogspot.com/