org.springframework.amqp.core.DirectExchange Java Examples

The following examples show how to use org.springframework.amqp.core.DirectExchange. 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 Project: summerframework   Author: spring-avengers   File: DeadLetterQueueCreator.java    License: Apache License 2.0 6 votes vote down vote up
public void createDeadLetterQueue(String fromExchange, String byRouteKey, String delayOrRetryRouteKey,
    String sourceQueue, String delayOrRetryQueueName, Long ttl) {
    if (sourceQueue == null || sourceQueue.isEmpty()) {
        logger.warn(
            "Have not config destination Queue, will not create delay queue by automatic,may be you must maintain binding by youself");
        return;
    }
    Properties properties = rabbitAdmin.getQueueProperties(delayOrRetryQueueName);
    if (properties == null) {
        Map<String, Object> delayQueueArgs = Maps.newHashMap();
        delayQueueArgs.put("x-message-ttl", ttl);
        delayQueueArgs.put("x-dead-letter-exchange", fromExchange);
        delayQueueArgs.put("x-dead-letter-routing-key", byRouteKey);
        Queue delayQueue = new Queue(delayOrRetryQueueName, true, false, false, delayQueueArgs);
        String returnQueueName = rabbitAdmin.declareQueue(delayQueue);
        if (returnQueueName != null) {
            Binding binding = BindingBuilder.bind(delayQueue)//
                .to(new DirectExchange(DeadLetterConstant.DEFAULT_DEADLETTEREXCHANGE_NAME))//
                .with(delayOrRetryRouteKey);//
            rabbitAdmin.declareBinding(binding);
        }
    }
}
 
Example #2
Source Project: WeBASE-Front   Author: WeBankFinTech   File: MQServiceTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDeclareBind() {
	Binding bind = BindingBuilder.bind(new Queue(queueName))
			.to(new DirectExchange(exchangeName))
			.with(routingKey);
	rabbitAdmin.declareBinding(bind);
}
 
Example #3
Source Project: xxpay-master   Author: jmdhappy   File: RabbitMq4PayNotify.java    License: MIT License 5 votes vote down vote up
@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);
}
 
Example #4
Source Project: spring-cloud-stream-binder-rabbit   Author: spring-cloud   File: RabbitBinderTests.java    License: 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:[email protected]:15672/api/");
	List<?> bindings = client.getBindingsBySource("/", exchange.getName());
	assertThat(bindings.size()).isEqualTo(1);
}
 
Example #5
Source Project: building-microservices   Author: livelessons-spring   File: MessagingApplication.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public InitializingBean prepareQueues(AmqpAdmin amqpAdmin) {
	return () -> {
		Queue queue = new Queue(NOTIFICATIONS, true);
		DirectExchange exchange = new DirectExchange(NOTIFICATIONS);
		Binding binding = BindingBuilder.bind(queue).to(exchange).with(NOTIFICATIONS);
		amqpAdmin.declareQueue(queue);
		amqpAdmin.declareExchange(exchange);
		amqpAdmin.declareBinding(binding);

	};
}
 
Example #6
Source Project: building-microservices   Author: livelessons-spring   File: AmqpIntegration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public InitializingBean prepareQueues(AmqpAdmin amqpAdmin) {
	return () -> {
		Queue queue = new Queue(this.echoQueueAndExchangeName, true);
		DirectExchange exchange = new DirectExchange(this.echoQueueAndExchangeName);
		Binding binding = BindingBuilder.bind(queue).to(exchange)
				.with(this.echoQueueAndExchangeName);
		amqpAdmin.declareQueue(queue);
		amqpAdmin.declareExchange(exchange);
		amqpAdmin.declareBinding(binding);
	};
}
 
Example #7
Source Project: elasticactors   Author: elasticsoftwarefoundation   File: RabbitTemplateMessageQueueFactory.java    License: Apache License 2.0 5 votes vote down vote up
private void ensureQueueExists(String queueName) {
    // ensure we have the queue created on the broker
    Queue queue = QueueBuilder.durable(queueName).build();
    amqpAdmin.declareQueue(queue);
    // and bound to the exchange
    DirectExchange exchange = ExchangeBuilder.directExchange(exchangeName).build();
    amqpAdmin.declareBinding(BindingBuilder.bind(queue).to(exchange).with(queueName));
}
 
Example #8
Source Project: WeBASE-Front   Author: WeBankFinTech   File: MQServiceTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testDeclareExchange() {
	rabbitAdmin.declareExchange(new DirectExchange(exchangeName));
}
 
Example #9
Source Project: spring-examples   Author: HaydiKodlayalim   File: RabbitMqConfiguration.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Bean
public DirectExchange directExchange() {
    return new DirectExchange(exchangeName);
}
 
Example #10
Source Project: spring-examples   Author: HaydiKodlayalim   File: RabbitMqConfiguration.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Bean
public Binding binding(final Queue queue, final DirectExchange directExchange){
    return BindingBuilder.bind(queue).to(directExchange).with(routingName);
}
 
Example #11
Source Project: springboot-example   Author: vipstone   File: DirectConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
DirectExchange directExchange() {
    // 参数一:交换器名称;参数二:是否持久化;参数三:是否自动删除消息
    return new DirectExchange(DirectConfig.EXCHANGE_NAME, false, false);
}
 
Example #12
Source Project: springboot-example   Author: vipstone   File: DirectConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
Binding bindingExchangeDirectQueue(Queue directQueue, DirectExchange directExchange) {
    return BindingBuilder.bind(directQueue).to(directExchange).with(DirectConfig.QUEUE_NAME);
}
 
Example #13
Source Project: kkbinlog   Author: kekingcn   File: RabbitMQClient.java    License: Apache License 2.0 4 votes vote down vote up
public DirectExchange getNotifyExchange() {
    return notifyExchange;
}
 
Example #14
Source Project: kkbinlog   Author: kekingcn   File: RabbitMQClient.java    License: Apache License 2.0 4 votes vote down vote up
private void setNotifyExchange() {
    DirectExchange notifyExchange = new DirectExchange(NOTIFY_EXCHANGE,true,false);
    amqpAdmin.declareExchange(notifyExchange);
    this.notifyExchange =  notifyExchange;
}
 
Example #15
Source Project: Hands-On-High-Performance-with-Spring-5   Author: PacktPublishing   File: RabbitMqConfiguration.java    License: MIT License 4 votes vote down vote up
@Bean
public DirectExchange exchange() {
	return new DirectExchange(RABBIT_MESSAGE_EXCHANGE);
}
 
Example #16
Source Project: Hands-On-High-Performance-with-Spring-5   Author: PacktPublishing   File: RabbitMqConfiguration.java    License: MIT License 4 votes vote down vote up
@Bean
Binding exchangeBinding(DirectExchange directExchange, Queue queue) {
	return BindingBuilder.bind(queue).to(directExchange).with(ROUTING_KEY);
}
 
Example #17
Source Project: fw-cloud-framework   Author: liuweijw   File: RabbitConfiguration.java    License: MIT License 4 votes vote down vote up
/**
 * 创建DLX exchange
 */
@Bean
DirectExchange delayExchange() {
	return new DirectExchange(PAY_NOTIFY_DELAY_EXCHANGE);
}
 
Example #18
Source Project: fw-cloud-framework   Author: liuweijw   File: RabbitConfiguration.java    License: MIT License 4 votes vote down vote up
/**
 * 创建per_queue_ttl_exchange
 */
@Bean
DirectExchange perQueueTTLExchange() {
	return new DirectExchange(PAY_NOTIFY_PER_QUEUE_TTL_EXCHANGE);
}
 
Example #19
Source Project: fw-cloud-framework   Author: liuweijw   File: RabbitConfiguration.java    License: MIT License 4 votes vote down vote up
/**
 * 将per_queue_ttl_exchange绑定到delay_queue_per_queue_ttl队列
 */
@Bean
Binding queueTTLBinding(Queue delayQueuePerQueueTTL, DirectExchange perQueueTTLExchange) {
	return BindingBuilder.bind(delayQueuePerQueueTTL).to(perQueueTTLExchange).with(
			PAY_NOTIFY_DELAY_QUENU_ALL_TTL);
}
 
Example #20
Source Project: java-tutorial   Author: jarvisqi   File: Tut6Config.java    License: MIT License 4 votes vote down vote up
@Bean
public DirectExchange directExchange() {
    return new DirectExchange("tut6.rpc");
}
 
Example #21
Source Project: java-tutorial   Author: jarvisqi   File: Tut6Config.java    License: MIT License 4 votes vote down vote up
@Bean
public Binding binding(DirectExchange exchange, Queue queue) {
    return BindingBuilder.bind(queue).to(exchange).with("rpc");
}
 
Example #22
Source Project: java-tutorial   Author: jarvisqi   File: Tut6Config.java    License: MIT License 4 votes vote down vote up
@Bean
public DirectExchange directExchange() {
    return new DirectExchange("tut6.rpc");
}
 
Example #23
Source Project: SpringBoot-Course   Author: qufei1993   File: RabbitMQConfig.java    License: MIT License 4 votes vote down vote up
@Bean
public DirectExchange orderDirectExchange() {
    return new DirectExchange(directExchangeName, false, false);
}
 
Example #24
Source Project: Pixiv-Illustration-Collection-Backend   Author: OysterQAQ   File: CreditRabbitmqConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean("creditExchange")
DirectExchange notifyExchange() {
    return new DirectExchange("creditExchange");
}
 
Example #25
Source Project: Spring-5.0-Cookbook   Author: PacktPublishing   File: RabbitMQConfig.java    License: MIT License 4 votes vote down vote up
@Bean
public DirectExchange exchange() {
       return new DirectExchange("login.packt");
}
 
Example #26
Source Project: Spring-5.0-Cookbook   Author: PacktPublishing   File: RabbitMQConfig.java    License: MIT License 4 votes vote down vote up
@Bean
public Binding bindingAsync(DirectExchange exchange, Queue queue) {
     return BindingBuilder.bind(queue).to(exchange).with("packt");
}
 
Example #27
Source Project: Spring-5.0-Cookbook   Author: PacktPublishing   File: RabbitMQConfigAsync.java    License: MIT License 4 votes vote down vote up
@Bean
public Binding binding(DirectExchange exchange, Queue requestQueue) {
    return BindingBuilder.bind(requestQueue).to(exchange).with("packt.async");
}
 
Example #28
Source Project: Spring-5.0-Cookbook   Author: PacktPublishing   File: RabbitMQConfig.java    License: MIT License 4 votes vote down vote up
@Bean
public DirectExchange exchange() {
      return new DirectExchange("login.packt");
}
 
Example #29
Source Project: Spring-5.0-By-Example   Author: PacktPublishing   File: RabbitMQConfiguration.java    License: MIT License 4 votes vote down vote up
@Bean("paymentExchange")
public DirectExchange paymentExchange(){
  return new DirectExchange(this.paymentExchange,true,false);
}
 
Example #30
Source Project: Spring-5.0-By-Example   Author: PacktPublishing   File: RabbitMQConfiguration.java    License: MIT License 4 votes vote down vote up
@Bean("paymentRequestBinding")
public Binding paymentRequestBinding(DirectExchange exchange,@Qualifier("paymentRequestQueue") Queue paymentRequestQueue){
  return BindingBuilder.bind(paymentRequestQueue).to(exchange).with(this.paymentRequestKey);
}