protected void sendSubscriptions() throws Throwable { for (DestinationType desType : _consumerList.keySet()) { Map<String, BrokerAsyncConsumer> subscriptions = _consumerList.get(desType); for (BrokerAsyncConsumer aconsumer : subscriptions.values()) { NetSubscribe subscription = aconsumer.getSubscription(); NetAction netAction = new NetAction(ActionType.SUBSCRIBE); netAction.setSubscribeMessage(subscription); NetMessage msg = buildMessage(netAction, subscription.getHeaders()); getNetHandler().sendMessage(msg); log.info("Reconnected async consumer for '{}'", subscription.getDestination()); } } synchronized (_syncSubscriptions) { for (String queueName : _syncSubscriptions.keySet()) { getNetHandler().sendMessage(_syncSubscriptions.get(queueName)); } } }
/** * Create a new asynchronous subscription. * * @param subscribe A subscription message. * @param listener A BrokerListener instance. * @param acceptRequest An AcceptRequest object used handling Accept messages. */ public void addAsyncConsumer( NetSubscribe subscribe, BrokerListener listener, AcceptRequest acceptRequest) throws Throwable { if ((subscribe != null) && (StringUtils.isNotBlank(subscribe.getDestination()))) { Map<String, BrokerAsyncConsumer> subscriptions = _consumerList.get( subscribe.getDestinationType().equals(DestinationType.TOPIC) ? DestinationType.TOPIC : DestinationType.QUEUE); BrokerAsyncConsumer previous = subscriptions.put( subscribe.getDestination(), new BrokerAsyncConsumer(subscribe, listener)); if (previous != null) { // A subscription for the given destination already existed. Set it again and subscriptions.put(subscribe.getDestination(), previous); throw new IllegalStateException("A listener for that Destination already exists"); } if (acceptRequest != null) { subscribe.setActionId(acceptRequest.getActionId()); PendingAcceptRequestsManager.addAcceptRequest(acceptRequest); } NetAction netAction = new NetAction(ActionType.SUBSCRIBE); netAction.setSubscribeMessage(subscribe); NetMessage msg = buildMessage(netAction, subscribe.getHeaders()); getNetHandler().sendMessage(msg); log.info("Created new async consumer for '{}'", subscribe.getDestination()); } else { throw new IllegalArgumentException("Mal-formed Notification request"); } }