Example usage for org.springframework.amqp.rabbit.connection CachingConnectionFactory setVirtualHost

List of usage examples for org.springframework.amqp.rabbit.connection CachingConnectionFactory setVirtualHost

Introduction

In this page you can find the example usage for org.springframework.amqp.rabbit.connection CachingConnectionFactory setVirtualHost.

Prototype

public void setVirtualHost(String virtualHost) 

Source Link

Usage

From source file:com.jbrisbin.groovy.mqdsl.RabbitMQDsl.java

public static void main(String[] argv) {

    // Parse command line arguments
    CommandLine args = null;/*from w  w w  . j  a v  a 2  s  .c om*/
    try {
        Parser p = new BasicParser();
        args = p.parse(cliOpts, argv);
    } catch (ParseException e) {
        log.error(e.getMessage(), e);
    }

    // Check for help
    if (args.hasOption('?')) {
        printUsage();
        return;
    }

    // Runtime properties
    Properties props = System.getProperties();

    // Check for ~/.rabbitmqrc
    File userSettings = new File(System.getProperty("user.home"), ".rabbitmqrc");
    if (userSettings.exists()) {
        try {
            props.load(new FileInputStream(userSettings));
        } catch (IOException e) {
            log.error(e.getMessage(), e);
        }
    }

    // Load Groovy builder file
    StringBuffer script = new StringBuffer();
    BufferedInputStream in = null;
    String filename = "<STDIN>";
    if (args.hasOption("f")) {
        filename = args.getOptionValue("f");
        try {
            in = new BufferedInputStream(new FileInputStream(filename));
        } catch (FileNotFoundException e) {
            log.error(e.getMessage(), e);
        }
    } else {
        in = new BufferedInputStream(System.in);
    }

    // Read script
    if (null != in) {
        byte[] buff = new byte[4096];
        try {
            for (int read = in.read(buff); read > -1;) {
                script.append(new String(buff, 0, read));
                read = in.read(buff);
            }
        } catch (IOException e) {
            log.error(e.getMessage(), e);
        }
    } else {
        System.err.println("No script file to evaluate...");
    }

    PrintStream stdout = System.out;
    PrintStream out = null;
    if (args.hasOption("o")) {
        try {
            out = new PrintStream(new FileOutputStream(args.getOptionValue("o")), true);
            System.setOut(out);
        } catch (FileNotFoundException e) {
            log.error(e.getMessage(), e);
        }
    }

    String[] includes = (System.getenv().containsKey("MQDSL_INCLUDE")
            ? System.getenv("MQDSL_INCLUDE").split(String.valueOf(File.pathSeparatorChar))
            : new String[] { System.getenv("HOME") + File.separator + ".mqdsl.d" });

    try {
        // Setup RabbitMQ
        String username = (args.hasOption("U") ? args.getOptionValue("U")
                : props.getProperty("mq.user", "guest"));
        String password = (args.hasOption("P") ? args.getOptionValue("P")
                : props.getProperty("mq.password", "guest"));
        String virtualHost = (args.hasOption("v") ? args.getOptionValue("v")
                : props.getProperty("mq.virtualhost", "/"));
        String host = (args.hasOption("h") ? args.getOptionValue("h")
                : props.getProperty("mq.host", "localhost"));
        int port = Integer.parseInt(
                args.hasOption("p") ? args.getOptionValue("p") : props.getProperty("mq.port", "5672"));

        CachingConnectionFactory connectionFactory = new CachingConnectionFactory(host);
        connectionFactory.setPort(port);
        connectionFactory.setUsername(username);
        connectionFactory.setPassword(password);
        if (null != virtualHost) {
            connectionFactory.setVirtualHost(virtualHost);
        }

        // The DSL builder
        RabbitMQBuilder builder = new RabbitMQBuilder();
        builder.setConnectionFactory(connectionFactory);
        // Our execution environment
        Binding binding = new Binding(args.getArgs());
        binding.setVariable("mq", builder);
        String fileBaseName = filename.replaceAll("\\.groovy$", "");
        binding.setVariable("log",
                LoggerFactory.getLogger(fileBaseName.substring(fileBaseName.lastIndexOf("/") + 1)));
        if (null != out) {
            binding.setVariable("out", out);
        }

        // Include helper files
        GroovyShell shell = new GroovyShell(binding);
        for (String inc : includes) {
            File f = new File(inc);
            if (f.isDirectory()) {
                File[] files = f.listFiles(new FilenameFilter() {
                    @Override
                    public boolean accept(File file, String s) {
                        return s.endsWith(".groovy");
                    }
                });
                for (File incFile : files) {
                    run(incFile, shell, binding);
                }
            } else {
                run(f, shell, binding);
            }
        }

        run(script.toString(), shell, binding);

        while (builder.isActive()) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                log.error(e.getMessage(), e);
            }
        }

        if (null != out) {
            out.close();
            System.setOut(stdout);
        }

    } finally {
        System.exit(0);
    }
}

From source file:io.manasobi.commons.config.AmqpConfig.java

@Bean
public ConnectionFactory rabbitConnectionFactory() {

    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();

    connectionFactory.setAddresses("192.168.0.9");
    connectionFactory.setVirtualHost("manasobi-host");
    connectionFactory.setUsername("manasobi");
    connectionFactory.setPassword("manasobi");

    return connectionFactory;
}

From source file:vn.topmedia.monitor.rabbit.config.AbstractRabbitConfiguration.java

@Bean
public ConnectionFactory connectionFactory() {
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory(server);
    connectionFactory.setUsername(username);
    connectionFactory.setPassword(password);
    connectionFactory.setVirtualHost(virtualhost);
    connectionFactory.setPort(port);//from   w  w  w.j ava 2  s.  c o  m
    return connectionFactory;
}

From source file:net.wessendorf.amqp.RabbitConfiguration.java

@Bean
public ConnectionFactory connectionFactory() {

    CachingConnectionFactory connectionFactory = new CachingConnectionFactory("localhost");

    // apply some config settings:
    connectionFactory.setUsername("guest");
    connectionFactory.setPassword("guest");
    connectionFactory.setVirtualHost("/");
    connectionFactory.setPort(5672);/*ww  w.j a v  a 2 s .c  om*/

    return connectionFactory;
}

From source file:vn.topmedia.monitor.rabbit.client.RabbitClientConfiguration.java

@Bean
@Override//from  www . j a v  a  2  s  .co m
public ConnectionFactory connectionFactory() {
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
    connectionFactory.setUsername(Constants.RABBIT_USER);
    connectionFactory.setPassword(Constants.RABBIT_PASSWORD);
    connectionFactory.setHost(Constants.RABBIT_SERVER);
    connectionFactory.setVirtualHost(Constants.RABBIT_VITUALHOST);
    connectionFactory.setPort(Constants.RABBIT_PORT);
    return connectionFactory;
}

From source file:com.sample.amqp.RabbitConfiguration.java

@Bean
public ConnectionFactory connectionFactory() {
    final URI ampqUrl;
    try {//from  w w w .j  ava2  s .  c om
        ampqUrl = new URI(getEnvOrThrow("CLOUDAMQP_URL"));
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }

    final CachingConnectionFactory factory = new CachingConnectionFactory();
    factory.setUsername(ampqUrl.getUserInfo().split(":")[0]);
    factory.setPassword(ampqUrl.getUserInfo().split(":")[1]);
    factory.setHost(ampqUrl.getHost());
    factory.setPort(ampqUrl.getPort());
    factory.setVirtualHost(ampqUrl.getPath().substring(1));
    factory.setPublisherReturns(true);

    return factory;
}

From source file:com.nkapps.billing.configs.RabbitMQConfig.java

@Bean
public ConnectionFactory connectionFactory() {
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
    connectionFactory.setHost(environment.getProperty("rabbitmq.host"));
    connectionFactory.setPort(Integer.parseInt(environment.getProperty("rabbitmq.port")));
    connectionFactory.setUsername(environment.getProperty("rabbitmq.username"));
    connectionFactory.setPassword(environment.getProperty("rabbitmq.password"));
    connectionFactory.setVirtualHost(environment.getProperty("rabbitmq.virtual_host"));

    return connectionFactory;
}

From source file:org.opentestsystem.delivery.logging.RabbitConfiguration.java

@Bean
public ConnectionFactory connectionFactory() {
    final CachingConnectionFactory factory = new CachingConnectionFactory(determineHost());
    if (isNotBlank(addresses)) {
        factory.setAddresses(addresses);
    }/*  w  w  w  .j  a v a  2s.c  o m*/
    factory.setPort(port);
    factory.setUsername(username);
    factory.setPassword(password);
    factory.setVirtualHost(vhost);
    return factory;
}

From source file:org.springframework.amqp.rabbit.connection.LocalizedQueueConnectionFactory.java

/**
 * Create a dedicated connection factory for the address.
 * @param address the address to which the factory should connect.
 * @param node  the node./*  w  w  w.j  a v a  2s.c o m*/
 * @return the connection factory.
 * @throws Exception if errors occur during creation.
 */
protected ConnectionFactory createConnectionFactory(String address, String node) throws Exception {
    RabbitConnectionFactoryBean rcfb = new RabbitConnectionFactoryBean();
    rcfb.setUseSSL(this.useSSL);
    rcfb.setSslPropertiesLocation(this.sslPropertiesLocation);
    rcfb.setKeyStore(this.keyStore);
    rcfb.setTrustStore(this.trustStore);
    rcfb.setKeyStorePassphrase(this.keyStorePassPhrase);
    rcfb.setTrustStorePassphrase(this.trustStorePassPhrase);
    rcfb.afterPropertiesSet();
    CachingConnectionFactory ccf = new CachingConnectionFactory(rcfb.getObject());
    ccf.setAddresses(address);
    ccf.setUsername(this.username);
    ccf.setPassword(this.password);
    ccf.setVirtualHost(this.vhost);
    ccf.setBeanName("node:" + node);
    return ccf;
}

From source file:org.springframework.cloud.stream.binder.rabbit.LocalizedQueueConnectionFactory.java

/**
 * Create a dedicated connection factory for the address.
 * @param address the address to which the factory should connect.
 * @return the connection factory.//from  w w  w  .  j  ava 2  s .  com
 * @throws Exception if errors occur during creation.
 */
protected ConnectionFactory createConnectionFactory(String address) throws Exception {
    RabbitConnectionFactoryBean rcfb = new RabbitConnectionFactoryBean();
    rcfb.setUseSSL(this.useSSL);
    rcfb.setSslPropertiesLocation(this.sslPropertiesLocation);
    rcfb.afterPropertiesSet();
    CachingConnectionFactory ccf = new CachingConnectionFactory(rcfb.getObject());
    ccf.setAddresses(address);
    ccf.setUsername(this.username);
    ccf.setPassword(this.password);
    ccf.setVirtualHost(this.vhost);
    return ccf;
}