private static ConnectionFactory getConnectionFactory(
     String host, String username, String password) {
   CachingConnectionFactory connectionFactory = new CachingConnectionFactory(host);
   connectionFactory.setPassword(password);
   connectionFactory.setUsername(username);
   return connectionFactory;
 }
 @Bean
 public ConnectionFactory connectionFactory() {
   CachingConnectionFactory connectionFactory = new CachingConnectionFactory("rabbitmq");
   // CachingConnectionFactory connectionFactory = new CachingConnectionFactory("192.168.99.104");
   connectionFactory.setUsername("guest");
   connectionFactory.setPassword("guest");
   return connectionFactory;
 }
  public Map<String, String> runDiagnostics() {
    final Map<String, String> diagnostics = new TreeMap<String, String>();
    final CachingConnectionFactory serverConnectionFactory = new CachingConnectionFactory(host);
    serverConnectionFactory.setVirtualHost(virtualHost);
    serverConnectionFactory.setUsername("pat");
    serverConnectionFactory.setPassword("p0stm4n");

    testConfig(diagnostics, "Server", serverConnectionFactory);

    final CachingConnectionFactory clientConnectionFactory = new CachingConnectionFactory(host);
    clientConnectionFactory.setVirtualHost(virtualHost);
    clientConnectionFactory.setUsername("flash");
    clientConnectionFactory.setPassword("readonly");
    testConfig(diagnostics, "Client", clientConnectionFactory);

    return diagnostics;
  }
  @Bean
  public CachingConnectionFactory rabbitConnectionFactory() {
    log.info("AMQP URL: {}", isBlank(amqpConnectionUri) ? "localhost:5672" : amqpConnectionUri);

    RabbitConnectionFactoryConfig config = uriToConnectionConfig(amqpConnectionUri);
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory(config.getHost());
    connectionFactory.setPort(config.getPort());

    if (config.getUsername() != null) {
      connectionFactory.setUsername(config.getUsername());
    }
    if (config.getPassword() != null) {
      connectionFactory.setPassword(config.getPassword());
    }
    if (config.getVirtualHost() != null) {
      connectionFactory.setVirtualHost(StringUtils.remove(config.getVirtualHost(), '/'));
    }

    return connectionFactory;
  }
  /**
   * Constructor
   *
   * @param host Host name
   * @param port Host connection port
   * @param username Connection user name
   * @param password Connection password
   * @param virtualHost RabbitMQ virtual host
   * @param exchangeName RabbitMQ exchange name
   * @param queueName Queue name
   */
  public RabbitMQTopicQueueProducer(
      String host,
      int port,
      String username,
      String password,
      String virtualHost,
      String exchangeName,
      String queueName) {
    super();

    CachingConnectionFactory connectionFactory = new CachingConnectionFactory(host, port);
    connectionFactory.setUsername(username);
    connectionFactory.setPassword(password);
    connectionFactory.setVirtualHost(virtualHost);
    RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
    rabbitTemplate.setExchange(exchangeName);
    rabbitTemplate.setQueue(queueName);

    this.setConnectionFactory(connectionFactory);
    this.setRabbitTemplate(rabbitTemplate);
  }