List of usage examples for com.rabbitmq.client ConnectionFactory setPassword
public void setPassword(String password)
From source file:dk.au.cs.karibu.backend.rabbitmq.RabbitMQPollingConsumer.java
License:Apache License
@Override public void openChannelAndSetRouting() throws IOException { theLogger.info(//from w ww . j a v a2 s .c om "openChannelAndSetRouting: Exchange:" + exchangeConfiguration + " Queue: " + queueConfiguration); ConnectionFactory factory = new ConnectionFactory(); factory.setUsername(exchangeConfiguration.getUsername()); factory.setPassword(exchangeConfiguration.getPassword()); if (exchangeConfiguration.isSSLConnection()) { try { factory.useSslProtocol(); } catch (KeyManagementException e) { String trace = ExceptionUtils.getStackTrace(e); theLogger.error("KeyMgtException: " + trace); } catch (NoSuchAlgorithmException e) { String trace = ExceptionUtils.getStackTrace(e); theLogger.error("NoSuchAlgoritmException: " + trace); } } connection = factory.newConnection(exchangeConfiguration.getServerAddressList()); channel = connection.createChannel(); channel.exchangeDeclare(exchangeConfiguration.getExchangeName(), exchangeConfiguration.getExchangeType(), exchangeConfiguration.isExchangeDurable()); // 'RabbitMQ in Action' p 102 Map<String, Object> moreArguments = new HashMap<String, Object>(); moreArguments.put("ha-mode", "all"); moreArguments.put("x-ha-policy", "all"); // TODO: find out why this does not work! channel.queueDeclare(queueConfiguration.getQueueName(), queueConfiguration.isQueueDurable(), queueConfiguration.isQueueExclusive(), queueConfiguration.isQueueAutoDelete(), moreArguments); channel.queueBind(queueConfiguration.getQueueName(), exchangeConfiguration.getExchangeName(), queueConfiguration.getRoutingKey()); consumer = new QueueingConsumer(channel); // Tell RabbitMQ to await acknowledgement before removing // msg from the queue. See http://www.rabbitmq.com/tutorials/tutorial-two-java.html boolean autoAck = false; channel.basicConsume(queueConfiguration.getQueueName(), autoAck, consumer); // Set the prefetch count to limit the amount of msg sent // to the daemons before they are acknowledged. Fixes a // bug that would induce an out-of-memory error in the // daemons during high transfer rates. // See http://www.rabbitmq.com/tutorials/tutorial-two-java.html // in the 'fair dispatch' section int prefetchCount = 100; // ISSUE: what is the 'right' value here? channel.basicQos(prefetchCount); }
From source file:dk.au.cs.karibu.producer.rabbitmq.RabbitChannelConnector.java
License:Apache License
@Override public void openConnection() throws IOException { theLogger.info("openConnection: " + exchangeConfiguration); ConnectionFactory factory = new ConnectionFactory(); factory.setUsername(exchangeConfiguration.getUsername()); factory.setPassword(exchangeConfiguration.getPassword()); if (exchangeConfiguration.isSSLConnection()) { try {// w ww . j a v a 2 s .c om factory.useSslProtocol(); } catch (KeyManagementException e) { theLogger.error("KeyManagementException: " + e.getLocalizedMessage()); } catch (NoSuchAlgorithmException e) { theLogger.error("NoSuchAlgorithmException: " + e.getLocalizedMessage()); } } connection = factory.newConnection(exchangeConfiguration.getServerAddressList()); channel = connection.createChannel(); channel.exchangeDeclare(exchangeConfiguration.getExchangeName(), exchangeConfiguration.getExchangeType(), exchangeConfiguration.isExchangeDurable()); // The queue and the binding between queue and exchange is defined by the server side! }
From source file:dk.bankjsonrabbit.messaging.Receive.java
public static HashMap<String, Object> setUpReceiver() throws java.io.IOException, TimeoutException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("datdb.cphbusiness.dk"); factory.setUsername("student"); factory.setPassword("cph"); connection = factory.newConnection(); channel = connection.createChannel(); channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null); System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); channel.basicQos(1);/*from w ww. j ava 2 s. c o m*/ QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(TASK_QUEUE_NAME, false, consumer); HashMap<String, Object> returnObjects = new HashMap<>(); returnObjects.put("channel", channel); returnObjects.put("consumer", consumer); return returnObjects; }
From source file:dk.bankjsonrabbit.messaging.Send.java
public static void sendMessage(String message, BasicProperties props) throws IOException, TimeoutException { String taskQueueName = props.getReplyTo(); ConnectionFactory factory = new ConnectionFactory(); factory.setHost("datdb.cphbusiness.dk"); factory.setUsername("student"); factory.setPassword("cph"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(taskQueueName, true, false, false, null); channel.basicPublish("", taskQueueName, props, message.getBytes()); channel.close();//from w ww . ja v a 2 s . c om connection.close(); }
From source file:dk.getcreditscore.messaging.Receive.java
public static HashMap<String, Object> setUpReceiver() throws java.io.IOException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("datdb.cphbusiness.dk"); factory.setUsername("student"); factory.setPassword("cph"); connection = factory.newConnection(); channel = connection.createChannel(); channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null); System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); channel.basicQos(1);//from w w w.j av a 2 s. c om QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(TASK_QUEUE_NAME, false, consumer); HashMap<String, Object> returnObjects = new HashMap<String, Object>(); returnObjects.put("channel", channel); returnObjects.put("consumer", consumer); return returnObjects; }
From source file:dk.getcreditscore.messaging.Send.java
public static void sendMessage(String message) throws IOException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("datdb.cphbusiness.dk"); factory.setUsername("student"); factory.setPassword("cph"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null); channel.basicPublish("", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes()); channel.close();// w w w. ja va 2 s .c o m connection.close(); }
From source file:dk.normalizer.messaging.Receive.java
public static HashMap<String, Object> setUpReceiver() throws java.io.IOException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("datdb.cphbusiness.dk"); factory.setUsername("student"); factory.setPassword("cph"); connection = factory.newConnection(); channel = connection.createChannel(); channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null); System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); channel.basicQos(1);/*from w w w . j ava 2 s.com*/ QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(TASK_QUEUE_NAME, false, consumer); HashMap<String, Object> returnObjects = new HashMap<>(); returnObjects.put("channel", channel); returnObjects.put("consumer", consumer); return returnObjects; }
From source file:dreamteamjson.DreamTeamJSON.java
/** * @param args the command line arguments * @throws java.io.IOException/*from w w w .j ava 2 s.com*/ */ public static void main(String[] args) throws IOException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("datdb.cphbusiness.dk"); factory.setUsername("Dreamteam"); factory.setPassword("bastian"); Connection connection = factory.newConnection(); Channel listeningChannel = connection.createChannel(); Channel sendingChannel = connection.createChannel(); listeningChannel.queueDeclare(LISTENING_QUEUE_NAME, false, false, false, null); System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); Consumer consumer = new DefaultConsumer(listeningChannel) { @Override public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { message = new String(body, "UTF-8"); System.out.println(" [x] Received '" + message + "'"); Message m = gson.fromJson(message, Message.class); System.out.println(m.toString()); double interestRate = 14; if (m.creditScore > 600) { interestRate -= 4.5; } else if (m.creditScore < 601 && m.creditScore > 500) { interestRate -= 2.7; } else if (m.creditScore < 501 && m.creditScore > 400) { interestRate -= 0.9; } int durationCut = m.loanDuration / 360; interestRate -= (durationCut * 0.18); double amountCut = m.loanAmount / 100000; interestRate -= (amountCut * 0.18); // Insert bank logic String loanResponse = "{\"interestRate\":" + interestRate + ",\"ssn\":" + m.ssn + "}"; sendingChannel.queueDeclare(SENDING_QUEUE_NAME, false, false, false, null); sendingChannel.basicPublish("", SENDING_QUEUE_NAME, null, loanResponse.getBytes()); } }; listeningChannel.basicConsume(LISTENING_QUEUE_NAME, true, consumer); }
From source file:dreamteamxmltranslator.Translator.java
public static void main(String[] args) throws IOException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("datdb.cphbusiness.dk"); factory.setUsername("Dreamteam"); factory.setPassword("bastian"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(LISTENING_QUEUE_NAME, false, false, false, null); channel.queueBind(LISTENING_QUEUE_NAME, EXCHANGE_NAME, "DreamTeamBankXML"); System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); Consumer consumer = new DefaultConsumer(channel) { @Override/*from w w w. j a v a2 s .c o m*/ public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { try { message = new String(body, "UTF-8"); System.out.println(" [x] Received '" + message + "'"); String[] arr = message.split(","); tester(arr); } catch (IOException_Exception ex) { Logger.getLogger(Translator.class.getName()).log(Level.SEVERE, null, ex); } } }; channel.basicConsume(LISTENING_QUEUE_NAME, true, consumer); }
From source file:dummyloanbroker.DummyLoanBroker.java
public static void main(String[] args) throws IOException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("datdb.cphbusiness.dk"); factory.setUsername("student"); factory.setPassword("cph"); com.rabbitmq.client.Connection connection = factory.newConnection(); com.rabbitmq.client.Channel channel = connection.createChannel(); String corrId = java.util.UUID.randomUUID().toString(); LoanRequestDTO loanRequest = new LoanRequestDTO("123456-7890", 456289.0, 25, -1); Gson gson = new Gson(); String message = gson.toJson(loanRequest); AMQP.BasicProperties props = new AMQP.BasicProperties.Builder().correlationId(corrId).build(); channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null); channel.basicPublish("", TASK_QUEUE_NAME, props, message.getBytes()); channel.close();/*from w w w. ja va 2 s . c o m*/ connection.close(); }