RecordedConsumer.java 2.5 KB
Newer Older
L
liujun 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
// Copyright (c) 2007-2020 VMware, Inc. or its affiliates.  All rights reserved.
//
// This software, the RabbitMQ Java client library, is triple-licensed under the
// Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
// ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
// LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2.  For the ASL,
// please see LICENSE-APACHE2.
//
// This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
// either express or implied. See the LICENSE file for specific language governing
// rights and limitations of this software.
//
// If you have any questions regarding licensing, please contact us at
// info@rabbitmq.com.

package com.rabbitmq.client.impl.recovery;

import com.rabbitmq.client.Consumer;

import java.io.IOException;
import java.util.Map;

/**
 * @since 3.3.0
 */
public class RecordedConsumer extends RecordedEntity {
    private String queue;
    private String consumerTag;
    private Consumer consumer;
    private boolean exclusive;
    private boolean autoAck;
    private Map<String, Object> arguments;

    public RecordedConsumer(AutorecoveringChannel channel, String queue) {
        super(channel);
        this.queue = queue;
    }

    public RecordedConsumer consumerTag(String value) {
        this.consumerTag = value;
        return this;
    }

    public RecordedConsumer consumer(Consumer value) {
        this.consumer = value;
        return this;
    }

    public RecordedConsumer exclusive(boolean value) {
        this.exclusive = value;
        return this;
    }

    public RecordedConsumer autoAck(boolean value) {
        this.autoAck = value;
        return this;
    }

    public String recover() throws IOException {
        this.consumerTag = this.channel.getDelegate().basicConsume(this.queue, this.autoAck, this.consumerTag, false, this.exclusive, this.arguments, this.consumer);
        return this.consumerTag;
    }

    public RecordedConsumer arguments(Map<String, Object> value) {
        this.arguments = value;
        return this;
    }

    public String getQueue() {
        return queue;
    }

    public void setQueue(String queue) {
        this.queue = queue;
    }

    public String getConsumerTag() {
        return consumerTag;
    }
    
    @Override
    public String toString() {
        return "RecordedConsumer[tag=" + consumerTag + ", queue=" + queue + ", autoAck=" + autoAck + ", exclusive=" + exclusive + ", arguments=" + arguments + ", consumer=" + consumer + ", channel=" + channel + "]";
    }
}