@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 + "'"); }
@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 + "'"); }
DirectExchangeRoutingKeyConfigurer(DestinationConfigurer destination, DirectExchange exchange) { super(destination, exchange.getName()); }
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); }
/** * @return Rabbit template with fixed reply queue, no reply container, no receive timeout. */ @Bean public RabbitTemplate fixedReplyQRabbitTemplateNoReplyContainer() { RabbitTemplate template = new RabbitTemplate(rabbitConnectionFactory()); template.setExchange(ex().getName()); template.setRoutingKey("testNoContainer"); template.setReplyAddress(replyExchange().getName() + "/" + replyQueue().getName()); return template; }
/** * @return Rabbit template with fixed reply queue. */ @Bean public RabbitTemplate fixedReplyQRabbitTemplate() { RabbitTemplate template = new RabbitTemplate(rabbitConnectionFactory()); template.setExchange(ex().getName()); template.setRoutingKey("test"); template.setReplyAddress(replyExchange().getName() + "/" + replyQueue().getName()); return template; }
@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 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")); }
/** * @return Rabbit template with incorrect fixed reply queue. */ @Bean public RabbitTemplate fixedReplyQRabbitTemplateWrongQueue() { RabbitTemplate template = new RabbitTemplate(rabbitConnectionFactory()); template.setExchange(ex().getName()); template.setRoutingKey("test"); template.setReplyAddress(requestQueue().getName()); return template; }
/** * @return Rabbit template with fixed reply queue and small timeout. */ @Bean public RabbitTemplate fixedReplyQRabbitTemplate() { RabbitTemplate template = new RabbitTemplate(rabbitConnectionFactory()); template.setExchange(ex().getName()); template.setRoutingKey("dlx.reply.test"); template.setReplyAddress(replyQueue().getName()); template.setReplyTimeout(1); return template; }
@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 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 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")); }
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);
@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()); }
@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()); }
@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()); }