/** * @return whether or not the subscriber is durable (persistent) */ @Override public boolean isDurable() { ConsumerInfo info = getConsumerInfo(); return info != null ? info.isDurable() : false; }
private boolean isInActiveDurableSub(Subscription sub) { return (sub.getConsumerInfo().isDurable() && sub instanceof DurableTopicSubscription && !((DurableTopicSubscription) sub).isActive()); }
@Override public void removeSubscription(ConnectionContext context, Subscription sub, long lastDeliveredSequenceId) throws Exception { if (!sub.getConsumerInfo().isDurable()) { boolean removed = false; synchronized (consumers) { removed = consumers.remove(sub); } if (removed) { super.removeSubscription(context, sub, lastDeliveredSequenceId); } } sub.remove(context, this); }
temporaryTopicSubscribers.put(key, view); } else { if (info.isDurable()) { durableTopicSubscribers.put(key, view);
public static ObjectName createSubscriptionName(String brokerObjectName, String connectionClientId, ConsumerInfo info) throws MalformedObjectNameException { String objectNameStr = brokerObjectName; objectNameStr += createDestinationProperties(info.getDestination()) + ",endpoint=Consumer"; objectNameStr += ",clientId=" + JMXSupport.encodeObjectNamePart(connectionClientId); objectNameStr += ",consumerId="; if (info.isDurable()){ objectNameStr += "Durable(" + JMXSupport.encodeObjectNamePart(connectionClientId + ":" + info.getSubscriptionName()) +")"; } else { objectNameStr += JMXSupport.encodeObjectNamePart(info.getConsumerId().toString()); } return new ObjectName(objectNameStr); }
@Override public void removeConsumer(ConnectionContext context, ConsumerInfo info) throws Exception { if (info.isDurable()) { SubscriptionKey key = new SubscriptionKey(context.getClientId(), info.getSubscriptionName()); DurableTopicSubscription sub = durableSubscriptions.get(key); if (sub != null) { // deactivate only if given context is same // as what is in the sub. otherwise, during linksteal // sub will get new context, but will be removed here if (sub.getContext() == context) { sub.deactivate(keepDurableSubsActive, info.getLastDeliveredSequenceId()); } } } else { super.removeConsumer(context, info); } }
@Override public void addSubscription(ConnectionContext context, final Subscription sub) throws Exception { if (!sub.getConsumerInfo().isDurable()) { } else { for (Subscription currentSub : consumers) { if (currentSub.getConsumerInfo().isDurable()) { DurableTopicSubscription dcurrentSub = (DurableTopicSubscription) currentSub; if (dcurrentSub.getSubscriptionKey().equals(dsub.getSubscriptionKey())) {
private boolean suppressMessageDispatch(MessageDispatch md, DemandSubscription sub) throws Exception { boolean suppress = false; // for durable subs, suppression via filter leaves dangling acks so we // need to check here and allow the ack irrespective if (sub.getLocalInfo().isDurable()) { NonCachedMessageEvaluationContext messageEvalContext = new NonCachedMessageEvaluationContext(); messageEvalContext.setMessageReference(md.getMessage()); messageEvalContext.setDestination(md.getDestination()); suppress = !sub.getNetworkBridgeFilter().matches(messageEvalContext); } return suppress; }
protected Subscription createSubscription(ConnectionContext context, ConsumerInfo info) throws JMSException { if (info.isDurable()) { throw new JMSException("A durable subscription cannot be created for a temporary topic."); } try { TopicSubscription answer = new TopicSubscription(broker, context, info, usageManager); // lets configure the subscription depending on the destination ActiveMQDestination destination = info.getDestination(); if (destination != null && broker.getDestinationPolicy() != null) { PolicyEntry entry = broker.getDestinationPolicy().getEntryFor(destination); if (entry != null) { entry.configure(broker, usageManager, answer); } } answer.init(); return answer; } catch (Exception e) { LOG.error("Failed to create TopicSubscription ", e); JMSException jmsEx = new JMSException("Couldn't create TopicSubscription"); jmsEx.setLinkedException(e); throw jmsEx; } }
@Override public Subscription addConsumer(ConnectionContext context, ConsumerInfo info) throws Exception { if (info.isDurable()) { if (broker.getBrokerService().isRejectDurableConsumers()) { throw new JMSException("Durable Consumers are not allowed");
public static boolean isForcedDurable(final ConsumerInfo info, final ActiveMQDestination[] dynamicallyIncludedDestinations, final ActiveMQDestination[] staticallyIncludedDestinations) { if (info.isDurable() || info.getDestination().isQueue()) { return false; } ActiveMQDestination destination = info.getDestination(); if (AdvisorySupport.isAdvisoryTopic(destination) || destination.isTemporary() || destination.isQueue()) { return false; } ActiveMQDestination matching = findMatchingDestination(dynamicallyIncludedDestinations, destination); if (matching != null) { return isDestForcedDurable(matching); } matching = findMatchingDestination(staticallyIncludedDestinations, destination); if (matching != null) { return isDestForcedDurable(matching); } return false; }
@Override protected DemandSubscription createDemandSubscription(ConsumerInfo info) throws IOException { boolean isForcedDurable = NetworkBridgeUtils.isForcedDurable(info, dynamicallyIncludedDestinations, staticallyIncludedDestinations); if (addToAlreadyInterestedConsumers(info, isForcedDurable)) { return null; // don't want this subscription added } //add our original id to ourselves info.addNetworkConsumerId(info.getConsumerId()); ConsumerId forcedDurableId = isForcedDurable ? info.getConsumerId() : null; if(info.isDurable() || isForcedDurable) { // set the subscriber name to something reproducible info.setSubscriptionName(getSubscriberName(info.getDestination())); // and override the consumerId with something unique so that it won't // be removed if the durable subscriber (at the other end) goes away info.setConsumerId(new ConsumerId(localSessionInfo.getSessionId(), consumerIdGenerator.getNextSequenceId())); } info.setSelector(null); DemandSubscription demandSubscription = doCreateDemandSubscription(info); if (forcedDurableId != null) { demandSubscription.addForcedDurableConsumer(forcedDurableId); forcedDurableRemoteId.add(forcedDurableId); } return demandSubscription; }
protected void configureDemandSubscription(ConsumerInfo info, DemandSubscription sub) throws IOException { if (AdvisorySupport.isConsumerAdvisoryTopic(info.getDestination()) || AdvisorySupport.isVirtualDestinationConsumerAdvisoryTopic(info.getDestination())) { sub.getLocalInfo().setDispatchAsync(true); } else { sub.getLocalInfo().setDispatchAsync(configuration.isDispatchAsync()); } configureConsumerPrefetch(sub.getLocalInfo()); subscriptionMapByLocalId.put(sub.getLocalInfo().getConsumerId(), sub); subscriptionMapByRemoteId.put(sub.getRemoteInfo().getConsumerId(), sub); sub.setNetworkBridgeFilter(createNetworkBridgeFilter(info)); if (!info.isDurable()) { // This works for now since we use a VM connection to the local broker. // may need to change if we ever subscribe to a remote broker. sub.getLocalInfo().setAdditionalPredicate(sub.getNetworkBridgeFilter()); } else { sub.setLocalDurableSubscriber(new SubscriptionInfo(info.getClientId(), info.getSubscriptionName())); } }
ActiveMQDestination destination = info.getDestination(); if (info.isDurable()) { if (AdvisorySupport.isAdvisoryTopic(info.getDestination())) { throw new JMSException("Cannot create a durable subscription for an advisory Topic");
}); if (!info.isDurable()) { ds.add(info.getConsumerId()); if (isForcedDurable) {
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); } } }
} else { String userName = brokerService.isPopulateUserNameInMBeans() ? context.getUserName() : null; if (sub.getConsumerInfo().isDurable()) { view = new DurableSubscriptionView(this, brokerService, context.getClientId(), userName, sub); } else {
/** * @return whether or not the subscriber is durable (persistent) */ @Override public boolean isDurable() { ConsumerInfo info = getConsumerInfo(); return info != null ? info.isDurable() : false; }
public static ObjectName createSubscriptionName(String brokerObjectName, String connectionClientId, ConsumerInfo info) throws MalformedObjectNameException { String objectNameStr = brokerObjectName; objectNameStr += createDestinationProperties(info.getDestination()) + ",endpoint=Consumer"; objectNameStr += ",clientId=" + JMXSupport.encodeObjectNamePart(connectionClientId); objectNameStr += ",consumerId="; if (info.isDurable()){ objectNameStr += "Durable(" + JMXSupport.encodeObjectNamePart(connectionClientId + ":" + info.getSubscriptionName()) +")"; } else { objectNameStr += JMXSupport.encodeObjectNamePart(info.getConsumerId().toString()); } return new ObjectName(objectNameStr); }
private boolean suppressMessageDispatch(MessageDispatch md, DemandSubscription sub) throws Exception { boolean suppress = false; // for durable subs, suppression via filter leaves dangling acks so we // need to check here and allow the ack irrespective if (sub.getLocalInfo().isDurable()) { NonCachedMessageEvaluationContext messageEvalContext = new NonCachedMessageEvaluationContext(); messageEvalContext.setMessageReference(md.getMessage()); messageEvalContext.setDestination(md.getDestination()); suppress = !sub.getNetworkBridgeFilter().matches(messageEvalContext); } return suppress; }