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.AmqpClientOptions; 12 13 //import hunt.codegen.annotations.DataObject; 14 //import hunt.core.buffer.Buffer; 15 //import hunt.core.json.JsonObject; 16 //import hunt.core.net.*; 17 import hunt.amqp.ProtonClientOptions; 18 19 import hunt.collection.Set; 20 import core.time; 21 22 /** 23 * Configures the AMQP Client. 24 * You can also configure the underlying Proton instance. Refer to {@link ProtonClientOptions} for details. 25 */ 26 //@DataObject(generateConverter = true, inheritConverter = true) 27 class AmqpClientOptions : ProtonClientOptions { 28 29 enum string DEFAULT_HOST = "localhost"; 30 enum int DEFAULT_PORT = 5672; 31 enum int DEFAULT_SENTINEL_PORT = 26379; 32 enum int DEFAULT_TIMEOUT = 2000; 33 // https://www.rabbitmq.com/access-control.html 34 enum string DEFAULT_USERNAME = "guest"; 35 enum string DEFAULT_PASSWORD = "guest"; 36 37 // TODO Capabilities and properties 38 39 private string host = DEFAULT_HOST;//= getFromSysOrEnv("amqp-client-host"); 40 private int port = DEFAULT_PORT;//= getPortFromSysOrEnv(); 41 42 private string username = DEFAULT_USERNAME;// = getFromSysOrEnv("amqp-client-username"); 43 private string password = DEFAULT_PASSWORD;// = getFromSysOrEnv("amqp-client-password"); 44 45 private string containerId ;//= UUID.randomUUID().toString(); 46 47 this() { 48 super(); 49 setConnectTimeout(10.seconds); 50 setIdleTimeout(10.seconds); 51 } 52 53 //AmqpClientOptions(JsonObject json) { 54 // super(json); 55 // AmqpClientOptionsConverter.fromJson(json, this); 56 //} 57 58 this(AmqpClientOptions other) { 59 super(other); 60 this.host = other.host; 61 this.password = other.password; 62 this.username = other.username; 63 this.port = other.port; 64 this.containerId = other.containerId; 65 } 66 67 //JsonObject toJson() { 68 // JsonObject json = super.toJson(); 69 // AmqpClientOptionsConverter.toJson(this, json); 70 // return json; 71 //} 72 73 /** 74 * @return the host. 75 */ 76 string getHost() { 77 return host; 78 } 79 80 /** 81 * Sets the host. 82 * 83 * @param host the host, must not be {@code null} when the client attempt to connect. Defaults to system variable 84 * {@code amqp-client-host} and to {@code AMQP_CLIENT_HOST} environment variable 85 * @return the current {@link AmqpClientOptions} 86 */ 87 AmqpClientOptions setHost(string host) { 88 this.host = host; 89 return this; 90 } 91 92 /** 93 * @return the port. 94 */ 95 int getPort() { 96 return port; 97 } 98 99 /** 100 * Sets the port. 101 * 102 * @param port the port, defaults to system variable {@code amqp-client-port} and to {@code AMQP_CLIENT_PORT} 103 * environment variable and if neither is set {@code 5672}. 104 * @return the current {@link AmqpClientOptions} 105 */ 106 AmqpClientOptions setPort(int port) { 107 this.port = port; 108 return this; 109 } 110 111 /** 112 * @return the username 113 */ 114 string getUsername() { 115 return username; 116 } 117 118 /** 119 * Sets the username. 120 * 121 * @param username the username, defaults to system variable {@code amqp-client-username} and 122 * to {@code AMQP_CLIENT_USERNAME} environment variable. 123 * @return the current {@link AmqpClientOptions} 124 */ 125 AmqpClientOptions setUsername(string username) { 126 this.username = username; 127 return this; 128 } 129 130 /** 131 * @return the password 132 */ 133 string getPassword() { 134 return password; 135 } 136 137 /** 138 * Sets the password. 139 * 140 * @param pwd the password, defaults to system variable {@code amqp-client-password} and to 141 * {@code AMQP_CLIENT_PASSWORD} environment variable. 142 * @return the current {@link AmqpClientOptions} 143 */ 144 AmqpClientOptions setPassword(string pwd) { 145 this.password = pwd; 146 return this; 147 } 148 149 /** 150 * @return the container id. 151 */ 152 string getContainerId() { 153 return containerId; 154 } 155 156 /** 157 * Sets the container id. 158 * 159 * @param containerId the container id 160 * @return the current {@link AmqpClientOptions} 161 */ 162 AmqpClientOptions setContainerId(string containerId) { 163 this.containerId = containerId; 164 return this; 165 } 166 167 /** 168 * @see ProtonClientOptions#addEnabledSaslMechanism(string) 169 */ 170 override 171 AmqpClientOptions addEnabledSaslMechanism(string saslMechanism) { 172 super.addEnabledSaslMechanism(saslMechanism); 173 return this; 174 } 175 176 /** 177 * @see ProtonClientOptions#setSendBufferSize(int) 178 */ 179 override 180 AmqpClientOptions setSendBufferSize(int sendBufferSize) { 181 super.setSendBufferSize(sendBufferSize); 182 return this; 183 } 184 185 /** 186 * @see ProtonClientOptions#setReceiveBufferSize(int) 187 */ 188 override 189 AmqpClientOptions setReceiveBufferSize(int receiveBufferSize) { 190 super.setReceiveBufferSize(receiveBufferSize); 191 return this; 192 } 193 194 /** 195 * @see ProtonClientOptions#setReuseAddress(boolean) 196 */ 197 override 198 AmqpClientOptions setReuseAddress(bool reuseAddress) { 199 super.setReuseAddress(reuseAddress); 200 return this; 201 } 202 203 /** 204 * @see ProtonClientOptions#setTrafficClass(int) 205 */ 206 override 207 AmqpClientOptions setTrafficClass(int trafficClass) { 208 super.setTrafficClass(trafficClass); 209 return this; 210 } 211 212 /** 213 * @see ProtonClientOptions#setTcpNoDelay(boolean) 214 */ 215 override 216 AmqpClientOptions setTcpNoDelay(bool tcpNoDelay) { 217 super.setTcpNoDelay(tcpNoDelay); 218 return this; 219 } 220 221 /** 222 * @see ProtonClientOptions#setTcpKeepAlive(boolean) 223 */ 224 override 225 AmqpClientOptions setTcpKeepAlive(bool tcpKeepAlive) { 226 super.setTcpKeepAlive(tcpKeepAlive); 227 return this; 228 } 229 230 /** 231 * @see ProtonClientOptions#setSoLinger(int) 232 */ 233 override 234 AmqpClientOptions setSoLinger(int soLinger) { 235 super.setSoLinger(soLinger); 236 return this; 237 } 238 239 /** 240 * @see ProtonClientOptions#setIdleTimeout(int) 241 */ 242 override 243 AmqpClientOptions setIdleTimeout(Duration idleTimeout) { 244 super.setIdleTimeout(idleTimeout); 245 return this; 246 } 247 248 /** 249 * @see ProtonClientOptions#setSsl(boolean) 250 */ 251 override 252 AmqpClientOptions setSsl(bool ssl) { 253 super.setSsl(ssl); 254 return this; 255 } 256 257 /** 258 * @see ProtonClientOptions#setKeyStoreOptions(JksOptions) 259 */ 260 //override 261 //AmqpClientOptions setKeyStoreOptions(JksOptions options) { 262 // super.setKeyStoreOptions(options); 263 // return this; 264 //} 265 266 /** 267 * @see ProtonClientOptions#setPfxKeyCertOptions(PfxOptions) 268 */ 269 //override 270 //AmqpClientOptions setPfxKeyCertOptions(PfxOptions options) { 271 // super.setPfxKeyCertOptions(options); 272 // return this; 273 //} 274 275 /** 276 * @see ProtonClientOptions#setPemKeyCertOptions(PemKeyCertOptions) 277 */ 278 //override 279 //AmqpClientOptions setPemKeyCertOptions(PemKeyCertOptions options) { 280 // super.setPemKeyCertOptions(options); 281 // return this; 282 //} 283 284 /** 285 * @see ProtonClientOptions#setTrustStoreOptions(JksOptions) 286 */ 287 //override 288 //AmqpClientOptions setTrustStoreOptions(JksOptions options) { 289 // super.setTrustStoreOptions(options); 290 // return this; 291 //} 292 293 /** 294 * @see ProtonClientOptions#setPemTrustOptions(PemTrustOptions) 295 */ 296 //override 297 //AmqpClientOptions setPemTrustOptions(PemTrustOptions options) { 298 // super.setPemTrustOptions(options); 299 // return this; 300 //} 301 302 /** 303 * @see ProtonClientOptions#setPfxTrustOptions(PfxOptions) 304 */ 305 //override 306 //AmqpClientOptions setPfxTrustOptions(PfxOptions options) { 307 // super.setPfxTrustOptions(options); 308 // return this; 309 //} 310 311 /** 312 * @see ProtonClientOptions#addEnabledCipherSuite(string) 313 */ 314 //override 315 //AmqpClientOptions addEnabledCipherSuite(string suite) { 316 // super.addEnabledCipherSuite(suite); 317 // return this; 318 //} 319 320 /** 321 * @see ProtonClientOptions#addCrlPath(string) 322 */ 323 //override 324 //AmqpClientOptions addCrlPath(string crlPath) { 325 // super.addCrlPath(crlPath); 326 // return this; 327 //} 328 329 /** 330 * @see ProtonClientOptions#addCrlValue(Buffer) 331 */ 332 //override 333 //AmqpClientOptions addCrlValue(Buffer crlValue) { 334 // super.addCrlValue(crlValue); 335 // return this; 336 //} 337 338 /** 339 * @see ProtonClientOptions#setTrustAll(boolean) 340 */ 341 override 342 AmqpClientOptions setTrustAll(bool trustAll) { 343 super.setTrustAll(trustAll); 344 return this; 345 } 346 347 /** 348 * @see ProtonClientOptions#setConnectTimeout(int) 349 */ 350 override 351 AmqpClientOptions setConnectTimeout(Duration connectTimeout) { 352 super.setConnectTimeout(connectTimeout); 353 return this; 354 } 355 356 /** 357 * @see ProtonClientOptions#setReconnectAttempts(int) 358 */ 359 override 360 AmqpClientOptions setReconnectAttempts(int attempts) { 361 super.setReconnectAttempts(attempts); 362 return this; 363 } 364 365 /** 366 * @see ProtonClientOptions#setReconnectInterval(long) 367 */ 368 override 369 AmqpClientOptions setReconnectInterval(Duration interval) { 370 super.setReconnectInterval(interval); 371 return this; 372 } 373 374 /** 375 * @see ProtonClientOptions#addEnabledSecureTransportProtocol(string) 376 */ 377 //override 378 //AmqpClientOptions addEnabledSecureTransportProtocol(string protocol) { 379 // super.addEnabledSecureTransportProtocol(protocol); 380 // return this; 381 //} 382 383 /** 384 * @see ProtonClientOptions#setHostnameVerificationAlgorithm(string) 385 */ 386 override 387 AmqpClientOptions setHostnameVerificationAlgorithm(string hostnameVerificationAlgorithm) { 388 super.setHostnameVerificationAlgorithm(hostnameVerificationAlgorithm); 389 return this; 390 } 391 392 /** 393 * @see ProtonClientOptions#setJdkSslEngineOptions(JdkSSLEngineOptions) 394 */ 395 //override 396 //AmqpClientOptions setJdkSslEngineOptions(JdkSSLEngineOptions sslEngineOptions) { 397 // super.setJdkSslEngineOptions(sslEngineOptions); 398 // return this; 399 //} 400 401 /** 402 * @see ProtonClientOptions#setOpenSslEngineOptions(OpenSSLEngineOptions) 403 */ 404 //override 405 //AmqpClientOptions setOpenSslEngineOptions(OpenSSLEngineOptions sslEngineOptions) { 406 // super.setOpenSslEngineOptions(sslEngineOptions); 407 // return this; 408 //} 409 410 /** 411 * @see ProtonClientOptions#setSslEngineOptions(SSLEngineOptions) 412 */ 413 //override 414 //AmqpClientOptions setSslEngineOptions(SSLEngineOptions sslEngineOptions) { 415 // super.setSslEngineOptions(sslEngineOptions); 416 // return this; 417 //} 418 419 /** 420 * @see ProtonClientOptions#setLocalAddress(string) 421 */ 422 override 423 AmqpClientOptions setLocalAddress(string localAddress) { 424 super.setLocalAddress(localAddress); 425 return this; 426 } 427 428 /** 429 * @see ProtonClientOptions#setReusePort(boolean) 430 */ 431 override 432 AmqpClientOptions setReusePort(bool reusePort) { 433 super.setReusePort(reusePort); 434 return this; 435 } 436 437 /** 438 * @see ProtonClientOptions#setTcpCork(boolean) 439 */ 440 override 441 AmqpClientOptions setTcpCork(bool tcpCork) { 442 super.setTcpCork(tcpCork); 443 return this; 444 } 445 446 /** 447 * @see ProtonClientOptions#setTcpFastOpen(boolean) 448 */ 449 override 450 AmqpClientOptions setTcpFastOpen(bool tcpFastOpen) { 451 super.setTcpFastOpen(tcpFastOpen); 452 return this; 453 } 454 455 /** 456 * @see ProtonClientOptions#setTcpQuickAck(boolean) 457 */ 458 override 459 AmqpClientOptions setTcpQuickAck(bool tcpQuickAck) { 460 super.setTcpQuickAck(tcpQuickAck); 461 return this; 462 } 463 464 /** 465 * @see ProtonClientOptions#removeEnabledSecureTransportProtocol(string) 466 */ 467 //override 468 //AmqpClientOptions removeEnabledSecureTransportProtocol(string protocol) { 469 // super.removeEnabledSecureTransportProtocol(protocol); 470 // return this; 471 //} 472 473 /** 474 * @see ProtonClientOptions#setEnabledSecureTransportProtocols(Set) 475 */ 476 //override 477 //AmqpClientOptions setEnabledSecureTransportProtocols(Set<string> enabledSecureTransportProtocols) { 478 // super.setEnabledSecureTransportProtocols(enabledSecureTransportProtocols); 479 // return this; 480 //} 481 482 /** 483 * @see ProtonClientOptions#setVirtualHost(string) 484 */ 485 override 486 AmqpClientOptions setVirtualHost(string virtualHost) { 487 super.setVirtualHost(virtualHost); 488 return this; 489 } 490 491 /** 492 * @see ProtonClientOptions#setSniServerName(string) 493 */ 494 override 495 AmqpClientOptions setSniServerName(string sniServerName) { 496 super.setSniServerName(sniServerName); 497 return this; 498 } 499 500 /** 501 * @see ProtonClientOptions#setHeartbeat(int) 502 */ 503 override 504 AmqpClientOptions setHeartbeat(int heartbeat) { 505 super.setHeartbeat(heartbeat); 506 return this; 507 } 508 509 /** 510 * @see ProtonClientOptions#setMaxFrameSize(int) 511 */ 512 override 513 AmqpClientOptions setMaxFrameSize(int maxFrameSize) { 514 super.setMaxFrameSize(maxFrameSize); 515 return this; 516 } 517 518 //private string getFromSysOrEnv(string key) { 519 // string sys = System.getProperty(key); 520 // if (sys is null) { 521 // return System.getenv(key.toUpperCase().replace("-", "_")); 522 // } 523 // return sys; 524 //} 525 // 526 //private int getPortFromSysOrEnv() { 527 // string s = getFromSysOrEnv("amqp-client-port"); 528 // if (s is null) { 529 // return 5672; 530 // } else { 531 // return Integer.parseInt(s); 532 // } 533 //} 534 }