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

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

Introduction

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

Prototype

public CachingConnectionFactory(com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory) 

Source Link

Document

Create a new CachingConnectionFactory for the given target ConnectionFactory.

Usage

From source file:com.mtech.easyexchange.ordersolver.OrderSolverConfigurer.java

public static void main(String... args) throws Exception {

    ConnectionFactory cf = new CachingConnectionFactory("127.0.0.1");

    RabbitAdmin admin = new RabbitAdmin(cf);

    Queue queue = new Queue("OrderQueue");
    admin.declareQueue(queue);// ww  w.  j a v a2s.  c o m

    TopicExchange exchange = new TopicExchange("OrderExchange");
    admin.declareExchange(exchange);

    admin.declareBinding(BindingBuilder.bind(queue).to(exchange).with("*"));

    OrderMessageHolder holder = new OrderMessageHolder();

    OrderSolverThread ost = new OrderSolverThread(holder);
    ost.start();

    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(cf);
    container.setMessageListener(new OrderMessageConsumer(holder));
    container.setQueueNames("OrderQueue");
    container.start();
}

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

public static void main(String[] argv) {

    // Parse command line arguments
    CommandLine args = null;/*from www. j av a  2  s.co 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.mtech.easyexchange.manager.factory.OrderManagerFactory.java

public static IOrderManager createOrderManager() {

    IBalanceManager bm = BalanceManagerFactory.createBalanceManager();
    Session session = SessionFactoryProvider.getCurrentSession();

    ConnectionFactory cf = new CachingConnectionFactory("127.0.0.1");

    RabbitTemplate rabbitTemplate = new RabbitTemplate(cf);

    IOrderChangedNotifier changeNotifier = new OrderChangedNotifier(rabbitTemplate);

    return new OrderManager(new OrderDao(session), bm, changeNotifier);
}

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);//from   w  w w  . j a va  2  s.co  m

    return connectionFactory;
}

From source file:camelinaction.RequestReplyAmqpTest.java

protected CamelContext createCamelContext() throws Exception {
    CamelContext camelContext = super.createCamelContext();

    camelContext.addComponent("spring-amqp",
            new SpringAMQPComponent(new CachingConnectionFactory("localhost")));

    return camelContext;
}

From source file:be.rufer.playground.amqpclient.config.RabbitConfig.java

@Bean
public ConnectionFactory connectionFactory() {
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory("localhost");
    connectionFactory.setUsername(amqpUser);
    connectionFactory.setPassword(amqpPassword);
    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  a v  a 2  s .c o m
    return connectionFactory;
}

From source file:cz.deii.sandbox.config.RabbitMqConfiguration.java

@Bean
public ConnectionFactory connectionFactory() {
    System.out.println(//  ww w  . ja v a2 s.c  om
            "connecting to: [host=" + host + ", username=" + username + ", password=" + password + "]");
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory(host);
    connectionFactory.setUsername(username);
    connectionFactory.setPassword(password);
    return connectionFactory;
}

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);//  ww  w .  j av a 2 s .  c  o  m
    return connectionFactory;
}

From source file:org.openbaton.nse.api.EventReceiver.java

@Bean
public ConnectionFactory getConnectionFactory(Environment env) {
    logger.debug("Created ConnectionFactory");
    CachingConnectionFactory factory = new CachingConnectionFactory(rabbitMQProperties.getHost());
    factory.setPassword(rabbitMQProperties.getPassword());
    factory.setUsername(rabbitMQProperties.getUsername());
    return factory;
}