package org.springblade.third.doordevice.conf;


import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @author lidexi
 * @date 2021/5/24 18:28
 * 亲邻虚拟队列
 */

@Configuration
public class QinLinMqConf {



//	@Value("${qinlin.virtualMq.queneName}")
	private String queneName;



//	@Bean
//	public Queue qinlin(){
//		Map<String, Object> args = new HashMap<>(2);
//		args.put("x-message-ttl", 1000 * 60 * 5); //5分钟有效期
//		return QueueBuilder.durable(this.queneName).withArguments(args).build();
//	}

	/**
	 * first 连接工厂
	 */
	/*@Bean(name = "qinlinMqConnection")
	public ConnectionFactory firstConnectionFactory(@Value("${qinlin.virtualMq.host}") String host,
													@Value("${qinlin.virtualMq.port}") int port,
													@Value("${qinlin.virtualMq.username}") String username,
													@Value("${qinlin.virtualMq.password}") String password,
													@Value("${qinlin.virtualMq.virtualHost}") String vHost) {
		CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
		connectionFactory.setHost(host);
		connectionFactory.setPort(port);
		connectionFactory.setUsername(username);
		connectionFactory.setPassword(password);
		connectionFactory.setVirtualHost(vHost);
		return connectionFactory;
	}*/

	/**
	 *  消费者
	 */
	/*@Bean(name = "qinlinListenerFactory")
	public SimpleRabbitListenerContainerFactory firstListenerFactory(
		SimpleRabbitListenerContainerFactoryConfigurer configurer,
		@Qualifier("qinlinMqConnection") ConnectionFactory connectionFactory) {
		SimpleRabbitListenerContainerFactory listenerContainerFactory = new SimpleRabbitListenerContainerFactory();
		//设置手动ack
		listenerContainerFactory.setAcknowledgeMode(AcknowledgeMode.NONE);
		configurer.configure(listenerContainerFactory, connectionFactory);
		return listenerContainerFactory;
	}*/



}
