@Override public String toString() { return "DurableConduitBridge:" + configuration.getBrokerName() + "->" + getRemoteBrokerName(); } /**
protected void removeDemandSubscription(ConsumerId id) throws IOException { DemandSubscription sub = subscriptionMapByRemoteId.remove(id); LOG.debug("{} remove request on {} from {}, consumer id: {}, matching sub: {}", new Object[]{ configuration.getBrokerName(), localBroker, remoteBrokerName, id, sub }); if (sub != null) { removeSubscription(sub); LOG.debug("{} removed sub on {} from {}: {}", new Object[]{ configuration.getBrokerName(), localBroker, remoteBrokerName, sub.getRemoteInfo() }); } }
protected String getSubscriberName(ActiveMQDestination dest) { String subscriberName = DURABLE_SUB_PREFIX + configuration.getBrokerName() + "_" + dest.getPhysicalName(); return subscriberName; }
@Override protected void removeDemandSubscription(ConsumerId id) throws IOException { List<DemandSubscription> tmpList = new ArrayList<DemandSubscription>(); for (DemandSubscription ds : subscriptionMapByLocalId.values()) { if (ds.remove(id)) { LOG.debug("{} on {} from {} removed interest for: {} from {}", new Object[]{ configuration.getBrokerName(), localBroker, remoteBrokerName, id, ds }); } if (ds.isEmpty()) { tmpList.add(ds); } } for (DemandSubscription ds : tmpList) { removeSubscription(ds); LOG.debug("{} on {} from {} removed {}", new Object[]{ configuration.getBrokerName(), localBroker, remoteBrokerName, ds }); } } }
/** * Subscriptions for these destinations are always created */ protected void setupStaticDestinations() { ActiveMQDestination[] dests = staticallyIncludedDestinations; if (dests != null) { for (ActiveMQDestination dest : dests) { if (isPermissableDestination(dest)) { DemandSubscription sub = createDemandSubscription(dest, null); if (sub != null) { sub.setStaticallyIncluded(true); try { addSubscription(sub); } catch (IOException e) { LOG.error("Failed to add static destination {}", dest, e); } LOG.trace("{}, bridging messages for static destination: {}", configuration.getBrokerName(), dest); } else { LOG.info("{}, static destination excluded: {}, demand already exists", configuration.getBrokerName(), dest); } } else { LOG.info("{}, static destination excluded: {}", configuration.getBrokerName(), dest); } } } }
private boolean hasLowerPriority(Subscription existingSub, ConsumerInfo candidateInfo) { boolean suppress = false; if (existingSub.getConsumerInfo().getPriority() >= candidateInfo.getPriority()) { LOG.debug("{} Ignoring duplicate subscription from {}, sub: {} is duplicate by network subscription with equal or higher network priority: {}, networkConsumerIds: {}", new Object[]{ configuration.getBrokerName(), remoteBrokerName, candidateInfo, existingSub, existingSub.getConsumerInfo().getNetworkConsumerIds() }); suppress = true; } else { // remove the existing lower priority duplicate and allow this candidate try { removeDuplicateSubscription(existingSub); LOG.debug("{} Replacing duplicate subscription {} with sub from {}, which has a higher priority, new sub: {}, networkConsumerIds: {}", new Object[]{ configuration.getBrokerName(), existingSub.getConsumerInfo(), remoteBrokerName, candidateInfo, candidateInfo.getNetworkConsumerIds() }); } catch (IOException e) { LOG.error("Failed to remove duplicated sub as a result of sub with higher priority, sub: {}", existingSub, e); } } return suppress; }
protected void removeSubscription(final DemandSubscription sub) throws IOException { if (sub != null) { LOG.trace("{} remove local subscription: {} for remote {}", new Object[]{configuration.getBrokerName(), sub.getLocalInfo().getConsumerId(), sub.getRemoteInfo().getConsumerId()}); // ensure not available for conduit subs pending removal subscriptionMapByLocalId.remove(sub.getLocalInfo().getConsumerId()); subscriptionMapByRemoteId.remove(sub.getRemoteInfo().getConsumerId()); // continue removal in separate thread to free up tshis thread for outstanding responses // Serialize with removeDestination operations so that removeSubs are serialized with // removeDestinations such that all removeSub advisories are generated serialExecutor.execute(new Runnable() { @Override public void run() { sub.waitForCompletion(); try { localBroker.oneway(sub.getLocalInfo().createRemoveCommand()); } catch (IOException e) { LOG.warn("failed to deliver remove command for local subscription, for remote {}", sub.getRemoteInfo().getConsumerId(), e); } } }); } }
if (started.compareAndSet(true, false)) { if (disposed.compareAndSet(false, true)) { LOG.debug(" stopping {} bridge to {}", configuration.getBrokerName(), remoteBrokerName); configuration.getBrokerName(), this, remoteBrokerName }); brokerService.getBroker().removeBroker(null, remoteBrokerInfo); LOG.info("{} bridge to {} stopped", configuration.getBrokerName(), remoteBrokerName);
LOG.debug("{} Ignoring sub from {}, browsers explicitly suppressed", configuration.getBrokerName(), remoteBrokerName); return; configuration.getBrokerName(), remoteBrokerName, networkTTL, info }); return; configuration.getBrokerName(), remoteBrokerName, info }); return; configuration.getBrokerName(), remoteBrokerName, info.getDestination(), info }); return; if (path != null && networkTTL > -1 && path.length >= networkTTL) { LOG.debug("{} Ignoring destination {} restricted to {} network hops only", new Object[]{ configuration.getBrokerName(), destInfo, networkTTL }); return; LOG.debug("{} Ignoring destination {} already routed through this broker once", configuration.getBrokerName(), destInfo); return; configuration.getBrokerName(), (destInfo.isAddOperation() ? "add" : "remove"), localBroker, remoteBrokerName, destInfo }); if (destInfo.isRemoveOperation()) {
if (localBrokerId.equals(remoteBrokerId)) { LOG.trace("{} disconnecting remote loop back connector for: {}, with id: {}", new Object[]{ configuration.getBrokerName(), remoteBrokerName, remoteBrokerId }); ServiceSupport.dispose(localBroker);
private void startLocalBridge() throws Throwable { if (!bridgeFailed.get() && localBridgeStarted.compareAndSet(false, true)) { synchronized (this) { LOG.trace("{} starting local Bridge, localBroker={}", configuration.getBrokerName(), localBroker); if (!disposed.get()) { localClientId = configuration.getName() + configuration.getClientIdToken() + remoteBrokerName + configuration.getClientIdToken() + "inbound" + configuration.getClientIdToken() + configuration.getBrokerName(); localConnectionInfo.setClientId(localClientId); localConnectionInfo.setUserName(configuration.getUserName()); duplexLocalConnectionInfo.setConnectionId(new ConnectionId(idGenerator.generateId())); duplexLocalConnectionInfo.setClientId(configuration.getName() + configuration.getClientIdToken() + remoteBrokerName + configuration.getClientIdToken() + "inbound" + configuration.getClientIdToken() + "duplex" + configuration.getClientIdToken() + configuration.getBrokerName()); duplexLocalConnectionInfo.setUserName(configuration.getUserName()); duplexLocalConnectionInfo.setPassword(configuration.getPassword()); }); LOG.trace("{} register bridge ({}) to {}", new Object[]{ configuration.getBrokerName(), this, remoteBrokerName }); } else {
configuration.getBrokerName(), remoteBrokerName, Arrays.toString(md.getMessage().getBrokerPath()), md.getMessage() }); configuration.getBrokerName(), remoteBrokerName, md.getConsumerId(), message.getDestination(), Arrays.toString(message.getBrokerPath()), (LOG.isTraceEnabled() ? message : message.getMessageId()) }); if (isDuplex() && NetworkBridgeFilter.isAdvisoryInterpretedByNetworkBridge(message)) { futureLocalBrokerInfo.set((BrokerInfo) command); } else if (command.isShutdownInfo()) { LOG.info("{} Shutting down {}", configuration.getBrokerName(), configuration.getName()); stop(); } else if (command.getClass() == ConnectionError.class) {
protected void startRemoteBridge() throws Exception { if (!bridgeFailed.get() && remoteBridgeStarted.compareAndSet(false, true)) { LOG.trace("{} starting remote Bridge, remoteBroker={}", configuration.getBrokerName(), remoteBroker); synchronized (this) { if (!isCreatedByDuplex()) { BrokerInfo brokerInfo = new BrokerInfo(); brokerInfo.setBrokerName(configuration.getBrokerName()); brokerInfo.setBrokerURL(configuration.getBrokerURL()); brokerInfo.setNetworkConnection(true); remoteConnectionInfo.setClientId(configuration.getName() + configuration.getClientIdToken() + configuration.getBrokerName() + configuration.getClientIdToken() + "outbound"); remoteConnectionInfo.setUserName(configuration.getUserName()); remoteConnectionInfo.setPassword(configuration.getPassword());
} else { if (isDuplex()) { LOG.trace("{} duplex command type: {}", configuration.getBrokerName(), command.getDataStructureType()); if (command.isMessage()) { final ActiveMQMessage message = (ActiveMQMessage) command;
if (canConduit(ds) && filter.matches(info.getDestination())) { LOG.debug("{} {} with ids {} matched (add interest) {}", new Object[]{ configuration.getBrokerName(), info, info.getNetworkConsumerIds(), ds });
protected void addConsumerInfo(final ConsumerInfo consumerInfo) throws IOException { ConsumerInfo info = consumerInfo.copy(); addRemoteBrokerToBrokerPath(info); DemandSubscription sub = createDemandSubscription(info); if (sub != null) { if (duplicateSuppressionIsRequired(sub)) { undoMapRegistration(sub); } else { if (consumerInfo.isDurable()) { //Handle the demand generated by proxy network subscriptions //The broker path is case is normal if (isProxyNSConsumerBrokerPath(sub.getRemoteInfo()) && info.getSubscriptionName() != null && info.getSubscriptionName().startsWith(DURABLE_SUB_PREFIX)) { final BrokerId[] path = info.getBrokerPath(); addProxyNetworkSubscriptionBrokerPath(sub, path, consumerInfo.getSubscriptionName()); //This is the durable sync case on broker restart } else if (isProxyNSConsumerClientId(sub.getRemoteInfo().getClientId()) && isProxyBridgeSubscription(info.getClientId(), info.getSubscriptionName())) { addProxyNetworkSubscriptionClientId(sub, sub.getRemoteInfo().getClientId(), consumerInfo.getSubscriptionName()); } else { sub.getDurableRemoteSubs().add(new SubscriptionInfo(sub.getRemoteInfo().getClientId(), consumerInfo.getSubscriptionName())); } } addSubscription(sub); LOG.debug("{} new demand subscription: {}", configuration.getBrokerName(), sub); } } }
protected DemandSubscription doCreateDemandSubscription(ConsumerInfo info) throws IOException { DemandSubscription result = new DemandSubscription(info); result.getLocalInfo().setConsumerId(new ConsumerId(localSessionInfo.getSessionId(), consumerIdGenerator.getNextSequenceId())); if (info.getDestination().isTemporary()) { // reset the local connection Id ActiveMQTempDestination dest = (ActiveMQTempDestination) result.getLocalInfo().getDestination(); dest.setConnectionId(localConnectionInfo.getConnectionId().toString()); } if (configuration.isDecreaseNetworkConsumerPriority()) { byte priority = (byte) configuration.getConsumerPriorityBase(); if (info.getBrokerPath() != null && info.getBrokerPath().length > 1) { // The longer the path to the consumer, the less it's consumer priority. priority -= info.getBrokerPath().length + 1; } result.getLocalInfo().setPriority(priority); LOG.debug("{} using priority: {} for subscription: {}", new Object[]{configuration.getBrokerName(), priority, info}); } configureDemandSubscription(info, result); return result; }
protected void removeDemandSubscription(ConsumerId id) throws IOException { DemandSubscription sub = subscriptionMapByRemoteId.remove(id); LOG.debug("{} remove request on {} from {}, consumer id: {}, matching sub: {}", new Object[]{ configuration.getBrokerName(), localBroker, remoteBrokerName, id, sub }); if (sub != null) { removeSubscription(sub); LOG.debug("{} removed sub on {} from {}: {}", new Object[]{ configuration.getBrokerName(), localBroker, remoteBrokerName, sub.getRemoteInfo() }); } }
protected String getSubscriberName(ActiveMQDestination dest) { String subscriberName = DURABLE_SUB_PREFIX + configuration.getBrokerName() + "_" + dest.getPhysicalName(); return subscriberName; }
protected void removeDemandSubscription(ConsumerId id) throws IOException { DemandSubscription sub = subscriptionMapByRemoteId.remove(id); if (LOG.isDebugEnabled()) { LOG.debug(configuration.getBrokerName() + " remove request on " + localBroker + " from " + remoteBrokerName + " , consumer id: " + id + ", matching sub: " + sub); } if (sub != null) { removeSubscription(sub); if (LOG.isDebugEnabled()) { LOG.debug(configuration.getBrokerName() + " removed sub on " + localBroker + " from " + remoteBrokerName + " : " + sub.getRemoteInfo()); } } }