rabbitmq 学习-10-channel 说明

rabbitmq java api 关于消息处理的一个重要的类是channel

channel主要进行相关定义,发送消息,获取消息,事务处理等。

channel可以在多线程中使用,但是在任何时候保证只有一个线程执行命令是很重要的,这在前面rabbitmq学习-6-rabbitmq基础已经说的很清楚了。

publicinterfaceChannelextendsShutdownNotifier{

//重新得到channelnumber

intgetChannelNumber();

//得到当前channel的connection

ConnectiongetConnection();

//关闭channel,closeCode=com.rabbitmq.client.AMQP#REPLY_SUCCESS,closeMessage='OK'

voidclose()throwsIOException;

//指定code和message关闭channel

voidclose(intcloseCode,StringcloseMessage)throwsIOException;

//中止channel,closeCode=com.rabbitmq.client.AMQP#REPLY_SUCCESS,closeMessage='OK'

//此操作中的所有异常将被丢弃

voidabort()throwsIOException;

//指定code和message中止channel

//此操作中的所有异常将被丢弃

voidabort(intcloseCode,StringcloseMessage)throwsIOException;

//得到当前channel的ReturnListener

ReturnListenergetReturnListener();

//设置当前channel的ReturnListener

voidsetReturnListener(ReturnListenerlistener);

/**

*Requestspecific"qualityofservice"settings.

*

*Thesesettingsimposelimitsontheamountofdatatheserver

*willdelivertoconsumersbeforerequiringthereceiptof

*acknowledgements.

*Thustheyprovideameansofconsumer-initiatedflowcontrol.

*@seecom.rabbitmq.client.AMQP.Basic.Qos

*@paramprefetchSizemaximumamountofcontent(measuredin

*octets)thattheserverwilldeliver,0ifunlimited

*@paramprefetchCountmaximumnumberofmessagesthattheserver

*willdeliver,0ifunlimited

*@paramglobaltrueifthesettingsshouldbeappliedtothe

*entireconnectionratherthanjustthecurrentchannel

*@throwsjava.io.IOExceptionifanerrorisencountered

*/

voidbasicQos(intprefetchSize,intprefetchCount,booleanglobal)throwsIOException;

/**

*RequestaspecificprefetchCount"qualityofservice"settings

*forthischannel.

*

*@see#basicQos(int,int,boolean)

*@paramprefetchCountmaximumnumberofmessagesthattheserver

*willdeliver,0ifunlimited

*@throwsjava.io.IOExceptionifanerrorisencountered

*/

voidbasicQos(intprefetchCount)throwsIOException;

//发送消息,"mandatory"and"immediate"都是false

voidbasicPublish(Stringexchange,StringroutingKey,BasicPropertiesprops,byte[]body)throwsIOException;

/**

*发送消息

*@paramexchange名称

*@paramroutingKey名称

*@parammandatory是否强制发送

*@paramimmediate是否立即发送

*@parampropsotherpropertiesforthemessage-routingheadersetc

*@parambody消息

*@throwsjava.io.IOExceptionifanerrorisencountered

*/

voidbasicPublish(Stringexchange,StringroutingKey,booleanmandatory,booleanimmediate,BasicPropertiesprops,byte[]body)

throwsIOException;

/**

*删除exchange,不管是否在使用

*@paramexchange名称

*@returnadeletion-confirmmethodtoindicatetheexchangewassuccessfullydeleted

*@throwsjava.io.IOExceptionifanerrorisencountered

*/

Exchange.DeleteOkexchangeDelete(Stringexchange)throwsIOException;

/**

*删除exchange

*@paramexchange名称

*@paramifUnused设置是否只删除没有使用的

*@returnadeletion-confirmmethodtoindicatetheexchangewassuccessfullydeleted

*@throwsjava.io.IOExceptionifanerrorisencountered

*/

Exchange.DeleteOkexchangeDelete(Stringexchange,booleanifUnused)throwsIOException;

/**

*定义exchange,non-autodelete,non-durable

*@paramexchange名称

*@paramexchange类型

*@returnadeletion-confirmmethodtoindicatetheexchangewassuccessfullydeleted

*@throwsjava.io.IOExceptionifanerrorisencountered

*/

Exchange.DeclareOkexchangeDeclare(Stringexchange,Stringtype)throwsIOException;

/**

*定义exchange,non-autodelete

*@paramexchange名称

*@paramexchange类型

*@paramdurable是否持续存在(持续存在,即使server重启也会存在)

*@throwsjava.io.IOExceptionifanerrorisencountered

*@returnadeclaration-confirmmethodtoindicatetheexchangewassuccessfullydeclared

*/

Exchange.DeclareOkexchangeDeclare(Stringexchange,Stringtype,booleandurable)throwsIOException;

/**

*定义exchange

*@paramexchange名称

*@paramexchange类型

*@parampassivetrueifwearepassivelydeclaringaexchange(assertingtheexchangealreadyexists)

*@paramdurable是否持续存在(持续存在,即使server重启也会存在)

*@paramautoDelete是否自动删除,自动删除-server会在它不在使用的时候将其删除

*@paramargumentsotherproperties(constructionarguments)fortheexchange

*@returnadeclaration-confirmmethodtoindicatetheexchangewassuccessfullydeclared

*@throwsjava.io.IOExceptionifanerrorisencountered

*/

Exchange.DeclareOkexchangeDeclare(Stringexchange,Stringtype,booleanpassive,booleandurable,booleanautoDelete,

Map<String,Object>arguments)throwsIOException;

/**

*定义一个queue,由server去命名,exclusive,autodelete,non-durable

*@returnadeclaration-confirmmethodtoindicatetheexchangewassuccessfullydeclared

*@throwsjava.io.IOExceptionifanerrorisencountered

*/

Queue.DeclareOkqueueDeclare()throwsIOException;

/**

*定义一个queue,non-exclusive,non-autodelete,non-durable

*@paramqueue名称

*@returnadeclaration-confirmmethodtoindicatethequeuewassuccessfullydeclared

*@throwsjava.io.IOExceptionifanerrorisencountered

*/

Queue.DeclareOkqueueDeclare(Stringqueue)throwsIOException;

/**

*定义一个queue,non-exclusive,non-autodelete

*@paramqueue名称

*@paramdurable是否持续存在(true:server重启也会存在)

*@returnadeclaration-confirmmethodtoindicatetheexchangewassuccessfullydeclared

*@throwsjava.io.IOExceptionifanerrorisencountered

*/

Queue.DeclareOkqueueDeclare(Stringqueue,booleandurable)throwsIOException;

/**

*定义一个queue

*@paramqueue名称

*@parampassivetrueifwearepassivelydeclaringaqueue(assertingthequeuealreadyexists)

*@paramdurable是否持续存在

*@paramexclusivetrueifwearedeclaringanexclusivequeue

*@paramautoDelete是否自动删除,true:不在使用了server将会自动删除它

*@paramargumentsotherproperties(constructionarguments)forthequeue

*@returnadeclaration-confirmmethodtoindicatethequeuewassuccessfullydeclared

*@throwsjava.io.IOExceptionifanerrorisencountered

*/

Queue.DeclareOkqueueDeclare(Stringqueue,booleanpassive,booleandurable,booleanexclusive,booleanautoDelete,

Map<String,Object>arguments)throwsIOException;

/**

*删除queue,不管它是否在使用

*@paramqueue名称

*@returnadeletion-confirmmethodtoindicatethequeuewassuccessfullydeleted

*@throwsjava.io.IOExceptionifanerrorisencountered

*/

Queue.DeleteOkqueueDelete(Stringqueue)throwsIOException;

/**

*删除queue

*@paramqueue名称

*@paramifUnused是否只删除没有被使用的queue

*@paramifEmpty是否只删除消息是空的queue

*@returnadeletion-confirmmethodtoindicatethequeuewassuccessfullydeleted

*@throwsjava.io.IOExceptionifanerrorisencountered

*/

Queue.DeleteOkqueueDelete(Stringqueue,booleanifUnused,booleanifEmpty)throwsIOException;

/**

*使用routingKey将queue绑定到exchange上

*@paramqueue名称

*@paramexchangethenameoftheexchange

*@paramroutingKeytheroutinekeytouseforthebinding

*@returnabinding-confirmmethodifthebindingwassuccessfullycreated

*@throwsjava.io.IOExceptionifanerrorisencountered

*/

Queue.BindOkqueueBind(Stringqueue,Stringexchange,StringroutingKey)throwsIOException;

/**

*使用routingKey将queue绑定到exchange上,带参数

*@paramqueuethenameofthequeue

*@paramexchangethenameoftheexchange

*@paramroutingKeytheroutinekeytouseforthebinding

*@paramargumentsotherproperties(bindingparameters)

*@returnabinding-confirmmethodifthebindingwassuccessfullycreated

*@throwsjava.io.IOExceptionifanerrorisencountered

*/

Queue.BindOkqueueBind(Stringqueue,Stringexchange,StringroutingKey,Map<String,Object>arguments)throwsIOException;

/**

*解除绑定

*@paramqueuethenameofthequeue

*@paramexchangethenameoftheexchange

*@paramroutingKeytheroutinekeytouseforthebinding

*@returnanunbinding-confirmmethodifthebindingwassuccessfullydeleted

*@throwsjava.io.IOExceptionifanerrorisencountered

*/

Queue.UnbindOkqueueUnbind(Stringqueue,Stringexchange,StringroutingKey)throwsIOException;

/**

*解除绑定,带参数

*@paramqueuethenameofthequeue

*@paramexchangethenameoftheexchange

*@paramroutingKeytheroutinekeytouseforthebinding

*@paramargumentsotherproperties(bindingparameters)

*@returnanunbinding-confirmmethodifthebindingwassuccessfullydeleted

*@throwsjava.io.IOExceptionifanerrorisencountered

*/

Queue.UnbindOkqueueUnbind(Stringqueue,Stringexchange,StringroutingKey,Map<String,Object>arguments)throwsIOException;

/**

*Purgesthecontentsofthegivenqueueandawaitsacompletion.

*@seecom.rabbitmq.client.AMQP.Queue.Purge

*@seecom.rabbitmq.client.AMQP.Queue.PurgeOk

*@paramqueuethenameofthequeue

*@returnapurge-confirmmethodifthepurgewasexecutedsuccesfully

*@throwsjava.io.IOExceptionifanerrorisencountered

*/

Queue.PurgeOkqueuePurge(Stringqueue)throwsIOException;

/**

*Purgesthecontentsofthegivenqueue.

*@seecom.rabbitmq.client.AMQP.Queue.Purge

*@seecom.rabbitmq.client.AMQP.Queue.PurgeOk

*@paramqueuethenameofthequeue

*@paramnowaitwhethertoawaitcompletionofthepurge

*@returnapurge-confirmmethodifthepurgewasexecutedsuccesfully

*@throwsjava.io.IOExceptionifanerrorisencountered

*/

Queue.PurgeOkqueuePurge(Stringqueue,booleannowait)throwsIOException;

/**

*从queue上取消息

*@paramqueuethenameofthequeue

*@paramnoAcktrueifnohandshakeisrequired

*@returna{@linkGetResponse}containingtheretrievedmessagedata

*@throwsjava.io.IOExceptionifanerrorisencountered

*/

GetResponsebasicGet(Stringqueue,booleannoAck)throwsIOException;

/**

*Acknowledgeoneorseveralreceived

*messages.SupplythedeliveryTagfromthe{@linkcom.rabbitmq.client.AMQP.Basic.GetOk}

*or{@linkcom.rabbitmq.client.AMQP.Basic.Deliver}method

*containingthereceivedmessagebeingacknowledged.

*@seecom.rabbitmq.client.AMQP.Basic.Ack

*@paramdeliveryTagthetagfromthereceived{@linkcom.rabbitmq.client.AMQP.Basic.GetOk}or{@linkcom.rabbitmq.client.AMQP.Basic.Deliver}

*@parammultipletrueifweareacknowledgingmultiplemessageswiththesamedeliverytag

*@throwsjava.io.IOExceptionifanerrorisencountered

*/

voidbasicAck(longdeliveryTag,booleanmultiple)throwsIOException;

/**

*Startanon-nolocal,non-exclusiveconsumer,with

*explicitacknowledgementsrequiredandaserver-generatedconsumerTag.

*@paramqueuethenameofthequeue

*@paramcallbackaninterfacetotheconsumerobject

*@returntheconsumerTaggeneratedbytheserver

*@throwsjava.io.IOExceptionifanerrorisencountered

*@seecom.rabbitmq.client.AMQP.Basic.Consume

*@seecom.rabbitmq.client.AMQP.Basic.ConsumeOk

*@see#basicAck

*@see#basicConsume(String,boolean,String,boolean,boolean,Consumer)

*/

StringbasicConsume(Stringqueue,Consumercallback)throwsIOException;

/**

*Startanon-nolocal,non-exclusiveconsumer,with

*aserver-generatedconsumerTag.

*@paramqueuethenameofthequeue

*@paramnoAcktrueifnohandshakeisrequired

*@paramcallbackaninterfacetotheconsumerobject

*@returntheconsumerTaggeneratedbytheserver

*@throwsjava.io.IOExceptionifanerrorisencountered

*@seecom.rabbitmq.client.AMQP.Basic.Consume

*@seecom.rabbitmq.client.AMQP.Basic.ConsumeOk

*@see#basicConsume(String,boolean,String,boolean,boolean,Consumer)

*/

StringbasicConsume(Stringqueue,booleannoAck,Consumercallback)throwsIOException;

/**

*Startanon-nolocal,non-exclusiveconsumer.

*@paramqueuethenameofthequeue

*@paramnoAcktrueifnohandshakeisrequired

*@paramconsumerTagaclient-generatedconsumertagtoestablishcontext

*@paramcallbackaninterfacetotheconsumerobject

*@returntheconsumerTagassociatedwiththenewconsumer

*@throwsjava.io.IOExceptionifanerrorisencountered

*@seecom.rabbitmq.client.AMQP.Basic.Consume

*@seecom.rabbitmq.client.AMQP.Basic.ConsumeOk

*@see#basicConsume(String,boolean,String,boolean,boolean,Consumer)

*/

StringbasicConsume(Stringqueue,booleannoAck,StringconsumerTag,Consumercallback)throwsIOException;

/**

*Startaconsumer.Callstheconsumer's{@linkConsumer#handleConsumeOk}

*methodbeforereturning.

*@paramqueuethenameofthequeue

*@paramnoAcktrueifnohandshakeisrequired

*@paramconsumerTagaclient-generatedconsumertagtoestablishcontext

*@paramnoLocalflagsettotrueunlessserverlocalbufferingisrequired

*@paramexclusivetrueifthisisanexclusiveconsumer

*@paramcallbackaninterfacetotheconsumerobject

*@returntheconsumerTagassociatedwiththenewconsumer

*@throwsjava.io.IOExceptionifanerrorisencountered

*@seecom.rabbitmq.client.AMQP.Basic.Consume

*@seecom.rabbitmq.client.AMQP.Basic.ConsumeOk

*/

StringbasicConsume(Stringqueue,booleannoAck,StringconsumerTag,booleannoLocal,booleanexclusive,Consumercallback)throwsIOException;

/**

*Cancelaconsumer.Callstheconsumer's{@linkConsumer#handleCancelOk}

*methodbeforereturning.

*@paramconsumerTagaclient-orserver-generatedconsumertagtoestablishcontext

*@throwsjava.io.IOExceptionifanerrorisencountered

*@seecom.rabbitmq.client.AMQP.Basic.Cancel

*@seecom.rabbitmq.client.AMQP.Basic.CancelOk

*/

voidbasicCancel(StringconsumerTag)throwsIOException;

/**

*Askthebrokertoresendunacknowledgedmessages.In0-8

*basic.recoverisasynchronous;in0-9-1itissynchronous,and

*thenew,deprecatedmethodbasic.recover_asyncisasynchronous.

*ToavoidthisAPIchanging,thisisnamedforthelatter,and

*willbedeprecated.

*@paramrequeueIftrue,messageswillberequeuedandpossibly

*deliveredtoadifferentconsumer.Iffalse,messageswillbe

*redeliveredtothesameconsumer.

*/

voidbasicRecoverAsync(booleanrequeue)throwsIOException;

/**

*启用事务模式

*@returnatransaction-selectionmethodtoindicatethetransactionwassuccessfullyinitiated

*@throwsjava.io.IOExceptionifanerrorisencountered

*/

Tx.SelectOktxSelect()throwsIOException;

/**

*提交事务

*@returnatransaction-commitmethodtoindicatethetransactionwassuccessfullycommitted

*@throwsjava.io.IOExceptionifanerrorisencountered

*/

Tx.CommitOktxCommit()throwsIOException;

/**

*回流事务

*@returnatransaction-rollbackmethodtoindicatethetransactionwassuccessfullyrolledback

*@throwsjava.io.IOExceptionifanerrorisencountered

*/

Tx.RollbackOktxRollback()throwsIOException;

}

相关推荐