activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Arshad Ahamad" <ars...@in.effectsoft.com>
Subject Multiple client in ActiveMQ useing openwire-cpp API's
Date Mon, 07 Aug 2006 11:29:44 GMT
Hi all,

 I am working on openwire-cpp ( for ActiveMQ-4.0) code on SuSe(Linux
 machine->i686-suse-linux, version 2.6.13-15.8-default), in C++ .


 I have a separate sender and receiver and I am able to make them
 communicate bi-directionally vi a single queue, and they are working fine.
 But I am unable to do the same for the multiple clients. How I can make
 many senders for a single receiver on one single queue (bi-directional). I
 am sending code for this sender and receiver  Pls help me, my project is
 delaying because of this.


 Thanks in advance........
***************************Receiver.cpp******************************
 p<IMessageConsumer>   consumer ;
 p<IMessageProducer>   producer, producer1 ;
 p<IQueue>             queue, queue1 ; 

 void TestReceiveQueue::execute() throw (exception)
 {
    p<ITextMessage>       message; 

     // Connect to a queue
     queue = session->getQueue("FOO.BAR") ;
     producer = session->createProducer(queue) ;
     consumer = session->createConsumer(queue) ; 

     printf("\nClientID is ->%s\n", (connection->getClientId())->c_str());
     consumer->setMessageListener( smartify(this) ) ; 

     message = session->createTextMessage("saifi");
     producer->send(message) ; 

     //Receive  message
       while(1)
       {
       }
     // Wait for asynchronous message for 1s
     semaphore.wait(1) ; 

     // Check if any error was registered by the message handler
     if( error != NULL )
         throw TraceException( error ) ;
 } 

void TestReceiveQueue::onMessage(p<IMessage> message)
{
    p<ITextMessage>       message2;
    p<IDestination> dest;
    char Replay[1000]= 
{'s','a','i','f','i','1','a','r','a','s','h','a','d'};
    p<string> sReceive;
    if( message == NULL )
    {
        error = "Received a null message" ;
        semaphore.notify() ;
        return ;
    }
    printf("Message ID->%s", message->getJMSMessageID()->c_str()); 

    p<ITextMessage> mess = p_dyncast<ITextMessage> (message);
    if (strcmp((sReceive = mess->getText())->c_str(), "saifi")!=0)
    {
    printf("\nRecieved message ->%s\n", mess->getText()->c_str()); 

    producer = session->createProducer(::queue) ;
    strcat(Replay, mess->getText()->c_str());
    message2 = session->createTextMessage(Replay);
    producer->send(message2) ; 

    }
    if( mess == NULL )
    {
        error = "Received wrong type of message" ;
        semaphore.notify() ;
        return ;
        }
    // Verify message content
if( strcmp((sReceive= mess->getText())->c_str(), "HelloWorld,Arshad")!= 0 )
    {
        error = "Message content has been corrupted" ;
    }
    semaphore.notify() ;
}
**************************End Receiver******************************* 

**************************sender.cpp**********************************
 void TestSendQueue::execute() throw (exception)
 {
     p<IQueue>             queue, queue1 ;
     p<IMessageConsumer>   consumer, consumer1 ;
     p<IMessageProducer>   producer ;
     p<ITextMessage>       message; 

     // Connect to a queue
     queue = session->getQueue("FOO.BAR") ; 

     // Create producer
     producer = session->createProducer(queue) ;
     producer->setPersistent(true) ; 

     //////////  For Listening
     //queue1 = session->getQueue("FOO.BAR1") ;
     consumer = session->createConsumer(queue);
     printf("\nClientID is ->%s\n", (connection->getClientId())->c_str());
     consumer->setMessageListener( smartify(this) ) ;
     //////////
     while(1)
     {
       //char MsgStr[50];
       printf("\n\nEnter message : ");
       fflush(stdin);
       cin.getline(MsgStr, 500);
       message = session->createTextMessage( MsgStr );
       if (strcmp(MsgStr, "END")!=0)
       {
        producer->send(message);
        sleep(1);
       }
       else
       {
        printf("\nTerminaing....\n");
        sleep(1);
        break;
       }
     } 

     // Wait for asynchronous message for 1s
    semaphore.wait(1) ; 

    // Check if any error was registered by the message handler
    if( error != NULL )
        throw TraceException( error ) ;
} 

 void TestSendQueue::onMessage(p<IMessage> message)
 {
   printf("Message ID->%s", message->getJMSMessageID()->c_str());
   printf("\nRecever is Online\n");
   p<string> sReceive;
   if( message == NULL )
   {
     error = "Received a null message" ;
     semaphore.notify() ;
     return ;
   }
     p<ITextMessage> mess = p_dyncast<ITextMessage> (message);
     if (strcmp((sReceive = mess->getText())->c_str(), "saifi")!=0)
       printf("\nResponce Message ->%s\n", mess->getText()->c_str());
     if( mess == NULL )
     {
       error = "Received wrong type of message" ;
       semaphore.notify() ;
       return ; 

     }
     if( strcmp((sReceive= mess->getText())->c_str(), "Hello World, Arshad") 
!= 0 )
     {
       error = "Message content has been corrupted" ;
     }
     semaphore.notify() ;
 }
**************************End Sender**********************************
 

 


 Thanks & Regards
 Arashad Ahamad

Mime
View raw message