@Bean public DirectExchange exchange() { return new DirectExchange("tut.rpc"); }
@Scheduled(fixedDelay = 1000, initialDelay = 500) public void send() { System.out.println(" [x] Requesting fib(" + start + ")"); Integer response = (Integer) template.convertSendAndReceive(exchange.getName(), "rpc", start++); System.out.println(" [.] Got '" + response + "'"); }
@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); }
@Test public void exchangeBinding() { DirectExchange directExchange = new DirectExchange("d"); FanoutExchange fanoutExchange = new FanoutExchange("f"); Binding binding = BindingBuilder.bind(directExchange).to(fanoutExchange); assertNotNull(binding); assertEquals(fanoutExchange.getName(), binding.getExchange()); assertEquals(Binding.DestinationType.EXCHANGE, binding.getDestinationType()); assertEquals(directExchange.getName(), binding.getDestination()); assertEquals("", binding.getRoutingKey()); }
@Bean(name = "Exchange_B") DirectExchange receiverExchange() { DirectExchange exchange = new DirectExchange("Exchange_B", true, false); exchange.setAdminsThatShouldDeclare(amqpAdmin()); return exchange; }
@Test public void testDeclareDelayedExchange() throws Exception { DirectExchange exchange = new DirectExchange("test.delayed.exchange"); exchange.setDelayed(true); Queue queue = new Queue(UUID.randomUUID().toString(), true, false, false); String exchangeName = exchange.getName(); Binding binding = new Binding(queue.getName(), DestinationType.QUEUE, exchangeName, queue.getName(), null);
@Bean public Exchange exchange() throws IOException { DirectExchange exchange = new DirectExchange("bar"); exchange.setAdminsThatShouldDeclare(admin1()); exchange.setInternal(true); return exchange; }
@Bean public DirectExchange internal() { DirectExchange directExchange = new DirectExchange("auto.internal", true, true); directExchange.setInternal(true); return directExchange; }
queue.setShouldDeclare(false); context.getBeanFactory().registerSingleton("foo", queue); DirectExchange exchange = new DirectExchange("bar"); exchange.setShouldDeclare(false); context.getBeanFactory().registerSingleton("bar", exchange); Binding binding = new Binding("foo", DestinationType.QUEUE, "bar", "foo", null);
@Test public void testAliasDirectExchange() throws Exception { DirectExchange exchange = beanFactory.getBean("alias", DirectExchange.class); assertNotNull(exchange); assertEquals("direct-alias", exchange.getName()); assertTrue(exchange.isDurable()); assertFalse(exchange.isAutoDelete()); }
@Test public void testDirectExchange() throws Exception { DirectExchange exchange = beanFactory.getBean("direct", DirectExchange.class); assertNotNull(exchange); assertEquals("direct", exchange.getName()); assertTrue(exchange.isDurable()); assertFalse(exchange.isAutoDelete()); assertFalse(exchange.shouldDeclare()); assertEquals(2, exchange.getDeclaringAdmins().size()); Binding binding = beanFactory.getBean("org.springframework.amqp.rabbit.config.BindingFactoryBean#0", Binding.class); assertFalse(binding.shouldDeclare()); assertEquals(2, binding.getDeclaringAdmins().size()); Map<String, Object> arguments = binding.getArguments(); assertNotNull(arguments); assertEquals(1, arguments.size()); assertTrue(arguments.containsKey("x-match")); assertEquals("any", arguments.get("x-match")); }
@Test public void testDirectExchangeWithArguments() throws Exception { DirectExchange exchange = beanFactory.getBean("direct-arguments", DirectExchange.class); assertNotNull(exchange); assertEquals("direct-arguments", exchange.getName()); assertEquals("bar", exchange.getArguments().get("foo")); }
@Test public void directBinding() { DirectExchange directExchange = new DirectExchange("d"); String routingKey = "r"; Binding binding = BindingBuilder.bind(queue).to(directExchange).with(routingKey); assertNotNull(binding); assertEquals(directExchange.getName(), binding.getExchange()); assertEquals(Binding.DestinationType.QUEUE, binding.getDestinationType()); assertEquals(queue.getName(), binding.getDestination()); assertEquals(routingKey, binding.getRoutingKey()); }
queue.setAdminsThatShouldDeclare(admin); context.getBeanFactory().registerSingleton("foo", queue); DirectExchange exchange = new DirectExchange("bar"); exchange.setAdminsThatShouldDeclare(admin); context.getBeanFactory().registerSingleton("bar", exchange); Binding binding = new Binding("foo", DestinationType.QUEUE, "bar", "foo", null);
@Test public void testDirectExchangeOverride() throws Exception { DirectExchange exchange = beanFactory.getBean("direct-override", DirectExchange.class); assertNotNull(exchange); assertEquals("direct-override", exchange.getName()); assertFalse(exchange.isDurable()); assertTrue(exchange.isAutoDelete()); }
@Test public void testDirectExchangeWithReferencedArguments() throws Exception { DirectExchange exchange = beanFactory.getBean("direct-ref-arguments", DirectExchange.class); assertNotNull(exchange); assertEquals("direct-ref-arguments", exchange.getName()); assertEquals("bar", exchange.getArguments().get("foo")); }
@Bean public DirectExchange direct() { return new DirectExchange("tut.direct"); }
@Test public void directBindingWithQueueName() { DirectExchange directExchange = new DirectExchange("d"); Binding binding = BindingBuilder.bind(queue).to(directExchange).withQueueName(); assertNotNull(binding); assertEquals(directExchange.getName(), binding.getExchange()); assertEquals(Binding.DestinationType.QUEUE, binding.getDestinationType()); assertEquals(queue.getName(), binding.getDestination()); assertEquals(queue.getName(), binding.getRoutingKey()); }
queue.setAdminsThatShouldDeclare(other); context.getBeanFactory().registerSingleton("foo", queue); DirectExchange exchange = new DirectExchange("bar"); exchange.setAdminsThatShouldDeclare(other); context.getBeanFactory().registerSingleton("bar", exchange); Binding binding = new Binding("foo", DestinationType.QUEUE, "bar", "foo", null);
@Scheduled(fixedDelay = 1000, initialDelay = 500) public void send() { StringBuilder builder = new StringBuilder("Hello to "); if (this.index.incrementAndGet() == 3) { this.index.set(0); } String key = keys[this.index.get()]; builder.append(key).append(' '); builder.append(this.count.incrementAndGet()); String message = builder.toString(); template.convertAndSend(direct.getName(), key, message); System.out.println(" [x] Sent '" + message + "'"); }