package com.cloud.eureka.server.configuration;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.stereotype.Component;

import java.util.Properties;

/**
 * @program: crm-backend
 * @description: 默认配置
 * @author: houn
 * @create: 2019-07-26 13:48
 */
@Component
public class DefaultEnvironmentPostProcessor implements EnvironmentPostProcessor {

    @Override
    public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {

        Properties properties = new Properties();
        /**
         * 默认activemq pool配置
         */
        properties.put("spring.activemq.pool.create-connection-on-startup", true);
        properties.put("spring.activemq.pool.enabled", true);
        properties.put("spring.activemq.pool.expiry-timeout", 0);
        properties.put("spring.activemq.pool.idle-timeout", 30000);
        properties.put("spring.activemq.pool.max-connections", 2020);
        properties.put("spring.activemq.pool.maximum-active-session-per-connection", 500);
        properties.put("spring.activemq.pool.reconnect-on-exception", true);
        properties.put("spring.activemq.pool.time-between-expiration-check", -1);
        properties.put("spring.activemq.pool.use-anonymous-producers", true);

        /**
         * 默认activemq配置
         */
        properties.put("spring.activemq.broker-url", "tcp://localhost:61616");
        properties.put("spring.activemq.close-timeout", 15);
        properties.put("spring.activemq.in-memory", true);
        properties.put("spring.activemq.non-blocking-redelivery", false);
        properties.put("spring.activemq.user", "admin");
        properties.put("spring.activemq.masterPassword", "admin");
        properties.put("spring.activemq.send-timeout", 0);

        PropertiesPropertySource propertySource = new PropertiesPropertySource("default", properties);

        environment.getPropertySources().addLast(propertySource);
    }

}
