org.springframework.amqp.rabbit.core.RabbitAdmin Java Examples
The following examples show how to use
org.springframework.amqp.rabbit.core.RabbitAdmin.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RabbitWithoutRabbitTemplateConfig.java From java-spring-rabbitmq with Apache License 2.0 | 6 votes |
@Bean public RabbitAdmin rabbitAdmin(Queue queue, ConnectionFactory connectionFactory) { final TopicExchange exchange = new TopicExchange("myExchange", true, false); final RabbitAdmin admin = new RabbitAdmin(connectionFactory); admin.declareQueue(queue); admin.declareExchange(exchange); admin.declareBinding(BindingBuilder.bind(queue).to(exchange).with("#")); return admin; }
Example #2
Source File: MQClient.java From zxl with Apache License 2.0 | 6 votes |
@Override public void afterPropertiesSet() throws Exception { List<RabbitAdmin> rabbitAdmins = getMqAdmins(); for (int i = 0; i < rabbitAdmins.size(); i++) { RabbitAdmin rabbitAdmin = rabbitAdmins.get(i); while (true) { if (!DEFAULT_EXCHANGE.equals(exchange)) { break; } try { rabbitAdmin.declareQueue(new Queue(routingKey, queueDurable, queueExclusive, queueAutoDelete, queueArguments)); rabbitAdmin.declareBinding(new Binding(routingKey, DestinationType.QUEUE, MQClient.DEFAULT_EXCHANGE, routingKey, bindingArguments)); break; } catch (Exception e) { LogUtil.warn(logger, "�������У�" + routingKey + "��ʧ��", e); } } } }
Example #3
Source File: EMSConfiguration.java From generic-vnfm with Apache License 2.0 | 6 votes |
@PostConstruct private void init() { log.info("Initialization of RabbitConfiguration"); emsConnectionFactory = new CachingConnectionFactory(); ((CachingConnectionFactory) emsConnectionFactory).setHost(brokerIp); ((CachingConnectionFactory) emsConnectionFactory).setPort(rabbitPort); ((CachingConnectionFactory) emsConnectionFactory).setUsername(emsRabbitUsername); ((CachingConnectionFactory) emsConnectionFactory).setPassword(emsRabbitPassword); rabbitAdmin = new RabbitAdmin(emsConnectionFactory); TopicExchange topicExchange = new TopicExchange("openbaton-exchange"); rabbitAdmin.declareExchange(topicExchange); log.info("exchange declared"); queueName_emsRegistrator = "ems." + vnfmHelper.getVnfmEndpoint() + ".register"; rabbitAdmin.declareQueue(new Queue(queueName_emsRegistrator, durable, exclusive, autodelete)); }
Example #4
Source File: RabbitBinderTests.java From spring-cloud-stream-binder-rabbit with Apache License 2.0 | 5 votes |
@Test public void testBadUserDeclarationsFatal() throws Exception { RabbitTestBinder binder = getBinder(); ConfigurableApplicationContext context = binder.getApplicationContext(); ConfigurableListableBeanFactory bf = context.getBeanFactory(); bf.registerSingleton("testBadUserDeclarationsFatal", new Queue("testBadUserDeclarationsFatal", false)); bf.registerSingleton("binder", binder); RabbitExchangeQueueProvisioner provisioner = TestUtils.getPropertyValue(binder, "binder.provisioningProvider", RabbitExchangeQueueProvisioner.class); bf.initializeBean(provisioner, "provisioner"); bf.registerSingleton("provisioner", provisioner); context.addApplicationListener(provisioner); RabbitAdmin admin = new RabbitAdmin(rabbitAvailableRule.getResource()); admin.declareQueue(new Queue("testBadUserDeclarationsFatal")); // reset the connection and configure the "user" admin to auto declare queues... rabbitAvailableRule.getResource().resetConnection(); bf.initializeBean(admin, "rabbitAdmin"); bf.registerSingleton("rabbitAdmin", admin); admin.afterPropertiesSet(); // the mis-configured queue should be fatal Binding<?> binding = null; try { binding = binder.bindConsumer("input", "baddecls", this.createBindableChannel("input", new BindingProperties()), createConsumerProperties()); fail("Expected exception"); } catch (BinderException e) { assertThat(e.getCause()).isInstanceOf(AmqpIOException.class); } finally { admin.deleteQueue("testBadUserDeclarationsFatal"); if (binding != null) { binding.unbind(); } } }
Example #5
Source File: ExceptionQueueContextConfig.java From sinavi-jfw with Apache License 2.0 | 5 votes |
/** * RabbitMQの管理操作を実行する{@link AmqpAdmin}のインスタンスを生成し、DIコンテナに登録します。 * この{@link AmqpAdmin}を利用することにより、Exchange/Queueの自動生成を行うことが可能となります。 * 自動生成する場合はSpring のBeanProfileのスコープ指定を<strong>development</strong>に指定してください。 * @return {@link RabbitAdmin}のインスタンス */ @Bean @Profile("development") public AmqpAdmin amqpAdmin() { RabbitAdmin rabbitAdmin = new RabbitAdmin(factory()); rabbitAdmin.setAutoStartup(true); return rabbitAdmin; }
Example #6
Source File: SpringIntegrationTest.java From rabbitmq-mock with Apache License 2.0 | 5 votes |
private RabbitTemplate queueAndExchangeSetup(BeanFactory context) { RabbitAdmin rabbitAdmin = context.getBean(RabbitAdmin.class); Queue queue = new Queue(QUEUE_NAME, false); rabbitAdmin.declareQueue(queue); TopicExchange exchange = new TopicExchange(EXCHANGE_NAME); rabbitAdmin.declareExchange(exchange); rabbitAdmin.declareBinding(BindingBuilder.bind(queue).to(exchange).with("test.*")); return context.getBean(RabbitTemplate.class); }
Example #7
Source File: TestQueueCleaner.java From sinavi-jfw with Apache License 2.0 | 5 votes |
public static void cleaner() { RabbitAdmin admin = new RabbitAdmin(factory()); admin.setAutoStartup(true); admin.deleteExchange("error.exchange"); admin.deleteExchange("exception.exchange"); admin.deleteQueue("recoverable.exception.messages.queue"); admin.deleteQueue("unrecoverable.exception.messages.queue"); }
Example #8
Source File: MqBeanParser.java From zxl with Apache License 2.0 | 5 votes |
protected void buildRabbitAdminBeanDefinition(String beanName, String connectionFactoryBeanName, BeanDefinitionRegistry beanDefinitionRegistry) { AbstractBeanDefinition rabbitAdminBeanDefinition = new GenericBeanDefinition(); rabbitAdminBeanDefinition.setBeanClass(RabbitAdmin.class); ConstructorArgumentValues rabbitAdminConstructorArgumentValues = new ConstructorArgumentValues(); rabbitAdminConstructorArgumentValues.addIndexedArgumentValue(0, new RuntimeBeanReference(connectionFactoryBeanName)); rabbitAdminBeanDefinition.setConstructorArgumentValues(rabbitAdminConstructorArgumentValues); beanDefinitionRegistry.registerBeanDefinition(beanName, rabbitAdminBeanDefinition); }
Example #9
Source File: MQServer.java From zxl with Apache License 2.0 | 5 votes |
protected void handleReceiveError(Exception warnException, RabbitAdmin mqAdmin) { Throwable throwable = warnException; while ((throwable = throwable.getCause()) != null) { if (throwable instanceof ShutdownSignalException && throwable.getMessage().contains(NOT_FOUND_MESSAGE)) { try { mqAdmin.declareQueue(new Queue(queueName, queueDurable, queueExclusive, queueAutoDelete, queueArguments)); mqAdmin.declareBinding(new Binding(queueName, DestinationType.QUEUE, MQClient.DEFAULT_EXCHANGE, queueName, bindingArguments)); } catch (Exception e) { } break; } } }
Example #10
Source File: RabbitMQClient.java From kkbinlog with Apache License 2.0 | 5 votes |
public synchronized static RabbitMQClient getInstance(ConnectionFactory connectionFactory) throws Exception { if (instance == null && connectionFactory != null) { instance = new RabbitMQClient(); instance.connectionFactory = connectionFactory; instance.amqpAdmin = new RabbitAdmin(connectionFactory); instance.amqpTemplate = new RabbitTemplate(connectionFactory); instance.setDataExchange(); instance.setNotifyExchange(); } return instance; }
Example #11
Source File: RabbitMqConfiguration.java From Hands-On-High-Performance-with-Spring-5 with MIT License | 5 votes |
@Bean public RabbitAdmin rabbitAdmin() { RabbitAdmin admin = new RabbitAdmin(connectionFactory()); admin.declareQueue(queue()); admin.declareExchange(exchange()); admin.declareBinding(exchangeBinding(exchange(), queue())); return admin; }
Example #12
Source File: RabbitmqFactory.java From shine-mq with Apache License 2.0 | 5 votes |
private RabbitmqFactory(MqProperties config) { Objects.requireNonNull(config, "The RabbitmqProperties is empty."); this.config = config; this.rabbit = config.getRabbit(); rabbitAdmin = new RabbitAdmin(rabbitConnectionFactory); rabbitTemplate = new RabbitTemplate(rabbitConnectionFactory); rabbitTemplate.setMessageConverter(serializerMessageConverter); if (config.getDistributed().isTransaction()) { setRabbitTemplateForDis(config); } template = new RabbitmqTemplate(this, rabbitTemplate, serializerMessageConverter); }
Example #13
Source File: AmqpReporter.java From haven-platform with Apache License 2.0 | 5 votes |
@Override public RabbitTemplate call() throws Exception { ConnectionFactory connectionFactory = connectionFactoryProvider.getObject(); Assert.notNull(connectionFactory, "connectionFactory is null"); if(exchangeFactory != null) { Exchange exchange = exchangeFactory.call(); if(exchange != null) { RabbitAdmin admin = new RabbitAdmin(connectionFactory); admin.declareExchange(exchange); } } return new RabbitTemplate(connectionFactory); }
Example #14
Source File: AmqpUtils.java From haven-platform with Apache License 2.0 | 5 votes |
/** * decalre specified excahnge * @param connectionFactory * @param exchangeType * @param exchangeName * @param durable * @param autoDelete */ public static void declareExchange(ConnectionFactory connectionFactory, String exchangeType, String exchangeName, boolean durable, boolean autoDelete) { Exchange x = createExchange(exchangeType, exchangeName, durable, autoDelete); RabbitAdmin admin = new RabbitAdmin(connectionFactory); admin.declareExchange(x); }
Example #15
Source File: LocalizedQueueConnectionFactoryIntegrationTests.java From spring-cloud-stream-binder-rabbit with Apache License 2.0 | 5 votes |
@Test public void testConnect() { 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"); assertThat(template.receiveAndConvert(queue.getName())).isEqualTo("foo"); ((CachingConnectionFactory) targetConnectionFactory).destroy(); admin.deleteQueue(queue.getName()); }
Example #16
Source File: RabbitChannelDefinitionProcessor.java From flowable-engine with Apache License 2.0 | 5 votes |
protected RabbitAdmin resolveAdmin(RabbitInboundChannelModel channelDefinition) { String rabbitAdmin = resolve(channelDefinition.getAdmin()); if (StringUtils.hasText(rabbitAdmin)) { Assert.state(this.beanFactory != null, "BeanFactory must be set to resolve RabbitAdmin by bean name"); try { return this.beanFactory.getBean(rabbitAdmin, RabbitAdmin.class); } catch (NoSuchBeanDefinitionException ex) { throw new IllegalArgumentException("Could not register rabbit listener endpoint on [" + channelDefinition + "], no " + RabbitAdmin.class.getSimpleName() + " with id '" + rabbitAdmin + "' was found in the application context", ex); } } else { return null; } }
Example #17
Source File: RabbitBinderModuleTests.java From spring-cloud-stream-binder-rabbit with Apache License 2.0 | 5 votes |
@After public void tearDown() { if (context != null) { context.close(); context = null; } RabbitAdmin admin = new RabbitAdmin(rabbitTestSupport.getResource()); admin.deleteExchange("input"); admin.deleteExchange("output"); }
Example #18
Source File: ITSpringRabbit.java From brave with Apache License 2.0 | 5 votes |
@BeforeClass public static void startRabbit() { rabbit.start(); CachingConnectionFactory connectionFactory = new CachingConnectionFactory(rabbit.getContainerIpAddress(), rabbit.getAmqpPort()); try { RabbitAdmin amqpAdmin = new RabbitAdmin(connectionFactory); amqpAdmin.declareExchange(exchange); amqpAdmin.declareQueue(queue); amqpAdmin.declareBinding(binding); } finally { connectionFactory.destroy(); } }
Example #19
Source File: RabbitBinderTests.java From spring-cloud-stream-binder-rabbit with Apache License 2.0 | 5 votes |
@Test public void testNonDurablePubSubWithAutoBindDLQ() throws Exception { RabbitAdmin admin = new RabbitAdmin(this.rabbitAvailableRule.getResource()); RabbitTestBinder binder = getBinder(); ExtendedConsumerProperties<RabbitConsumerProperties> consumerProperties = createConsumerProperties(); consumerProperties.getExtension().setPrefix(TEST_PREFIX); consumerProperties.getExtension().setAutoBindDlq(true); consumerProperties.getExtension().setDurableSubscription(false); consumerProperties.setMaxAttempts(1); // disable retry BindingProperties bindingProperties = createConsumerBindingProperties( consumerProperties); DirectChannel moduleInputChannel = createBindableChannel("input", bindingProperties); moduleInputChannel.setBeanName("nondurabletest"); moduleInputChannel.subscribe(new MessageHandler() { @Override public void handleMessage(Message<?> message) throws MessagingException { throw new RuntimeException("foo"); } }); Binding<MessageChannel> consumerBinding = binder.bindConsumer("nondurabletest.0", "tgroup", moduleInputChannel, consumerProperties); consumerBinding.unbind(); assertThat(admin.getQueueProperties(TEST_PREFIX + "nondurabletest.0.dlq")) .isNull(); }
Example #20
Source File: RabbitExchangeQueueProvisioner.java From spring-cloud-stream-binder-rabbit with Apache License 2.0 | 5 votes |
public RabbitExchangeQueueProvisioner(ConnectionFactory connectionFactory, List<DeclarableCustomizer> customizers) { this.rabbitAdmin = new RabbitAdmin(connectionFactory); this.autoDeclareContext.refresh(); this.rabbitAdmin.setApplicationContext(this.autoDeclareContext); this.rabbitAdmin.afterPropertiesSet(); this.customizers = customizers; }
Example #21
Source File: RabbitBinderTests.java From spring-cloud-stream-binder-rabbit with Apache License 2.0 | 5 votes |
@Test public void testConsumerPropertiesWithUserInfrastructureNoBind() throws Exception { RabbitAdmin admin = new RabbitAdmin(this.rabbitAvailableRule.getResource()); Queue queue = new Queue("propsUser1.infra"); admin.declareQueue(queue); DirectExchange exchange = new DirectExchange("propsUser1"); admin.declareExchange(exchange); admin.declareBinding(BindingBuilder.bind(queue).to(exchange).with("foo")); RabbitTestBinder binder = getBinder(); ExtendedConsumerProperties<RabbitConsumerProperties> properties = createConsumerProperties(); properties.getExtension().setDeclareExchange(false); properties.getExtension().setBindQueue(false); Binding<MessageChannel> consumerBinding = binder.bindConsumer("propsUser1", "infra", createBindableChannel("input", new BindingProperties()), properties); Lifecycle endpoint = extractEndpoint(consumerBinding); SimpleMessageListenerContainer container = TestUtils.getPropertyValue(endpoint, "messageListenerContainer", SimpleMessageListenerContainer.class); assertThat(TestUtils.getPropertyValue(container, "missingQueuesFatal", Boolean.class)).isFalse(); assertThat(container.isRunning()).isTrue(); consumerBinding.unbind(); assertThat(container.isRunning()).isFalse(); Client client = new Client("http://guest:guest@localhost:15672/api/"); List<?> bindings = client.getBindingsBySource("/", exchange.getName()); assertThat(bindings.size()).isEqualTo(1); }
Example #22
Source File: RabbitTestBinder.java From spring-cloud-stream-binder-rabbit with Apache License 2.0 | 5 votes |
public RabbitTestBinder(ConnectionFactory connectionFactory, RabbitMessageChannelBinder binder) { this.applicationContext = new AnnotationConfigApplicationContext(Config.class); binder.setApplicationContext(this.applicationContext); this.setPollableConsumerBinder(binder); this.rabbitAdmin = new RabbitAdmin(connectionFactory); }
Example #23
Source File: AbstractAmqpIntegrationTest.java From hawkbit with Eclipse Public License 1.0 | 4 votes |
protected RabbitAdmin getRabbitAdmin() { return rabbitAdmin; }
Example #24
Source File: TestQueueCleaner.java From sinavi-jfw with Apache License 2.0 | 4 votes |
public static void retryCleaner() { RabbitAdmin admin = new RabbitAdmin(factory()); admin.setAutoStartup(true); admin.deleteExchange("retry.test.exchange"); admin.deleteQueue("retry.test.queue"); }
Example #25
Source File: RabbitMQInitializerTest.java From sinavi-jfw with Apache License 2.0 | 4 votes |
@Bean public AmqpAdmin amqpAdmin() { RabbitAdmin rabbitAdmin = new RabbitAdmin(factory()); rabbitAdmin.setAutoStartup(true); return rabbitAdmin; }
Example #26
Source File: CommonConfig.java From pinpoint with Apache License 2.0 | 4 votes |
@Bean public AmqpAdmin amqpAdmin(ConnectionFactory connectionFactory) { return new RabbitAdmin(connectionFactory); }
Example #27
Source File: RabbitBinderTests.java From spring-cloud-stream-binder-rabbit with Apache License 2.0 | 4 votes |
@Test public void testRoutingKeyExpressionPartitionedAndDelay() throws Exception { RabbitTestBinder binder = getBinder(); ExtendedProducerProperties<RabbitProducerProperties> producerProperties = createProducerProperties(); producerProperties.getExtension().setRoutingKeyExpression( spelExpressionParser.parseExpression("#root.getPayload().field")); // requires delayed message exchange plugin; tested locally // producerProperties.getExtension().setDelayedExchange(true); producerProperties.getExtension() .setDelayExpression(spelExpressionParser.parseExpression("1000")); producerProperties.setPartitionKeyExpression(new ValueExpression<>(0)); DirectChannel output = createBindableChannel("output", createProducerBindingProperties(producerProperties)); output.setBeanName("rkeProducer"); Binding<MessageChannel> producerBinding = binder.bindProducer("rkep", output, producerProperties); RabbitAdmin admin = new RabbitAdmin(this.rabbitAvailableRule.getResource()); Queue queue = new AnonymousQueue(); TopicExchange exchange = new TopicExchange("rkep"); org.springframework.amqp.core.Binding binding = BindingBuilder.bind(queue) .to(exchange).with("rkepTest-0"); admin.declareQueue(queue); admin.declareBinding(binding); output.addInterceptor(new ChannelInterceptor() { @Override public Message<?> preSend(Message<?> message, MessageChannel channel) { assertThat(message.getHeaders() .get(RabbitExpressionEvaluatingInterceptor.ROUTING_KEY_HEADER)) .isEqualTo("rkepTest"); assertThat(message.getHeaders() .get(RabbitExpressionEvaluatingInterceptor.DELAY_HEADER)) .isEqualTo(1000); return message; } }); output.send(new GenericMessage<>(new Pojo("rkepTest"))); Object out = spyOn(queue.getName()).receive(false); assertThat(out).isInstanceOf(byte[].class); assertThat(new String((byte[]) out, StandardCharsets.UTF_8)) .isEqualTo("{\"field\":\"rkepTest\"}"); producerBinding.unbind(); }
Example #28
Source File: RabbitConfiguration.java From tutorials with MIT License | 4 votes |
@Bean public AmqpAdmin amqpAdmin() { return new RabbitAdmin(connectionFactory()); }
Example #29
Source File: RabbitMqConfiguration.java From scraping-microservice-java-python-rabbitmq with Apache License 2.0 | 4 votes |
@Bean public AmqpAdmin amqpAdmin() { return new RabbitAdmin(connectionFactory()); }
Example #30
Source File: RabbitBinderModuleTests.java From spring-cloud-stream-binder-rabbit with Apache License 2.0 | 4 votes |
@Test public void testParentConnectionFactoryNotInheritedByCustomizedBindersAndProducerRetryBootProperties() { List<String> params = new ArrayList<>(); params.add("--spring.cloud.stream.input.binder=custom"); params.add("--spring.cloud.stream.output.binder=custom"); params.add("--spring.cloud.stream.binders.custom.type=rabbit"); params.add("--spring.cloud.stream.binders.custom.environment.foo=bar"); params.add("--server.port=0"); params.add("--spring.rabbitmq.template.retry.enabled=true"); params.add("--spring.rabbitmq.template.retry.maxAttempts=2"); params.add("--spring.rabbitmq.template.retry.initial-interval=1000"); params.add("--spring.rabbitmq.template.retry.multiplier=1.1"); params.add("--spring.rabbitmq.template.retry.max-interval=3000"); context = new SpringApplicationBuilder(SimpleProcessor.class) .web(WebApplicationType.NONE) .run(params.toArray(new String[params.size()])); BinderFactory binderFactory = context.getBean(BinderFactory.class); // @checkstyle:off @SuppressWarnings("unchecked") Binder<MessageChannel, ExtendedConsumerProperties<RabbitConsumerProperties>, ExtendedProducerProperties<RabbitProducerProperties>> binder = (Binder<MessageChannel, ExtendedConsumerProperties<RabbitConsumerProperties>, ExtendedProducerProperties<RabbitProducerProperties>>) binderFactory .getBinder(null, MessageChannel.class); // @checkstyle:on assertThat(binder).isInstanceOf(RabbitMessageChannelBinder.class); DirectFieldAccessor binderFieldAccessor = new DirectFieldAccessor(binder); ConnectionFactory binderConnectionFactory = (ConnectionFactory) binderFieldAccessor .getPropertyValue("connectionFactory"); ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class); assertThat(binderConnectionFactory).isNotSameAs(connectionFactory); CompositeHealthContributor bindersHealthIndicator = context .getBean("bindersHealthContributor", CompositeHealthContributor.class); assertThat(bindersHealthIndicator); RabbitHealthIndicator indicator = (RabbitHealthIndicator) bindersHealthIndicator.getContributor("custom"); assertThat(indicator).isNotNull(); assertThat(indicator.health().getStatus()).isEqualTo(Status.UP); String name = UUID.randomUUID().toString(); Binding<MessageChannel> binding = binder.bindProducer(name, new DirectChannel(), new ExtendedProducerProperties<>(new RabbitProducerProperties())); RetryTemplate template = TestUtils.getPropertyValue(binding, "lifecycle.amqpTemplate.retryTemplate", RetryTemplate.class); assertThat(template).isNotNull(); SimpleRetryPolicy retryPolicy = TestUtils.getPropertyValue(template, "retryPolicy", SimpleRetryPolicy.class); ExponentialBackOffPolicy backOff = TestUtils.getPropertyValue(template, "backOffPolicy", ExponentialBackOffPolicy.class); assertThat(retryPolicy.getMaxAttempts()).isEqualTo(2); assertThat(backOff.getInitialInterval()).isEqualTo(1000L); assertThat(backOff.getMultiplier()).isEqualTo(1.1); assertThat(backOff.getMaxInterval()).isEqualTo(3000L); binding.unbind(); new RabbitAdmin(rabbitTestSupport.getResource()).deleteExchange(name); context.close(); }