новое С++ API

9 views
Skip to first unread message

Alexandre Kalendarev

unread,
Mar 4, 2010, 10:56:28 AM3/4/10
to rabbit...@googlegroups.com
представляю переработанное API
более дружелюбное для пользователя, убран класс  Basic, его методы переместились 
в классы AMQPQueue & AMQPExchange - так более логично

для публикации методов разработана модель events

высказывайте идеи, если есть



Александр



Connection class

class AMQP {
AMQP();
AMQP( string connectionString );
AMQP( string connectionString , int channelNumber);
void Open( string connectionString );
void Open( string connectionString , int channelNumber);
void Close();
setChannel(int channelNumber);

AMQPExchange createQueue( );
AMQPExchange createQueue(int channelNumber );
AMQPExchange createQueue( string  queueName);
AMQPExchange createQueue( const char *  queueName);
AMQPExchange createQueue( string  queueName, int channelNumber);
AMQPExchange createQueue( const char *  queueName, int channelNumber);

AMQPQueue createExchange();
AMQPQueue createExchange(int channelNumber);
AMQPQueue createExchange(string  exchangeName);
AMQPQueue createExchange(const char *  exchangeName);
AMQPQueue createExchange(string  exchangeName, int channelNumber);
AMQPQueue createExchange( const char *  exchangeName, int channelNumber);

}

const AMQPCnnDebug = "localhost:5672"

the example:

AMQP amqp("guest:guest@localhost:5673/somevhost");
AMQPExchange * exchange = amgp.createExchange();  

default connection string is "localhost:5672"
the debug connection string   AMQPCnnDebug  is "guest:guest@localhost:5673" 

AMQP amqp( AMQPCnnDebug );


Exchange class

class AMQPExchange {
AMQPExchange( AMQPConnection * cnn );
void Declare(string name);
void Declare(string name, int parms);
void Declare(string name, int parms, map properties ); // *)?

void Delete(string name)

void Bind ( string queueName );
void Bind ( string queueName , string key);

void Ubind ( string queueName );
void Ubind ( string queueName , string key);

void Publish(  string message);
void Publish(  uchar* message);
void Publish(  string message, const char * key);
void Publish(  uchar* message, const char * key);

}


the parms is set of constants as AMQPDurable, AMQPAutodelete etc
the type of exchange is AMQPDirect default or AMQPFanout, or AMQPTopic 


Example:
AMQP amqp();
AMQPExchange * ex = amqp.createExchange();
ex->Declare("my_exchange");
or:
AMQP amqp();
AMQPExchange * ex = amqp.createExchange("my_exchange"); // if exchange "my_exchange" alredy declared.
ex->Bind("qu1", "spb.news");



Queue class

class AMQPQueue {
AMQPQueue(AMQPConnection * cnn);

void Declare(string name);
void Declare(string name, int parms);
void Declare(string name, int parms, map properties ); // *)?

void Delete(string name)

void Purge (string name)

void Bind ( string exchangeName );
void Bind ( string exchangeName , string key);

void Ubind ( string exchangeName );
void Ubind ( string exchangeName , string key);

void Cancel()


AMQPMessage *  Get()
AMQPMessage *  Get( string queueName)

void Ask( ) 
void Ask( string queueName ) ????

void Reject(  ) ????
void Reject( string queueName )

void addEvents( enum eventName,  IAMQPEvents events );

void Consume( );
void Consume( string queueName , IAMQPEvents * callback );
}


the parms is set of constants as AMQPDurable, AMQPAutodelete etc


example:
AMQP amqp();
AMQPEQueue * qu = amqp.createQueue();
qu->Declare("qu_mylife");




class AMQPMessage  ????
 int timestamp
 int expiration
 string contentType
 string deliveryTag
 uchar* message or string 
 int number // internal number message
 string exchange 
 string key
....

 AMQPEvents is the abstract class, the callbackName is derived from IAMQPEvent.

after received each the message call the method run of derived AMQPCallback base class.


*) properties is map of addional property, it will to resolve in future.

Examples:

// publish message
AMQP amqp();

AMQPExchange * ex = amqp.createExchange();
ex->Declare("my_exchange", AMQPTopic);
ex->Bind("my_exchange", "qu_mylive", "news" );
ex->Publish("my_exchange", "12345" , "news");

// deteting ex will after exit from scope of amqp variable;


// consume message
class printMessage : IAMQPEvents {
void run (uchar* message) {
std::cout << message << std::endl;
}
}
AMQP amqp();

AMQPQueue * queue = amqp.createQueue("qu_mylive");
queue->addEvent(AMQPonMessage, printMessage);
queue->Consume( pm); 



unrealise classes(it will to resolve in future):  AMQPFile, AMQPStreams etc ...

exceptions:

AMQPnoConnectException
AMQPnonAutorizeException
AMQPnotFoundException 
AMQPnotAllowedException 
...
AMQPerrorException (AMQPcommandInvalidException  )


Reply all
Reply to author
Forward
0 new messages