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

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

Introduction

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

Prototype

public void setPort(int port) 

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   ww w.  ja v  a2 s .  c o m
    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:com.bfair.pricing.config.AbstractStockAppRabbitConfiguration.java

@Bean
public ConnectionFactory connectionFactory() {

    CachingConnectionFactory connectionFactory = new CachingConnectionFactory("localhost");
    connectionFactory.setUsername("guest");
    connectionFactory.setPassword("guest");
    connectionFactory.setPort(port);
    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);
    return connectionFactory;
}

From source file:vn.com.vndirect.api.service.SpringAMQP.java

protected CamelContext addAmqpCamelContext() throws Exception {
    CachingConnectionFactory factory = new CachingConnectionFactory();
    factory.setAddresses(addressesAmqp);
    factory.setUsername(usernameAmqp);//  w ww  .jav a 2 s.c o m
    factory.setPassword(passwordAmqp);
    factory.setPort(5672);
    RabbitTemplate amqpTemplate = new RabbitTemplate(factory);
    amqpTemplate.setMessageConverter(new JsonMessageConverter());
    SpringAMQPComponent amqpComponent = new SpringAMQPComponent(factory);
    amqpComponent.setAmqpTemplate(amqpTemplate);
    context.addComponent("spring-amqp", amqpComponent);
    return context;
}

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);

    return connectionFactory;
}

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:com.sample.amqp.RabbitConfiguration.java

@Bean
public ConnectionFactory connectionFactory() {
    final URI ampqUrl;
    try {/*from w  w w  .  j a v  a2  s  .c  o  m*/
        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:vn.topmedia.monitor.rabbit.client.RabbitClientConfiguration.java

@Bean
@Override// www .ja 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.noriental.solr.config.test.BrokerRunning.java

@Override
public Statement apply(Statement base, Description description) {

    // Check at the beginning, so this can be used as a static field
    if (assumeOnline) {
        Assume.assumeTrue(brokerOnline.get(port));
    } else {/*w ww  . j  av a  2 s  . com*/
        Assume.assumeTrue(brokerOffline.get(port));
    }

    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
    connectionFactory.setHost("localhost");

    try {

        connectionFactory.setPort(port);
        if (StringUtils.hasText(hostName)) {
            connectionFactory.setHost(hostName);
        }
        RabbitAdmin admin = new RabbitAdmin(connectionFactory);

        for (Queue queue : queues) {
            String queueName = queue.getName();

            if (purge) {
                logger.debug("Deleting queue: " + queueName);
                // Delete completely - gets rid of consumers and bindings as well
                admin.deleteQueue(queueName);
            }

            if (isDefaultQueue(queueName)) {
                // Just for test probe.
                admin.deleteQueue(queueName);
            } else {
                admin.declareQueue(queue);
            }
        }
        brokerOffline.put(port, false);
        if (!assumeOnline) {
            Assume.assumeTrue(brokerOffline.get(port));
        }

        if (this.management) {
            Client client = new Client("http://localhost:15672/api/", "guest", "guest");
            if (!client.alivenessTest("/")) {
                throw new RuntimeException(
                        "Aliveness test failed for localhost:15672 guest/quest; " + "management not available");
            }
        }
    } catch (AmqpTimeoutException e) {
        fail("Timed out getting connection");
    } catch (Exception e) {
        logger.warn("Not executing tests because basic connectivity test failed", e);
        brokerOnline.put(port, false);
        if (assumeOnline) {
            Assume.assumeNoException(e);
        }
    } finally {
        connectionFactory.destroy();
    }

    return super.apply(base, description);

}

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);
    }//from   w  w  w  .j  a v a2 s .c om
    factory.setPort(port);
    factory.setUsername(username);
    factory.setPassword(password);
    factory.setVirtualHost(vhost);
    return factory;
}