RABBITMQ Channel parameter detailed

Source: Internet
Author: User
Tags ack rabbitmq
1. Channel 

1.1 channel.exchangedeclare ():
Type: There are direct, fanout, topic three
Durable:true, false true: Server restart will remain exchange. Warning: This option is set only and does not persist on behalf of messages. That is, there is no guarantee that the message will still be restarted. Original: True if we are declaring a durable exchange (the exchange would survive a server restart)
autodelete:true, False.true : Whether the server can delete the exchange when there is no consumer. Original 1:true If the server should delete the exchange when it was no longer in use.
/**
     * Declare an Exchange.
     * @see com.rabbitmq.client.AMQP.Exchange.Declare
     * @see com.rabbitmq.client.AMQP.Exchange.DeclareOk
     * @ Param exchange The name of the Exchange
     * @param type the exchange type
     * @param durable true if we are declaring A durable exchange (the exchange would survive a server restart)
     * @param autodelete True if the server should delete T He exchange when it was no longer in use
     * @param arguments other properties (construction arguments) for the exchange< c8/>* @return A declaration-confirm method to indicate the exchange is successfully declared
     * @throws java.io.IOExce Ption If an error is encountered
     *
    /Exchange.declareok Exchangedeclare (String Exchange, String type, Boolean du Rable, Boolean autodelete,
                                       map<string, object> arguments) throws IOException;
1.2 Chanel.basicqos ()
prefetchsize:0 
Prefetchcount: will tell RABBITMQ not to give a consumer to push more than n messages at the same time, that is, once there is no ACK of n messages, then the consumer will block off until there is a message ack
Global:true\false whether the above setting is applied to the channel, simply, is the above limit the channel level or the consumer level
Note: It is said that Prefetchsize and global these two, RABBITMQ did not achieve, for the moment do not study
    /**
     * Request specific "Quality of service" settings.
     *
     * These settings impose limits on the amount of data the server
     * would deliver to consumers before requiring ACK Nowledgements.
     * Thus They provide a means of consumer-initiated flow control.
     * @see Com.rabbitmq.client.AMQP.Basic.Qos
     * @param prefetchsize maximum amount of content (measured in
     * octets) t Hat the server would deliver, 0 if unlimited
     * @param prefetchcount Maximum number of messages that the server
     * W Ill deliver, 0 if unlimited
     * @param global True if the settings should is applied to the
     * Entire channel Rathe R than each consumer
     * @throws java.io.IOException If a error is encountered
     *
    /void Basicqos (int prefetch Size, int prefetchcount, Boolean global) throws IOException;
1.3 Channel.basicpublish ()
Routingkey: Route key, #匹配0个或多个单词, * match a word in topic Exchange to do message forwarding

Mandatory:true: If Exchange cannot find a qualifying queue based on its type and message Routekey, the Basic.return method is called to return the message to the producer. False: This occurs when broker throws a message directly
Immediate:true: If Exchange finds that there are no consumers on the corresponding queue when it route the message to queue (s), the message is not placed in the queue. When all the queues (one or more) associated with the message Routekey do not have a consumer, the message is returned to the producer through the Basic.return method.
basicproperties: Note that basicproperties.deliverymode,0: no persistence 1: persistence refers to the persistence of messages, with channel (durable=true), queue ( Durable) can be implemented, even if the server is down, the message remains
simple: the mandatory flag tells the server to at least route the message to a queue, or return the message to the producer The immediate flag tells the server that if there is a consumer on the queue associated with the message, the message is immediately delivered to it, and if all the queues have no consumers, return the message directly to the producer without waiting for the message to be queued to the consumer.
  /** * Publish a message. * * Publishing to a non-existent exchange would result in a channel-level * protocol exception, which closes the
     Channel. * * Invocations of <code>Channel#basicPublish</code> would eventually block if a * <a href= "http:/
     /www.rabbitmq.com/alarms.html ">resource-driven alarm</a> is in effect. * * @see Com.rabbitmq.client.AMQP.Basic.Publish * @see <a href= "http://www.rabbitmq.com/alarms.html" >resou
     Rce-driven Alarms</a>. * @param exchange the Exchange to publish the message to * @param routingkey the routing key * @param mandatory True if the ' mandatory ' flag is-to-be set * @param immediate true if the ' immediate ' flag was to be * set.
     Note that the RabbitMQ server does is not a support for this flag. * @param props other properties for the message-routing headers etc * @param body the message body * @throws J Ava.io.IOException If an error is EncountEred */void Basicpublish (String Exchange, String Routingkey, Boolean mandatory, Boolean immediate, Basicproperti Es props, byte[] body) throws IOException;

1.4 channel.basicack ();

Deliverytag: The message's index
multiple: Batch. True: All messages smaller than Deliverytag will be ack once.

    /**
     * Acknowledge one or several received
     * messages. Supply the Deliverytag from the {@link com.rabbitmq.client.AMQP.Basic.GetOk}
     * or {@link Com.rabbitmq.client.AMQP.Basic.Deliver} Method
     * containing the received message being acknowledged.
     * @see com.rabbitmq.client.AMQP.Basic.Ack
     * @param deliverytag the tag from the received {@link COM.RABBITMQ.CLIENT.A MQP. Basic.getok} or {@link com.rabbitmq.client.AMQP.Basic.Deliver}
     * @param multiple true to acknowledge all messages up T O and
     * including the supplied delivery tag, false to acknowledge just
     * the supplied delivery tag.
     * @throws Java.io.IOException If an error is encountered
     *
    /void Basicack (Long Deliverytag, boolean multiple) th Rows IOException;

1.5 Channel.basicnack (Delivery.getenvelope (). Getdeliverytag (), false, true);

Deliverytag: The message's index
multiple: Batch. True: All messages smaller than Deliverytag will be rejected at once.
Requeue: Rejected whether to re-enter the queue

/** * Reject One or several received messages. * * Supply the <code>deliveryTag</code> from the {@link com.rabbitmq.client.AMQP.Basic.GetOk} * or {
     @link Com.rabbitmq.client.AMQP.Basic.GetOk} method containing the message to be rejected. * @see Com.rabbitmq.client.AMQP.Basic.Nack * @param deliverytag the tag from the received {@link com.rabbitmq.client. Amqp. Basic.getok} or {@link com.rabbitmq.client.AMQP.Basic.Deliver} * @param multiple True to reject all messages D including * the supplied delivery tag;
     False to reject just the supplied * delivery tag. * @param requeue True if the rejected message (s) should be requeued rather * than discarded/dead-lettered * @thr OWS Java.io.IOException If an error is encountered */void Basicnack (Long Deliverytag, Boolean multiple, Boolean Requeue) throws IOException; 

1.5 Channel.basicreject (Delivery.getenvelope (). Getdeliverytag (), false);

Deliverytag: The message's index
Requeue: rejected whether to re-enter the queue

channel.basicnack with Channel.basicreject The difference is that Basicnack can reject multiple messages, and Basicreject can only reject one message

at a time
/**
     * Reject a message. Supply the Deliverytag from the {@link com.rabbitmq.client.AMQP.Basic.GetOk}
     * or {@link Com.rabbitmq.client.AMQP.Basic.Deliver} Method
     * containing the received message being rejected.
     * @see com.rabbitmq.client.AMQP.Basic.Reject
     * @param deliverytag the tag from the received {@link Com.rabbitmq.clien T.amqp.  Basic.getok} or {@link com.rabbitmq.client.AMQP.Basic.Deliver}
     * @param requeue True if the rejected message should be Requeued rather than discarded/dead-lettered
     * @throws java.io.IOException If an error is encountered
     */
    Voi D basicreject (Long Deliverytag, Boolean requeue) throws IOException;
1.6 Channel.basicconsume (Queue_name, true, consumer);
Autoack: Whether automatic ack, if not auto ack, need to use Channel.ack, Channel.nack, channel.basicreject for message reply
/** * Start a non-nolocal, non-exclusive consumer, with * a server-generated
     Consumertag.  * @param queue The name of the the queue * @param autoack True if the server should consider messages * acknowledged Once delivered; False if the server should expect * Explicit acknowledgements * @param callback an interface to the consumer obj ECT * @return The Consumertag generated by the server * 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.