final protected DemandSubscription createDemandSubscription(ActiveMQDestination destination, final String subscriptionName) { ConsumerInfo info = new ConsumerInfo(); info.setNetworkSubscription(true); info.setDestination(destination); if (subscriptionName != null) { info.setSubscriptionName(subscriptionName); } // Indicate that this subscription is being made on behalf of the remote broker. info.setBrokerPath(new BrokerId[]{remoteBrokerId}); // the remote info held by the DemandSubscription holds the original // consumerId, the local info get's overwritten info.setConsumerId(new ConsumerId(localSessionInfo.getSessionId(), consumerIdGenerator.getNextSequenceId())); DemandSubscription result = null; try { result = createDemandSubscription(info); } catch (IOException e) { LOG.error("Failed to create DemandSubscription ", e); } return result; }
@Override public void slowConsumer(ConnectionContext context, Destination destination, Subscription subs) { if (isLogAll() || isLogConsumerEvents() || isLogInternalEvents()) { LOG.info("Detected slow consumer on {}", destination.getName()); StringBuffer buf = new StringBuffer("Connection("); buf.append(subs.getConsumerInfo().getConsumerId().getConnectionId()); buf.append(") Session("); buf.append(subs.getConsumerInfo().getConsumerId().getSessionId()); buf.append(")"); LOG.info(buf.toString()); } super.slowConsumer(context, destination, subs); }
public TransportConnectionState lookupConnectionState(ConsumerId id) { TransportConnectionState cs = lookupConnectionState(id.getConnectionId()); if (cs == null) { throw new IllegalStateException( "Cannot lookup a consumer from a connection that had not been registered: " + id.getParentId().getParentId()); } return cs; }
public ConsumerId(ConsumerId id) { this.connectionId = id.getConnectionId(); this.sessionId = id.getSessionId(); this.value = id.getValue(); }
/** * Un-marshal an object instance from the data input stream * * @param o the object to un-marshal * @param dataIn the data input stream to build the object from * @throws IOException */ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn) throws IOException { super.looseUnmarshal(wireFormat, o, dataIn); ConsumerId info = (ConsumerId)o; info.setConnectionId(looseUnmarshalString(dataIn)); info.setSessionId(looseUnmarshalLong(wireFormat, dataIn)); info.setValue(looseUnmarshalLong(wireFormat, dataIn)); }
SessionId sessionId = new SessionId(info.getConnectionId(), -1); ConsumerInfo info = new ConsumerInfo(new ConsumerId(sessionId, consumerIdGenerator.getNextSequenceId())); info.setDestination(ActiveMQMessageTransformation.transformDestination(topic)); info.setSubscriptionName(subscriptionName); info.setSelector(messageSelector); info.setPrefetchSize(maxMessages); if (info.getDestination().getOptions() != null) { Map<String, String> options = new HashMap<>(info.getDestination().getOptions()); IntrospectionSupport.setProperties(this.info, options, "consumer.");
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; }
public TopicSubscription(Broker broker,ConnectionContext context, ConsumerInfo info, SystemUsage usageManager) throws Exception { super(broker, context, info); this.usageManager = usageManager; String matchedName = "TopicSubscription:" + CURSOR_NAME_COUNTER.getAndIncrement() + "[" + info.getConsumerId().toString() + "]"; if (info.getDestination().isTemporary() || broker.getTempDataStore()==null ) { this.matched = new VMPendingMessageCursor(false); } else { this.matched = new FilePendingMessageCursor(broker,matchedName,false); } this.scheduler = broker.getScheduler(); }
@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; }
@Override public ObjectName createDurableSubscriber(String clientId, String subscriberName, String topicName, String selector) throws Exception { ConnectionContext context = getConnectionContext(); context.setBroker(safeGetBroker()); context.setClientId(clientId); ConsumerInfo info = new ConsumerInfo(); ConsumerId consumerId = new ConsumerId(); consumerId.setConnectionId(clientId); consumerId.setSessionId(sessionIdCounter.incrementAndGet()); consumerId.setValue(0); info.setConsumerId(consumerId); info.setDestination(new ActiveMQTopic(topicName)); info.setSubscriptionName(subscriberName); info.setSelector(selector); Subscription subscription = safeGetBroker().addConsumer(context, info); safeGetBroker().removeConsumer(context, info); if (subscription != null) { return subscription.getObjectName(); } return null; }
Set<Subscription> dupChecker = new HashSet<Subscription>(rc); TopicMessageStore store = (TopicMessageStore)dest.getMessageStore(); ConsumerInfo consumerInfo = createInactiveConsumerInfo(info); if (sub == null) { ConnectionContext c = new ConnectionContext(); c.setBroker(context.getBroker()); c.setClientId(key.getClientId()); c.setConnectionId(consumerInfo.getConsumerId().getParentId().getParentId()); sub = (DurableTopicSubscription)createSubscription(c, consumerInfo); sub.setOfflineTimestamp(System.currentTimeMillis()); dest.addSubscription(context, sub); if (sub.matches(dest.getActiveMQDestination())) { rc.add(sub); dest.addSubscription(context, sub);
if (brokerConsumerDests.get(pair) == null) { ConnectionId connectionId = new ConnectionId(connectionIdGenerator.generateId()); SessionId sessionId = new SessionId(connectionId, sessionIdGenerator.getNextSequenceId()); ConsumerId consumerId = new ConsumerId(sessionId, consumerIdGenerator.getNextSequenceId()); info = new ConsumerInfo(consumerId); ActiveMQTopic topic = AdvisorySupport.getVirtualDestinationConsumerAdvisoryTopic(info.getDestination()); fireConsumerAdvisory(context, info.getDestination(), topic, info);
public ObjectName registerSubscription(ConnectionContext context, Subscription sub) { String connectionClientId = context.getClientId(); SubscriptionKey key = new SubscriptionKey(context.getClientId(), sub.getConsumerInfo().getSubscriptionName()); try { ObjectName objectName = BrokerMBeanSupport.createSubscriptionName(brokerObjectName, connectionClientId, sub.getConsumerInfo()); SubscriptionView view; if (sub.getConsumerInfo().getConsumerId().getConnectionId().equals("OFFLINE")) { info.setClientId(context.getClientId()); info.setSubscriptionName(sub.getConsumerInfo().getSubscriptionName()); info.setDestination(sub.getConsumerInfo().getDestination()); info.setSelector(sub.getSelector());
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 addSubscription(ConnectionContext context, Subscription sub) throws Exception { // Only consumers on the same connection can consume from // the temporary destination // However, we could have failed over - and we do this // check client side anyways .... if (!context.isFaultTolerant() && (!context.isNetworkConnection() && !tempDest .getConnectionId().equals( sub.getConsumerInfo().getConsumerId() .getConnectionId()))) { tempDest.setConnectionId(sub.getConsumerInfo().getConsumerId().getConnectionId()); LOG.debug("changed ownership of {} to {}", this, tempDest.getConnectionId()); } super.addSubscription(context, sub); }
final protected DemandSubscription createDemandSubscription(ActiveMQDestination destination) { ConsumerInfo info = new ConsumerInfo(); info.setDestination(destination); // the remote info held by the DemandSubscription holds the original // consumerId, // the local info get's overwritten info.setConsumerId(new ConsumerId(localSessionInfo.getSessionId(), consumerIdGenerator.getNextSequenceId())); DemandSubscription result = null; try { result = createDemandSubscription(info); } catch (IOException e) { LOG.error("Failed to create DemandSubscription ", e); } if (result != null) { result.getLocalInfo().setPriority(ConsumerInfo.NETWORK_CONSUMER_PRIORITY); } return result; }
@Override public Response processAddConsumer(ConsumerInfo info) { if (info != null) { SessionId sessionId = info.getConsumerId().getParentId(); if (sessionId != null) { ConnectionId connectionId = sessionId.getParentId(); if (connectionId != null) { ConnectionState cs = connectionStates.get(connectionId); if (cs != null) { SessionState ss = cs.getSessionState(sessionId); if (ss != null) { ss.addConsumer(info); if (info.isResponseRequired()) { return new Tracked(new ExceptionResponseCheckAction(info)); } } } } } } return TRACKED_RESPONSE_MARKER; }
@Override public Response processAddConsumer(ConsumerInfo info) throws Exception { SessionId sessionId = info.getConsumerId().getParentId(); ConnectionId connectionId = sessionId.getParentId(); TransportConnectionState cs = lookupConnectionState(connectionId); if (cs == null) { if (!ss.getConsumerIds().contains(info.getConsumerId())) { ActiveMQDestination destination = info.getDestination(); if (destination != null && !AdvisorySupport.isAdvisoryTopic(destination)) { if (getConsumerCount(connectionId) >= connector.getMaximumConsumersAllowedPerConnection()){
/** * @return a newly created ConsumedId unique to this connection session instance. */ private ConsumerId createConsumerId() { return new ConsumerId(connectionSessionId, consumerIdGenerator.getNextSequenceId()); }
@Override public void slowConsumer(ConnectionContext context, Destination destination, Subscription subs) { super.slowConsumer(context, destination, subs); try { if (!AdvisorySupport.isAdvisoryTopic(destination.getActiveMQDestination())) { ActiveMQTopic topic = AdvisorySupport.getSlowConsumerAdvisoryTopic(destination.getActiveMQDestination()); ActiveMQMessage advisoryMessage = new ActiveMQMessage(); advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_CONSUMER_ID, subs.getConsumerInfo().getConsumerId().toString()); fireAdvisory(context, topic, subs.getConsumerInfo(), null, advisoryMessage); } } catch (Exception e) { handleFireFailure("slow consumer", e); } }