[openamq-dev] Durable Queues

Martin Sustrik sustrik at imatix.com
Wed Aug 22 13:28:51 CEST 2007


Oops, sorry, I've missed you have exclusive flag set (when calling 
queue.declare). Exclusive means that nobody except the creator 
connection has access to the queue and it implies auto-delete of the 
queue when the connection is closed.

Martin

Malinga wrote:
> Hi this is the class (external application) which is used to create the 
> queues for the product. it creates a queue but its not permanent 
> (durable) yet. whats the wrong ?
> 
> 
> 
> 
> 
> 
> #include <stdio.h> /* This handles the basic IO functionality */
>  
> #include "base.h" /*  iMatix base header file,
>                       Defines the standard preprocessing environment for 
> C development.  Also
>                       defines a set of portability macros for 
> functionality that is not part
>                       of the APR layer we are using for most 
> portability. */
>  
> #include "amq_client_connection.h" /* A amq_client_connection object 
> establishes and manages a single
>                       connection to a amq server. The connection can 
> hold many sessions - each is a 
>                       amq_client_session object. To use this API, first 
> create a connection to the server, 
>                       then create one or more sessions and do work on 
> the sessions. Each session represents 
>                       a serial stream of work. In simple applications, a 
> single session is usually sufficient.
>                       In multithreaded applications, each thread will 
> want its own session. */
>  
> #include "amq_client_session.h" /* This class provides the session 
> serialisation API.
>                       Generated from amq_client_session.icl by icl_gen 
> using GSL/4. */
>  
> #include "RMiddleware.h" /* Defines all the middleware related 
> funtionality */
>  
> #include <sys/time.h> /* This will used to get the very usefull time 
> related functions to calcualte the staticstics */
>  
> amq_client_connection_t *connection; // Current connection.
> amq_client_session_t *session; // Current session.
> icl_longstr_t *auth_data; // Autantication data set.
>  
> int create(int argc, char *argv [], char* chost, char* cdestination){     
>  
>     int rc;     
>  
>     if (!connection){
>         icl_system_initialise (argc, argv); /* This should called with 
> the environment variables, 
>                                          which will initialize the 
> system, else it will give 
>                                          us a error and stop furter 
> processing. */
>  
>         /* This will open a connection, need to do some more error 
> handling */     
>         auth_data = amq_client_connection_auth_plain ("guest", "guest");
>         connection = amq_client_connection_new (chost, "/", auth_data, 
> "sender", 0, 30000);
>         icl_longstr_destroy (&auth_data);
>     }else{
>         //icl_console_print ("INFO : Connection Already Initialized");
>     }
>  
>     
> /////////////////////////////////////////////////////////////////////////////////////////// 
> 
>     
> /////////////////////////////////////////////////////////////////////////////////////////// 
> 
>     ////////////////////////////////// EXCEPTION HANDLING 
> /////////////////////////////////////
>     
> /////////////////////////////////////////////////////////////////////////////////////////// 
> 
>     
> /////////////////////////////////////////////////////////////////////////////////////////// 
> 
>     if (!connection) {
>         icl_console_print ("ERROR : Could not open connection to the 
> specified message broker");
>         return 3000;
>     }else{
>         icl_console_print ("INFO : connected to %s/%s - %s - %s",
>         connection->server_product,
>         connection->server_version,
>         connection->server_platform,
>         connection->server_information);
>     }
>     
> /////////////////////////////////////////////////////////////////////////////////////////// 
> 
>     
> /////////////////////////////////////////////////////////////////////////////////////////// 
> 
>     
> /////////////////////////////////////////////////////////////////////////////////////////// 
> 
>     
> /////////////////////////////////////////////////////////////////////////////////////////// 
> 
>     
> /////////////////////////////////////////////////////////////////////////////////////////// 
> 
>      
>     if(!session){
>         session = amq_client_session_new (connection);
>     }else{
>         icl_console_print ("INFO : Session Already Initialized");
>     }
>      
>     
> /////////////////////////////////////////////////////////////////////////////////////////// 
> 
>     
> /////////////////////////////////////////////////////////////////////////////////////////// 
> 
>     ////////////////////////////////// EXCEPTION HANDLING 
> /////////////////////////////////////
>     
> /////////////////////////////////////////////////////////////////////////////////////////// 
> 
>     
> /////////////////////////////////////////////////////////////////////////////////////////// 
> 
>     if (!session) {
>         icl_console_print ("ERROR : could not open session to the 
> specified conection");
>         return 3001; // Shoud not exit like this
>     }else{
>         icl_console_print ("INFO : established a virtual connection ( 
> session ) to this connection");
>     }
>     
> /////////////////////////////////////////////////////////////////////////////////////////// 
> 
>     
> /////////////////////////////////////////////////////////////////////////////////////////// 
> 
>     
> /////////////////////////////////////////////////////////////////////////////////////////// 
> 
>     
> /////////////////////////////////////////////////////////////////////////////////////////// 
> 
>     
> ///////////////////////////////////////////////////////////////////////////////////////////
> 
>     //  Create a private queue
>     amq_client_session_queue_declare (
>             session,                        //  session
>             0,                              //  ticket
>             NULL,                           //  queue name
>             FALSE,                          //  passive
>             TRUE,                          //  durable
>             TRUE,                           //  exclusive
>             FALSE,                           //  auto-delete
>             NULL);                          //  arguments
>  
>         //  Bind the queue to the exchange
>         amq_client_session_queue_bind (
>                 session,                        //  session
>                 0,                              //  ticket
>                 NULL,                           //  queue
>                 "amq.direct",                   //  exchange
>                 cdestination,                  //  routing-key
>                 NULL);                          //  arguments
> 
>         amq_client_session_basic_consume (
>                 session,                        //  session
>                 0,                              //  ticket
>                 NULL,                           //  queue
>                 NULL,                           //  consumer-tag
>                 TRUE,                           //  no-local
>                 TRUE,                           //  no-ack
>                 TRUE,                           //  exclusive
>                 NULL);                          //  arguments
>  
>         return 0;
> }
>  
> void dispose (){
>      // Close the channel
>      amq_client_session_destroy (&session);
>      // icl_console_print ("INFO : Session disposed sucessfully");
>  
>      // Close the connection
>      amq_client_connection_destroy (&connection);
>      //    icl_console_print ("INFO : Connection disposed sucessfully");
>  
>      // Uninitialise system
>      icl_system_terminate ();
>      //icl_console_print ("INFO : System terminated");
> }
>  
> int main(int argc, char* argv[]){
>     int status = create(argc, argv, "localhost:5672", "destination");
>     printf("Status of queue creation : %d\n", status);
>     dispose();
>     return 0;
> }
> 
> ------------------------------------------------------------------------
> Sick sense of humor? Visit Yahoo! TV's Comedy with an Edge 
> <http://us.rd.yahoo.com/evt=47093/*http://tv.yahoo.com/collections/222>to 
> see what's on, when.
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> openamq-dev mailing list
> openamq-dev at lists.openamq.org
> http://lists.openamq.org/mailman/listinfo/openamq-dev



More information about the openamq-dev mailing list