001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.activemq.network; 018 019import java.util.List; 020import java.util.concurrent.CopyOnWriteArrayList; 021 022import org.apache.activemq.advisory.AdvisorySupport; 023import org.apache.activemq.broker.SslContext; 024import org.apache.activemq.command.ActiveMQDestination; 025import org.apache.activemq.command.ConsumerInfo; 026 027/** 028 * Configuration for a NetworkBridge 029 */ 030public class NetworkBridgeConfiguration { 031 032 private boolean conduitSubscriptions = true; 033 /** 034 * Whether or not network subscriptions on queues are eligible to be conduit 035 * Default is false 036 */ 037 private boolean conduitNetworkQueueSubscriptions; 038 private boolean useVirtualDestSubs; 039 private boolean dynamicOnly; 040 private boolean syncDurableSubs; 041 private boolean dispatchAsync = true; 042 private boolean decreaseNetworkConsumerPriority; 043 private int consumerPriorityBase = ConsumerInfo.NETWORK_CONSUMER_PRIORITY; 044 private boolean duplex; 045 private boolean bridgeTempDestinations = true; 046 private int prefetchSize = 1000; 047 /** 048 * By default set to 0, which is disabled and prefetchSize value will be 049 * used instead. 050 */ 051 private int advisoryPrefetchSize = 0; 052 private int advisoryAckPercentage = 75; 053 private int networkTTL = 1; 054 private int consumerTTL = networkTTL; 055 private int messageTTL = networkTTL; 056 057 private String brokerName = "localhost"; 058 private String brokerURL = ""; 059 private String userName; 060 private String password; 061 private String destinationFilter = null; 062 private String name = "NC"; 063 private String clientIdToken = "_"; 064 065 protected List<ActiveMQDestination> excludedDestinations = new CopyOnWriteArrayList<ActiveMQDestination>(); 066 protected List<ActiveMQDestination> dynamicallyIncludedDestinations = new CopyOnWriteArrayList<ActiveMQDestination>(); 067 protected List<ActiveMQDestination> staticallyIncludedDestinations = new CopyOnWriteArrayList<ActiveMQDestination>(); 068 069 private boolean suppressDuplicateQueueSubscriptions = false; 070 private boolean suppressDuplicateTopicSubscriptions = true; 071 072 private boolean alwaysSyncSend = true; 073 private boolean staticBridge = false; 074 private boolean useCompression = false; 075 private boolean advisoryForFailedForward = false; 076 private boolean useBrokerNamesAsIdSeed = true; 077 private boolean gcDestinationViews = true; 078 private long gcSweepTime = 60 * 1000; 079 private boolean checkDuplicateMessagesOnDuplex = false; 080 081 /** 082 * Bridge factory implementation - by default backed by static factory, which is default implementation and will rely change. 083 */ 084 private BridgeFactory bridgeFactory = NetworkBridgeFactory.INSTANCE; 085 private SslContext sslContext; 086 087 /** 088 * @return the conduitSubscriptions 089 */ 090 public boolean isConduitSubscriptions() { 091 return this.conduitSubscriptions; 092 } 093 094 /** 095 * @param conduitSubscriptions the conduitSubscriptions to set 096 */ 097 public void setConduitSubscriptions(boolean conduitSubscriptions) { 098 this.conduitSubscriptions = conduitSubscriptions; 099 } 100 101 public boolean isConduitNetworkQueueSubscriptions() { 102 return conduitNetworkQueueSubscriptions; 103 } 104 105 public void setConduitNetworkQueueSubscriptions(boolean conduitNetworkQueueSubscriptions) { 106 this.conduitNetworkQueueSubscriptions = conduitNetworkQueueSubscriptions; 107 } 108 109 /** 110 * @return the dynamicOnly 111 */ 112 public boolean isDynamicOnly() { 113 return this.dynamicOnly; 114 } 115 116 /** 117 * @param dynamicOnly the dynamicOnly to set 118 */ 119 public void setDynamicOnly(boolean dynamicOnly) { 120 this.dynamicOnly = dynamicOnly; 121 } 122 123 public boolean isSyncDurableSubs() { 124 return syncDurableSubs; 125 } 126 127 public void setSyncDurableSubs(boolean syncDurableSubs) { 128 this.syncDurableSubs = syncDurableSubs; 129 } 130 131 /** 132 * @return the bridgeTempDestinations 133 */ 134 public boolean isBridgeTempDestinations() { 135 return this.bridgeTempDestinations; 136 } 137 138 /** 139 * @param bridgeTempDestinations the bridgeTempDestinations to set 140 */ 141 public void setBridgeTempDestinations(boolean bridgeTempDestinations) { 142 this.bridgeTempDestinations = bridgeTempDestinations; 143 } 144 145 /** 146 * @return the decreaseNetworkConsumerPriority 147 */ 148 public boolean isDecreaseNetworkConsumerPriority() { 149 return this.decreaseNetworkConsumerPriority; 150 } 151 152 /** 153 * @param decreaseNetworkConsumerPriority the 154 * decreaseNetworkConsumerPriority to set 155 */ 156 public void setDecreaseNetworkConsumerPriority(boolean decreaseNetworkConsumerPriority) { 157 this.decreaseNetworkConsumerPriority = decreaseNetworkConsumerPriority; 158 } 159 160 /** 161 * @return the dispatchAsync 162 */ 163 public boolean isDispatchAsync() { 164 return this.dispatchAsync; 165 } 166 167 /** 168 * @param dispatchAsync the dispatchAsync to set 169 */ 170 public void setDispatchAsync(boolean dispatchAsync) { 171 this.dispatchAsync = dispatchAsync; 172 } 173 174 /** 175 * @return the duplex 176 */ 177 public boolean isDuplex() { 178 return this.duplex; 179 } 180 181 /** 182 * @param duplex the duplex to set 183 */ 184 public void setDuplex(boolean duplex) { 185 this.duplex = duplex; 186 } 187 188 /** 189 * @return the brokerName 190 */ 191 public String getBrokerName() { 192 return this.brokerName; 193 } 194 195 /** 196 * @param brokerName the localBrokerName to set 197 */ 198 public void setBrokerName(String brokerName) { 199 this.brokerName = brokerName; 200 } 201 202 public String getClientIdToken() { 203 return clientIdToken; 204 } 205 206 public void setClientIdToken(String clientIdToken) { 207 this.clientIdToken = clientIdToken; 208 } 209 210 /** 211 * @return the networkTTL 212 */ 213 public int getNetworkTTL() { 214 return this.networkTTL; 215 } 216 217 /** 218 * @param networkTTL the networkTTL to set 219 */ 220 public void setNetworkTTL(int networkTTL) { 221 this.networkTTL = networkTTL; 222 setConsumerTTL(networkTTL); 223 setMessageTTL(networkTTL); 224 } 225 226 /** 227 * @return the password 228 */ 229 public String getPassword() { 230 return this.password; 231 } 232 233 /** 234 * @param password the password to set 235 */ 236 public void setPassword(String password) { 237 this.password = password; 238 } 239 240 /** 241 * @return the prefetchSize 242 */ 243 public int getPrefetchSize() { 244 return this.prefetchSize; 245 } 246 247 /** 248 * @param prefetchSize the prefetchSize to set 249 * @org.apache.xbean.Property propertyEditor="org.apache.activemq.util.MemoryIntPropertyEditor" 250 */ 251 public void setPrefetchSize(int prefetchSize) { 252 if (prefetchSize < 1) { 253 throw new IllegalArgumentException("prefetchSize must be > 0" 254 + " because network consumers do not poll for messages."); 255 } 256 this.prefetchSize = prefetchSize; 257 } 258 259 public int getAdvisoryPrefetchSize() { 260 return advisoryPrefetchSize; 261 } 262 263 /** 264 * Prefetch size for advisory consumers. Just like prefetchSize, if set, this 265 * value must be greater than 0 because network consumers do not poll for messages. 266 * Setting this to 0 or less means this value is disabled and prefetchSize will be 267 * used instead. 268 * 269 * @param advisoryPrefetchSize 270 */ 271 public void setAdvisoryPrefetchSize(int advisoryPrefetchSize) { 272 this.advisoryPrefetchSize = advisoryPrefetchSize; 273 } 274 275 public int getAdvisoryAckPercentage() { 276 return advisoryAckPercentage; 277 } 278 279 /** 280 * @param advisoryAckPercentage the percentage of the advisory prefetch size 281 * value that can be dispatched before an ack will be sent, defaults to 75 282 * which means that when the number of received messages is greater than 75% of 283 * the prefetch size an ack will be sent back 284 */ 285 public void setAdvisoryAckPercentage(int advisoryAckPercentage) { 286 this.advisoryAckPercentage = advisoryAckPercentage; 287 } 288 289 /** 290 * @return the userName 291 */ 292 public String getUserName() { 293 return this.userName; 294 } 295 296 /** 297 * @param userName the userName to set 298 */ 299 public void setUserName(String userName) { 300 this.userName = userName; 301 } 302 303 /** 304 * @return the destinationFilter 305 */ 306 public String getDestinationFilter() { 307 if (this.destinationFilter == null) { 308 if (dynamicallyIncludedDestinations != null && !dynamicallyIncludedDestinations.isEmpty()) { 309 StringBuffer filter = new StringBuffer(); 310 String delimiter = ""; 311 for (ActiveMQDestination destination : dynamicallyIncludedDestinations) { 312 if (!destination.isTemporary()) { 313 filter.append(delimiter); 314 filter.append(AdvisorySupport.CONSUMER_ADVISORY_TOPIC_PREFIX); 315 filter.append(destination.getDestinationTypeAsString()); 316 filter.append("."); 317 filter.append(destination.getPhysicalName()); 318 delimiter = ","; 319 320 if (useVirtualDestSubs) { 321 filter.append(delimiter); 322 filter.append(AdvisorySupport.VIRTUAL_DESTINATION_CONSUMER_ADVISORY_TOPIC_PREFIX); 323 filter.append(destination.getDestinationTypeAsString()); 324 filter.append("."); 325 filter.append(destination.getPhysicalName()); 326 } 327 } 328 } 329 return filter.toString(); 330 } else { 331 StringBuffer filter = new StringBuffer(); 332 filter.append(AdvisorySupport.CONSUMER_ADVISORY_TOPIC_PREFIX); 333 filter.append(">"); 334 if (useVirtualDestSubs) { 335 filter.append(","); 336 filter.append(AdvisorySupport.VIRTUAL_DESTINATION_CONSUMER_ADVISORY_TOPIC_PREFIX); 337 filter.append(">"); 338 } 339 return filter.toString(); 340 } 341 } else { 342 // prepend consumer advisory prefix 343 // to keep backward compatibility 344 if (!this.destinationFilter.startsWith(AdvisorySupport.CONSUMER_ADVISORY_TOPIC_PREFIX)) { 345 return AdvisorySupport.CONSUMER_ADVISORY_TOPIC_PREFIX + this.destinationFilter; 346 } else { 347 return this.destinationFilter; 348 } 349 } 350 } 351 352 /** 353 * @param destinationFilter the destinationFilter to set 354 */ 355 public void setDestinationFilter(String destinationFilter) { 356 this.destinationFilter = destinationFilter; 357 } 358 359 /** 360 * @return the name 361 */ 362 public String getName() { 363 return this.name; 364 } 365 366 /** 367 * @param name the name to set 368 */ 369 public void setName(String name) { 370 this.name = name; 371 } 372 373 public List<ActiveMQDestination> getExcludedDestinations() { 374 return excludedDestinations; 375 } 376 377 public void setExcludedDestinations( 378 List<ActiveMQDestination> excludedDestinations) { 379 this.excludedDestinations = excludedDestinations; 380 } 381 382 public List<ActiveMQDestination> getDynamicallyIncludedDestinations() { 383 return dynamicallyIncludedDestinations; 384 } 385 386 public void setDynamicallyIncludedDestinations( 387 List<ActiveMQDestination> dynamicallyIncludedDestinations) { 388 this.dynamicallyIncludedDestinations = dynamicallyIncludedDestinations; 389 } 390 391 public List<ActiveMQDestination> getStaticallyIncludedDestinations() { 392 return staticallyIncludedDestinations; 393 } 394 395 public void setStaticallyIncludedDestinations( 396 List<ActiveMQDestination> staticallyIncludedDestinations) { 397 this.staticallyIncludedDestinations = staticallyIncludedDestinations; 398 } 399 400 public boolean isSuppressDuplicateQueueSubscriptions() { 401 return suppressDuplicateQueueSubscriptions; 402 } 403 404 /** 405 * 406 * @param val if true, duplicate network queue subscriptions (in a cyclic network) will be suppressed 407 */ 408 public void setSuppressDuplicateQueueSubscriptions(boolean val) { 409 suppressDuplicateQueueSubscriptions = val; 410 } 411 412 public boolean isSuppressDuplicateTopicSubscriptions() { 413 return suppressDuplicateTopicSubscriptions; 414 } 415 416 /** 417 * 418 * @param val if true, duplicate network topic subscriptions (in a cyclic network) will be suppressed 419 */ 420 public void setSuppressDuplicateTopicSubscriptions(boolean val) { 421 suppressDuplicateTopicSubscriptions = val; 422 } 423 424 /** 425 * @return the brokerURL 426 */ 427 public String getBrokerURL() { 428 return this.brokerURL; 429 } 430 431 /** 432 * @param brokerURL the brokerURL to set 433 */ 434 public void setBrokerURL(String brokerURL) { 435 this.brokerURL = brokerURL; 436 } 437 438 public boolean isAlwaysSyncSend() { 439 return alwaysSyncSend; 440 } 441 442 /** 443 * @param alwaysSyncSend when true, both persistent and non persistent 444 * messages will be sent using a request. When false, non persistent messages 445 * are acked once the oneway send succeeds, which can potentially lead to 446 * message loss. 447 * Using an async request, allows multiple outstanding requests. This ensures 448 * that a bridge need not block all sending when the remote broker needs to 449 * flow control a single destination. 450 */ 451 public void setAlwaysSyncSend(boolean alwaysSyncSend) { 452 this.alwaysSyncSend = alwaysSyncSend; 453 } 454 455 public int getConsumerPriorityBase() { 456 return consumerPriorityBase; 457 } 458 459 /** 460 * @param consumerPriorityBase , default -5. Sets the starting priority 461 * for consumers. This base value will be decremented by the length of the 462 * broker path when decreaseNetworkConsumerPriority is set. 463 */ 464 public void setConsumerPriorityBase(int consumerPriorityBase) { 465 this.consumerPriorityBase = consumerPriorityBase; 466 } 467 468 public boolean isStaticBridge() { 469 return staticBridge; 470 } 471 472 public void setStaticBridge(boolean staticBridge) { 473 this.staticBridge = staticBridge; 474 } 475 476 /** 477 * @param useCompression 478 * True if the Network should enforce compression for messages sent. 479 */ 480 public void setUseCompression(boolean useCompression) { 481 this.useCompression = useCompression; 482 } 483 484 /** 485 * @return the useCompression setting, true if message will be compressed on send. 486 */ 487 public boolean isUseCompression() { 488 return useCompression; 489 } 490 491 public boolean isAdvisoryForFailedForward() { 492 return advisoryForFailedForward; 493 } 494 495 public void setAdvisoryForFailedForward(boolean advisoryForFailedForward) { 496 this.advisoryForFailedForward = advisoryForFailedForward; 497 } 498 499 public void setConsumerTTL(int consumerTTL) { 500 this.consumerTTL = consumerTTL; 501 } 502 503 public int getConsumerTTL() { 504 return consumerTTL; 505 } 506 507 public void setMessageTTL(int messageTTL) { 508 this.messageTTL = messageTTL; 509 } 510 511 public int getMessageTTL() { 512 return messageTTL; 513 } 514 515 public boolean isUseBrokerNamesAsIdSeed() { 516 return useBrokerNamesAsIdSeed; 517 } 518 519 public void setUseBrokerNameAsIdSees(boolean val) { 520 useBrokerNamesAsIdSeed = val; 521 } 522 523 public boolean isGcDestinationViews() { 524 return gcDestinationViews; 525 } 526 527 public void setGcDestinationViews(boolean gcDestinationViews) { 528 this.gcDestinationViews = gcDestinationViews; 529 } 530 531 public long getGcSweepTime() { 532 return gcSweepTime; 533 } 534 535 public void setGcSweepTime(long gcSweepTime) { 536 this.gcSweepTime = gcSweepTime; 537 } 538 539 public boolean isCheckDuplicateMessagesOnDuplex() { 540 return checkDuplicateMessagesOnDuplex; 541 } 542 543 public void setCheckDuplicateMessagesOnDuplex(boolean checkDuplicateMessagesOnDuplex) { 544 this.checkDuplicateMessagesOnDuplex = checkDuplicateMessagesOnDuplex; 545 } 546 547 public boolean isUseVirtualDestSubs() { 548 return useVirtualDestSubs; 549 } 550 551 public BridgeFactory getBridgeFactory() { 552 return bridgeFactory; 553 } 554 555 public void setBridgeFactory(BridgeFactory bridgeFactory) { 556 this.bridgeFactory = bridgeFactory; 557 } 558 559 /** 560 * This was a typo, so this is deprecated as of 5.13.1 561 */ 562 @Deprecated 563 public boolean isUseVirtualDestSus() { 564 return useVirtualDestSubs; 565 } 566 567 public void setUseVirtualDestSubs( 568 boolean useVirtualDestSubs) { 569 this.useVirtualDestSubs = useVirtualDestSubs; 570 } 571 572 public void setSslContext(SslContext sslContext) { 573 this.sslContext = sslContext; 574 } 575 576 public SslContext getSslContext() { 577 return sslContext; 578 } 579}