List of usage examples for org.springframework.amqp.rabbit.connection CachingConnectionFactory setPassword
public void setPassword(String password)
From source file:com.xoom.rabbit.test.Main.java
public static void main(String[] args) throws InterruptedException { if (args.length != 9) { System.out.println(//from ww w . j a v a2s .co m "usage: java -jar target/rabbit-tester-0.1-SNAPSHOT-standalone.jar [consumer_threads] [number_of_messages] [amqp_host] [amqp_port] [produce] [consume] [message size in bytes] [username] [password]"); return; } final long startTime = System.currentTimeMillis(); int consumerThreads = Integer.parseInt(args[0]); final int messages = Integer.parseInt(args[1]); String host = args[2]; int port = Integer.parseInt(args[3]); boolean produce = Boolean.parseBoolean(args[4]); boolean consume = Boolean.parseBoolean(args[5]); final int messageSize = Integer.parseInt(args[6]); String username = args[7]; String password = args[8]; if (produce) { System.out.println("Sending " + messages + " messages to " + host + ":" + port); } if (consume) { System.out.println("Consuming " + messages + " messages from " + host + ":" + port); } if (!produce && !consume) { System.out.println("Not producing or consuming any messages."); } CachingConnectionFactory connectionFactory = new CachingConnectionFactory(host, port); connectionFactory.setUsername(username); connectionFactory.setPassword(password); connectionFactory.setChannelCacheSize(consumerThreads + 1); RabbitAdmin amqpAdmin = new RabbitAdmin(connectionFactory); DirectExchange exchange = new DirectExchange(EXCHANGE_NAME, true, false); Queue queue = new Queue(QUEUE_NAME); amqpAdmin.declareExchange(exchange); amqpAdmin.declareQueue(queue); amqpAdmin.declareBinding(BindingBuilder.bind(queue).to(exchange).with(ROUTING_KEY)); final AmqpTemplate amqpTemplate = new RabbitTemplate(connectionFactory); final CountDownLatch producerLatch = new CountDownLatch(messages); final CountDownLatch consumerLatch = new CountDownLatch(messages); SimpleMessageListenerContainer listenerContainer = null; if (consume) { listenerContainer = new SimpleMessageListenerContainer(); listenerContainer.setConnectionFactory(connectionFactory); listenerContainer.setQueueNames(QUEUE_NAME); listenerContainer.setConcurrentConsumers(consumerThreads); listenerContainer.setMessageListener(new MessageListener() { @Override public void onMessage(Message message) { if (consumerLatch.getCount() == 1) { System.out.println("Finished consuming " + messages + " messages in " + (System.currentTimeMillis() - startTime) + "ms"); } consumerLatch.countDown(); } }); listenerContainer.start(); } if (produce) { while (producerLatch.getCount() > 0) { try { byte[] message = new byte[messageSize]; RND.nextBytes(message); amqpTemplate.send(EXCHANGE_NAME, ROUTING_KEY, new Message(message, new MessageProperties())); producerLatch.countDown(); } catch (Exception e) { System.out.println("Failed to send message " + (messages - producerLatch.getCount()) + " will retry forever."); } } } if (consume) { consumerLatch.await(); listenerContainer.shutdown(); } connectionFactory.destroy(); }
From source file:com.jbrisbin.groovy.mqdsl.RabbitMQDsl.java
public static void main(String[] argv) { // Parse command line arguments CommandLine args = null;// www . j av a 2 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: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 . ja v a 2 s .c om*/ return connectionFactory; }
From source file:cz.deii.sandbox.config.RabbitMqConfiguration.java
@Bean public ConnectionFactory connectionFactory() { System.out.println(/*w w w.j a va 2 s .c o m*/ "connecting to: [host=" + host + ", username=" + username + ", password=" + password + "]"); CachingConnectionFactory connectionFactory = new CachingConnectionFactory(host); connectionFactory.setUsername(username); connectionFactory.setPassword(password); return connectionFactory; }
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.client.RabbitClientConfiguration.java
@Bean @Override/* w w w. j a va2 s . c om*/ 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.bfair.pricing.config.AbstractStockAppRabbitConfiguration.java
@Bean public ConnectionFactory connectionFactory() { CachingConnectionFactory connectionFactory = new CachingConnectionFactory("localhost"); connectionFactory.setUsername("guest"); connectionFactory.setPassword("guest"); connectionFactory.setPort(port);/*w w w . j a v a 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);//from w w w . j a va2 s . c o m return connectionFactory; }
From source file:io.acme.solution.api.conf.RabbitConfigurer.java
@Bean public ConnectionFactory getConnectionFactory() { log.info("Creating rabbit connection for command bus, publishing, on host: {" + this.hostname + "}"); final CachingConnectionFactory connectionFactory = new CachingConnectionFactory(this.hostname, this.port); connectionFactory.setUsername(this.username); connectionFactory.setPassword(this.password); return connectionFactory; }
From source file:io.acme.solution.infrastructure.conf.EventBusConfigurer.java
@Bean @Primary//from w w w .j av a2 s . c om public ConnectionFactory eventBusConnectionFactory() { log.info("Creating event bus connection on hostname: {" + this.hostname + "}"); final CachingConnectionFactory connectionFactory = new CachingConnectionFactory(this.hostname, this.port); connectionFactory.setUsername(this.username); connectionFactory.setPassword(this.password); return connectionFactory; }