Java Code Examples for org.springframework.amqp.rabbit.core.RabbitAdmin#declareExchange()

The following examples show how to use org.springframework.amqp.rabbit.core.RabbitAdmin#declareExchange() . 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 vote down vote up
@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: EMSConfiguration.java    From generic-vnfm with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: SpringIntegrationTest.java    From rabbitmq-mock with Apache License 2.0 5 votes vote down vote up
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 4
Source File: RabbitMqConfiguration.java    From Hands-On-High-Performance-with-Spring-5 with MIT License 5 votes vote down vote up
@Bean
public RabbitAdmin rabbitAdmin() {
	RabbitAdmin admin = new RabbitAdmin(connectionFactory());
	admin.declareQueue(queue());
	admin.declareExchange(exchange());
	admin.declareBinding(exchangeBinding(exchange(), queue()));
	return admin;
}
 
Example 5
Source File: RabbitBinderTests.java    From spring-cloud-stream-binder-rabbit with Apache License 2.0 5 votes vote down vote up
@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 6
Source File: AmqpUtils.java    From haven-platform with Apache License 2.0 5 votes vote down vote up
/**
 * 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 7
Source File: AmqpReporter.java    From haven-platform with Apache License 2.0 5 votes vote down vote up
@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 8
Source File: ITSpringRabbit.java    From brave with Apache License 2.0 5 votes vote down vote up
@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 9
Source File: RabbitMQUtils.java    From WeBASE-Front with Apache License 2.0 4 votes vote down vote up
/**
 * new exchange by rabbitAdmin
 * @param rabbitAdmin
 */
public static void declareExchange(RabbitAdmin rabbitAdmin, String exchangeName){
    DirectExchange directExchange = new DirectExchange(exchangeName);
    rabbitAdmin.declareExchange(directExchange);
}
 
Example 10
Source File: RabbitMQUtils.java    From WeBASE-Front with Apache License 2.0 3 votes vote down vote up
/**
 * new exchange and bind queue by rabbitAdmin
 * @param rabbitAdmin
 * @param exchangeName
 * @param queueName
 * @param routingKey
 */
public static void declareExchangeAndQueue(RabbitAdmin rabbitAdmin,
                                            String exchangeName, String queueName, String routingKey){
    DirectExchange directExchange = new DirectExchange(exchangeName);
    rabbitAdmin.declareExchange(directExchange);
    rabbitAdmin.declareQueue(new Queue(queueName));
}