Refine search
@Scheduled(fixedDelay = 1000, initialDelay = 500) public void send() { String message = "Hello World!"; this.template.convertAndSend(queue.getName(), message); System.out.println(" [x] Sent '" + message + "'"); }
@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 public void addQueue(String vhost, Queue queue) { QueueInfo info = new QueueInfo(); info.setArguments(queue.getArguments()); info.setAutoDelete(queue.isAutoDelete()); info.setDurable(queue.isDurable()); info.setExclusive(queue.isExclusive()); this.rabbitClient.declareQueue(vhost, queue.getName(), info); }
@Test public void testReferenceArgumentsQueue() throws Exception { Queue queue = beanFactory.getBean("refArguments", Queue.class); assertNotNull(queue); assertEquals("bar", queue.getArguments().get("foo")); assertEquals(200L, queue.getArguments().get("x-message-ttl")); assertEquals("all", queue.getArguments().get("x-ha-policy")); }
@Test public void testConnect() throws Exception { RabbitAdmin admin = new RabbitAdmin(this.lqcf); Queue queue = new Queue(UUID.randomUUID().toString(), false, false, true); admin.declareQueue(queue); ConnectionFactory targetConnectionFactory = this.lqcf.getTargetConnectionFactory("[" + queue.getName() + "]"); RabbitTemplate template = new RabbitTemplate(targetConnectionFactory); template.convertAndSend("", queue.getName(), "foo"); assertEquals("foo", template.receiveAndConvert(queue.getName())); admin.deleteQueue(queue.getName()); }
/** * Provide a Queue name to be used. If this is not provided, * the Queue's name will be the same as the channel name. * @param queueName The queue name. */ public void setQueueName(String queueName) { this.queue = new Queue(queueName); }
@Test public void testQueue() throws Exception { Queue queue = beanFactory.getBean("foo", Queue.class); assertNotNull(queue); assertEquals("foo", queue.getName()); assertTrue(queue.isDurable()); assertFalse(queue.isAutoDelete()); assertFalse(queue.isExclusive()); }
@Test public void testArgumentsQueue() throws Exception { Queue queue = beanFactory.getBean("arguments", Queue.class); assertNotNull(queue); assertEquals("bar", queue.getArguments().get("foo")); assertEquals(100L, queue.getArguments().get("x-message-ttl")); assertEquals("all", queue.getArguments().get("x-ha-policy")); }
@Bean public IntegrationFlow amqpFlow(ConnectionFactory rabbitConnectionFactory, AmqpTemplate amqpTemplate) { return IntegrationFlows .from(Amqp.inboundGateway(rabbitConnectionFactory, amqpTemplate, queue()) .id("amqpInboundGateway") .configureContainer(c -> c .id("amqpInboundGatewayContainer") .recoveryInterval(5000) .concurrentConsumers(1)) .defaultReplyTo(defaultReplyTo().getName())) .transform("hello "::concat) .transform(String.class, String::toUpperCase) .get(); }
@Test public void testQueueDeclareBad() { this.rabbitAdmin.setIgnoreDeclarationExceptions(true); Queue queue = new AnonymousQueue(); assertEquals(queue.getName(), this.rabbitAdmin.declareQueue(queue)); queue = new Queue(queue.getName()); assertNull(this.rabbitAdmin.declareQueue(queue)); this.rabbitAdmin.deleteQueue(queue.getName()); }
/** * Provide an explicitly configured queue name. If this is not provided, then a Queue will be created * implicitly with the channelName as its name. The implicit creation will require that either an AmqpAdmin * instance has been provided or that the configured AmqpTemplate is an instance of RabbitTemplate. * @param queueName The queue name. */ public void setQueueName(String queueName) { this.queue = new Queue(queueName); }
@Scheduled(fixedDelay = 1000, initialDelay = 500) public void send() { StringBuilder builder = new StringBuilder("Hello"); if (dots.getAndIncrement() == 3) { dots.set(1); } for (int i = 0; i < dots.get(); i++) { builder.append('.'); } builder.append(count.incrementAndGet()); String message = builder.toString(); template.convertAndSend(queue.getName(), message); System.out.println(" [x] Sent '" + message + "'"); }