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