private String queueName(final CollectorConfiguration collector) { final Integer hash = Objects.hash( collector.getBrokerHost(), collector.getBrokerPort(), collector.getVirtualHost(), collector.getExchangeName()); return String.format("%s.collector.hash%08X",this.name,hash); }
private void bindQueue(final String queueName) throws ControllerException { try { this.manager.channel().queueBind(queueName,this.collector.getExchangeName(),Notifications.ROUTING_KEY_PATTERN); this.cleaners.push(CleanerFactory.queueUnbind(this.collector.getExchangeName(),queueName,Notifications.ROUTING_KEY_PATTERN)); } catch (final IOException e) { throw new ControllerException(this.collector.getBrokerHost(),this.collector.getBrokerPort(),this.collector.getVirtualHost(),"Could not bind queue '"+queueName+"' to exchange '"+this.collector.getExchangeName()+"' using routing key '"+Notifications.ROUTING_KEY_PATTERN+"'",e); } }
void publishEvent(final String event, final String eventType) throws ControllerException { this.write.lock(); try { checkState(this.manager.isConnected(),"Not connected"); final Channel aChannel = this.manager.currentChannel(); aChannel.addReturnListener(new LoggingReturnListener()); publish( aChannel, this.collector.getExchangeName(), Notifications.routingKey(eventType), event); } finally { this.write.unlock(); } }
/** * The a durable topic exchange is always declared */ private void declareExchange() throws ControllerException { try { this.manager.channel().exchangeDeclare(this.collector.getExchangeName(),EXCHANGE_TYPE,true); } catch (final IOException e) { if(!FailureAnalyzer.isExchangeDeclarationRecoverable(e)) { throw new ControllerException(this.collector.getBrokerHost(),this.collector.getBrokerPort(),this.collector.getVirtualHost(),"Could not create exchange named '"+this.collector.getExchangeName()+"'",e); } } }