1 /* 2 * hunt-amqp-client: AMQP Client Library for D Programming Language. Support for RabbitMQ and other AMQP Server. 3 * 4 * Copyright (C) 2018-2019 HuntLabs 5 * 6 * Website: https://www.huntlabs.net 7 * 8 * Licensed under the Apache-2.0 License. 9 * 10 */ 11 module hunt.amqp.client.AmqpReceiverOptions; 12 13 //import hunt.codegen.annotations.DataObject; 14 //import hunt.core.json.JsonObject; 15 16 import hunt.collection.ArrayList; 17 import hunt.collection.List; 18 import hunt.Object; 19 20 /** 21 * Configures the AMQP Receiver. 22 */ 23 //@DataObject(generateConverter = true) 24 class AmqpReceiverOptions { 25 26 private string linkName; 27 private bool dynamic; 28 private string qos; 29 private List!string capabilities ;// = new ArrayList<>(); 30 private bool durable; 31 private int maxBufferedMessages; 32 private bool autoAcknowledgement ;// = true; 33 34 this() { 35 capabilities = new ArrayList!string; 36 autoAcknowledgement = true; 37 } 38 39 this(AmqpReceiverOptions other) { 40 this(); 41 setDynamic(other.isDynamic()); 42 setLinkName(other.getLinkName()); 43 setCapabilities(other.getCapabilities()); 44 setDurable(other.isDurable()); 45 setMaxBufferedMessages(other.maxBufferedMessages); 46 } 47 48 //public AmqpReceiverOptions(JsonObject json) { 49 // super(); 50 // AmqpReceiverOptionsConverter.fromJson(json, this); 51 //} 52 // 53 //public JsonObject toJson() { 54 // JsonObject json = new JsonObject(); 55 // AmqpReceiverOptionsConverter.toJson(this, json); 56 // return json; 57 //} 58 59 public string getLinkName() { 60 return linkName; 61 } 62 63 public AmqpReceiverOptions setLinkName(string linkName) { 64 this.linkName = linkName; 65 return this; 66 } 67 68 /** 69 * @return whether the receiver is using a dynamic address. 70 */ 71 public bool isDynamic() { 72 return dynamic; 73 } 74 75 /** 76 * Sets whether the link remote terminus to be used should indicate it is 77 * 'dynamic', requesting the peer names it with a dynamic address. 78 * <p> 79 * The address provided by the peer can then be inspected using the 80 * {@link AmqpReceiver#address()} method on the {@link AmqpReceiver} received once opened. 81 * 82 * @param dynamic true if the link should request a dynamic terminus address 83 * @return the options 84 */ 85 public AmqpReceiverOptions setDynamic(bool dynamic) { 86 this.dynamic = dynamic; 87 return this; 88 } 89 90 /** 91 * Gets the local QOS config, values can be {@code null}, {@code AT_MOST_ONCE} or {@code AT_LEAST_ONCE}. 92 * 93 * @return the local QOS config. 94 */ 95 public string getQos() { 96 return qos; 97 } 98 99 /** 100 * Sets the local QOS config. 101 * 102 * @param qos the local QOS config. Accepted values are: {@code null}, {@code AT_MOST_ONCE} or {@code AT_LEAST_ONCE}. 103 * @return the options. 104 */ 105 public AmqpReceiverOptions setQos(string qos) { 106 this.qos = qos; 107 return this; 108 } 109 110 /** 111 * Gets the list of desired capabilities for the source. 112 * A registry of commonly defined source capabilities and their meanings is maintained at 113 * <a href="http://www.amqp.org/specification/1.0/source-capabilities">AMQP Source Capabilities</a>. 114 * 115 * @return the list of capabilities, empty if none. 116 */ 117 public List!string getCapabilities() { 118 if (capabilities is null) { 119 return new ArrayList!string(); 120 } 121 return capabilities; 122 } 123 124 /** 125 * Sets the list of desired capabilities 126 * A registry of commonly defined source capabilities and their meanings is maintained at 127 * <a href="http://www.amqp.org/specification/1.0/source-capabilities">AMQP Source Capabilities</a>. 128 * 129 * @param capabilities the set of capabilities. 130 * @return the options 131 */ 132 public AmqpReceiverOptions setCapabilities(List!string capabilities) { 133 this.capabilities = capabilities; 134 return this; 135 } 136 137 /** 138 * Adds a desired capability. 139 * A registry of commonly defined source capabilities and their meanings is maintained at 140 * <a href="http://www.amqp.org/specification/1.0/source-capabilities">AMQP Source Capabilities</a>. 141 * 142 * @param capability the capability to add, must not be {@code null} 143 * @return the options 144 */ 145 public AmqpReceiverOptions addCapability(string capability) { 146 // Objects.requireNonNull(capability, "The capability must not be null"); 147 if (this.capabilities is null) { 148 this.capabilities = new ArrayList!string(); 149 } 150 this.capabilities.add(capability); 151 return this; 152 } 153 154 /** 155 * @return if the receiver is durable. 156 */ 157 public bool isDurable() { 158 return durable; 159 } 160 161 /** 162 * Sets the durability. 163 * <p> 164 * Passing {@code true} sets the expiry policy of the source to {@code NEVER} and the durability of the source 165 * to {@code UNSETTLED_STATE}. 166 * 167 * @param durable whether or not the receiver must indicate it's durable 168 * @return the options. 169 */ 170 public AmqpReceiverOptions setDurable(bool durable) { 171 this.durable = durable; 172 return this; 173 } 174 175 /** 176 * @return the max buffered messages 177 */ 178 public int getMaxBufferedMessages() { 179 return this.maxBufferedMessages; 180 } 181 182 /** 183 * Sets the max buffered messages. This message can be used to configure the initial credit of a receiver. 184 * 185 * @param maxBufferSize the max buffered size, must be positive. If not set, default credit is used. 186 * @return the current {@link AmqpReceiverOptions} instance. 187 */ 188 public AmqpReceiverOptions setMaxBufferedMessages(int maxBufferSize) { 189 this.maxBufferedMessages = maxBufferSize; 190 return this; 191 } 192 193 /** 194 * @return {@code true} if the auto-acknowledgement is enabled, {@code false} otherwise. 195 */ 196 public bool isAutoAcknowledgement() { 197 return autoAcknowledgement; 198 } 199 200 /** 201 * Sets the auto-acknowledgement. 202 * When enabled (default), the messages are automatically acknowledged. If set to {@code false}, the messages must 203 * be acknowledged explicitly using {@link AmqpMessage#accepted()}, {@link AmqpMessage#released()} and 204 * {@link AmqpMessage#rejected()}. 205 * 206 * @param auto whether or not the auto-acknowledgement should be enabled. 207 * @return the current {@link AmqpReceiverOptions} instance. 208 */ 209 public AmqpReceiverOptions setAutoAcknowledgement(bool aut) { 210 this.autoAcknowledgement = aut; 211 return this; 212 } 213 }