[rabbitmq-discuss] Draft of C++ rabbitMq API
Alexandre Kalendarev
akalend at mail.ru
Thu Mar 4 15:49:16 GMT 2010
the new version of draft:
the Draft of C++ API
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 at localhost:5673/somevhost");
AMQPExchange * exchange = amgp.createExchange();
default connection string is "localhost:5672"
the debug connection string AMQPCnnDebug is "guest:guest at 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 )
Hi Alexandre,
>
> Thanks for this, it's a great start.
>
> Alexandre Kalendarev wrote:
> > 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)
> > }
>
> The only question I have is why these are classes. I would have expected
> "factory" methods such as Declare to live on AMQPConnection itself. (Do
> you intend, by the way, to support multiple channels per connection? I
> can't say I recommend it, but for some scenarios it's probably pretty
> useful.)
>
> I would have expected something more like:
>
> class AMQPConnection {
> ...
> AMQPExchange *ExchangeDeclare( ... );
> AMQPQueue *QueueDeclare( ... );
> ...
> }
>
> class AMQPExchange {
> void Delete();
> void Publish(string routingKey, ...);
>
> string getName();
> // etc
> }
>
> I'm afraid my C++ years are approximately a decade behind me, so please
> don't read my suggestions too literally :-) It'll take me a while to get
> back up to speed with what's considered good modern C++ style...
>
> (Also, could AMQPExchange be a valuetype? It's pretty tiny, it's
> stateless, and it'd be nice to avoid memory-management headaches where
> possible.)
>
> Regards,
> Tony
>
More information about the rabbitmq-discuss
mailing list