@Override protected void doDeclares() { AmqpAdmin admin = getAdmin(); if (admin != null) { if (admin.getQueueProperties(this.queue.getName()) == null) { admin.declareQueue(this.queue); } if (this.exchange != null) { admin.declareExchange(this.exchange); } if (this.binding != null) { admin.declareBinding(this.binding); } } }
@PostConstruct public void init() { DirectExchange exchange = new DirectExchange(PAY_NOTIFY_EXCHANGE_NAME); exchange.setDelayed(true); Queue queue = new Queue(PAY_NOTIFY_QUEUE_NAME); Binding binding = BindingBuilder.bind(queue).to(exchange).withQueueName(); amqpAdmin.declareExchange(exchange); amqpAdmin.declareQueue(queue); amqpAdmin.declareBinding(binding); }
@Override protected void doDeclares() { AmqpAdmin admin = getAdmin(); if (admin != null && this.queue != null && admin.getQueueProperties(this.queue.getName()) == null) { admin.declareQueue(this.queue); } }
@Bean public Queue hystrixStreamQueue() { Map<String, Object> args = new HashMap<>(); args.put("x-message-ttl", 60000); //TODO: configure TTL Queue queue = new Queue(Constants.HYSTRIX_STREAM_NAME, false, false, false, args); amqpAdmin.declareQueue(queue); amqpAdmin.declareBinding(BindingBuilder.bind(queue).to(hystrixStreamExchange()).with("")); return queue; }
private void setNotifyExchange() { DirectExchange notifyExchange = new DirectExchange(NOTIFY_EXCHANGE,true,false); amqpAdmin.declareExchange(notifyExchange); this.notifyExchange = notifyExchange; }
/** * An example application that only configures the AMQP broker */ public static void main(String[] args) throws Exception { ApplicationContext context = new ClassPathXmlApplicationContext("rabbitConfiguration.xml"); AmqpAdmin amqpAdmin = context.getBean(AmqpAdmin.class); Queue helloWorldQueue = new Queue("hello.world.queue"); amqpAdmin.declareQueue(helloWorldQueue); }
@Bean public Binding binding(Exchange exchange, Queue queue) { Binding binding = BindingBuilder.bind(queue).to(exchange).with("*").noargs(); admin.declareBinding(binding); return binding; }
private void attemptDeclarations(AmqpAdmin amqpAdmin) { ApplicationContext context = this.getApplicationContext(); if (context != null) { Set<String> queueNames = getQueueNamesAsSet(); Map<String, Queue> queueBeans = context.getBeansOfType(Queue.class); for (Entry<String, Queue> entry : queueBeans.entrySet()) { Queue queue = entry.getValue(); if (isMismatchedQueuesFatal() || (queueNames.contains(queue.getName()) && amqpAdmin.getQueueProperties(queue.getName()) == null)) { if (logger.isDebugEnabled()) { logger.debug("Redeclaring context exchanges, queues, bindings."); } amqpAdmin.initialize(); break; } } } }
Properties queueProperties = checkAdmin.getQueueProperties(queue); if (queueProperties == null && isMissingQueuesFatal()) { throw new IllegalStateException("At least one of the configured queues is missing");
protected void checkMismatchedQueues() { if (this.mismatchedQueuesFatal && this.amqpAdmin != null) { try { this.amqpAdmin.initialize(); } catch (AmqpConnectException e) { logger.info("Broker not available; cannot check queue declarations"); } catch (AmqpIOException e) { if (RabbitUtils.isMismatchedQueueArgs(e)) { throw new FatalListenerStartupException("Mismatched queues", e); } else { logger.info("Failed to get connection during start(): " + e); } } } else { try { Connection connection = getConnectionFactory().createConnection(); // NOSONAR if (connection != null) { connection.close(); } } catch (Exception e) { logger.info("Broker not available; cannot force queue declarations during start"); } } }
@Autowired public void defineExchange(AmqpAdmin admin) { Queue tradesQueue = QueueBuilder.durable("trades").build(); Exchange tradingExchange = ExchangeBuilder.topicExchange("trading-engine-events").build(); admin.declareExchange(tradingExchange); admin.declareQueue(tradesQueue); admin.declareBinding(BindingBuilder.bind(tradesQueue) .to(tradingExchange) .with("#") .noargs()); }
private void sendNoftify(String queueName, Object msg) { Queue queue = new Queue(queueName, true, false, true); amqpAdmin.declareQueue(queue); Binding binding = BindingBuilder.bind(queue).to(notifyExchange).withQueueName(); amqpAdmin.declareBinding(binding); amqpTemplate.convertAndSend(notifyExchange.getName(),queueName, msg); }
@Bean public DirectExchange hystrixStreamExchange() { DirectExchange exchange = new DirectExchange(Constants.HYSTRIX_STREAM_NAME); amqpAdmin.declareExchange(exchange); return exchange; }
@Override protected void doDeclares() { AmqpAdmin admin = getAdmin(); if (admin != null && admin.getQueueProperties(this.queue.getName()) == null) { admin.declareQueue(this.queue); } }
@Bean public Queue queue() { Queue queue = QueueBuilder.durable("OrderEvents").build(); admin.declareQueue(queue); return queue; }
@Bean public Binding binding(Exchange exchange, Queue queue) { Binding binding = BindingBuilder.bind(queue).to(exchange).with("*").noargs(); admin.declareBinding(binding); return binding; } }
private void attemptDeclarations(AmqpAdmin amqpAdmin) { ApplicationContext context = this.getApplicationContext(); if (context != null) { Set<String> queueNames = getQueueNamesAsSet(); Map<String, Queue> queueBeans = context.getBeansOfType(Queue.class); for (Entry<String, Queue> entry : queueBeans.entrySet()) { Queue queue = entry.getValue(); if (isMismatchedQueuesFatal() || (queueNames.contains(queue.getName()) && amqpAdmin.getQueueProperties(queue.getName()) == null)) { if (logger.isDebugEnabled()) { logger.debug("Redeclaring context exchanges, queues, bindings."); } amqpAdmin.initialize(); break; } } } }
Properties queueProperties = checkAdmin.getQueueProperties(queue); if (queueProperties == null && isMissingQueuesFatal()) { throw new IllegalStateException("At least one of the configured queues is missing");
protected void checkMismatchedQueues() { if (this.mismatchedQueuesFatal && this.amqpAdmin != null) { try { this.amqpAdmin.initialize(); } catch (AmqpConnectException e) { logger.info("Broker not available; cannot check queue declarations"); } catch (AmqpIOException e) { if (RabbitUtils.isMismatchedQueueArgs(e)) { throw new FatalListenerStartupException("Mismatched queues", e); } else { logger.info("Failed to get connection during start(): " + e); } } } else { try { Connection connection = getConnectionFactory().createConnection(); // NOSONAR if (connection != null) { connection.close(); } } catch (Exception e) { logger.info("Broker not available; cannot force queue declarations during start"); } } }
@Override protected void doDeclares() { AmqpAdmin admin = getAdmin(); if (admin != null) { if (admin.getQueueProperties(this.queue.getName()) == null) { admin.declareQueue(this.queue); } if (this.exchange != null) { admin.declareExchange(this.exchange); } if (this.binding != null) { admin.declareBinding(this.binding); } } }