Example usage for com.rabbitmq.client ConnectionFactory setPassword

List of usage examples for com.rabbitmq.client ConnectionFactory setPassword

Introduction

In this page you can find the example usage for com.rabbitmq.client ConnectionFactory setPassword.

Prototype

public void setPassword(String password) 

Source Link

Document

Set the password.

Usage

From source file:com.mycompany.loanbroker.requestLoan.java

/**
 * Web service operation//from w w w . ja va 2s  . c om
 */
@WebMethod(operationName = "request")
public String request(@WebParam(name = "ssn") String ssn, @WebParam(name = "loanAmount") double loanAmount,
        @WebParam(name = "loanDuration") int loanDuration) throws IOException, InterruptedException {

    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("datdb.cphbusiness.dk");
    factory.setUsername("Dreamteam");
    factory.setPassword("bastian");
    Connection connection = factory.newConnection();
    Channel sendingchannel = connection.createChannel();
    Channel listeningChannel = connection.createChannel();

    listeningChannel.exchangeDeclare(EXCHANGE, "direct");
    listeningChannel.queueDeclare(LISTENING_QUEUE_NAME, false, false, false, null);
    listeningChannel.queueBind(LISTENING_QUEUE_NAME, EXCHANGE, ssn.replace("-", ""));

    sendingchannel.queueDeclare(SENDING_QUEUE_NAME, false, false, false, null);

    message = ssn + "," + loanAmount + "," + loanDuration;

    sendingchannel.basicPublish("", SENDING_QUEUE_NAME, null, message.getBytes());

    sendingchannel.close();

    Consumer consumer = new DefaultConsumer(listeningChannel) {
        @Override
        public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
                byte[] body) throws IOException {
            String message = new String(body, "UTF-8");
            System.out.println(" [x] The LoanBroker Has Received '" + message + "'");
            result = message;
        }
    };

    listeningChannel.basicConsume(LISTENING_QUEUE_NAME, true, consumer);
    //connection.close();

    return result;
}

From source file:com.mycompany.normalizer.Normalizer.java

public static void main(String[] argv) throws Exception {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("datdb.cphbusiness.dk");
    factory.setUsername("Dreamteam");
    factory.setPassword("bastian");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();
    final Channel sendingChannel = connection.createChannel();

    channel.queueDeclare(QUEUE_NAME, false, false, false, null);

    sendingChannel.exchangeDeclare(SENDING_QUEUE_NAME, "fanout");
    System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

    Consumer consumer = new DefaultConsumer(channel) {
        @Override//from  ww  w. jav  a 2 s.c  o m
        public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
                byte[] body) throws IOException {
            String message = new String(body, "UTF-8");
            System.out.println(" [x] Received '" + message + "'");

            //HANDLE HERE
            if (message.startsWith("{")) {
                // Transform with GSON

                schoolBank = message.contains("-");

                if (!schoolBank) {
                    message = message.replace("-", "");
                    JResponse jresponse = gson.fromJson(message, JResponse.class);
                    jresponse.setBank("cphbusiness.bankJSON");
                    message = gson.toJson(jresponse);

                } else {
                    message = message.replace("-", "");
                    JResponse jresponse = gson.fromJson(message, JResponse.class);
                    jresponse.setBank("DreamTeamBankJSON");
                    message = gson.toJson(jresponse);
                }

                sendingChannel.basicPublish(SENDING_QUEUE_NAME, "", null, message.getBytes());

            } else {

                schoolBank = message.contains("-");
                String result = "";

                if (!schoolBank) {
                    message = message.replace("-", "");
                    JSONObject soapDatainJsonObject = XML.toJSONObject(message);

                    result = gson.toJson(soapDatainJsonObject);
                    result = result.replace("{\"map\":{\"LoanResponse\":{\"map\":", "");
                    result = result.replace("}}}", "");

                    JResponse jresponse = gson.fromJson(result, JResponse.class);
                    jresponse.setBank("cphbusiness.bankXML");
                    result = gson.toJson(jresponse);

                } else {
                    message = message.replace("-", "");
                    JSONObject soapDatainJsonObject = XML.toJSONObject(message);

                    result = gson.toJson(soapDatainJsonObject);
                    result = result.replace("{\"map\":{\"LoanResponse\":{\"map\":", "");
                    result = result.replace("}}}", "");

                    JResponse jresponse = gson.fromJson(result, JResponse.class);
                    jresponse.setBank("DreamTeamBankXML");

                    result = gson.toJson(jresponse);
                }

                //  XResponse response = gson.fromJson(soapDatainJsonObject, XResponse.class);
                sendingChannel.basicPublish(SENDING_QUEUE_NAME, "", null, result.getBytes());

            }

        }
    };
    channel.basicConsume(QUEUE_NAME, true, consumer);
}

From source file:com.mycompany.receiptlist.ReceiptList.java

public static void main(String[] argv) throws Exception {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("datdb.cphbusiness.dk");
    factory.setUsername("Dreamteam");
    factory.setPassword("bastian");
    Connection connection = factory.newConnection();
    Channel listeningChannel = connection.createChannel();
    final Channel sendingChannel = connection.createChannel();

    listeningChannel.queueDeclare(QUEUE_NAME, false, false, false, null);
    sendingChannel.exchangeDeclare(EXCHANGE_NAME, "direct");
    System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

    Consumer consumer = new DefaultConsumer(listeningChannel) {
        @Override/*from w  ww .  java  2 s.c  o  m*/
        public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
                byte[] body) throws IOException {
            String message = new String(body, "UTF-8");
            System.out.println(" [x] Received '" + message + "'");

            String[] arr = message.split(",");

            for (int i = 0; i < arr.length; i++) {
                switch (arr[i]) {
                case "DreamTeamXMLQueue":
                    sendingChannel.basicPublish(EXCHANGE_NAME, "DreamTeamBankXML", null, message.getBytes());
                    break;
                case "DreamTeamJSONQueue":
                    sendingChannel.basicPublish(EXCHANGE_NAME, "DreamTeamBankJSON", null, message.getBytes());
                    break;
                case "cphbusiness.bankXML":
                    sendingChannel.basicPublish(EXCHANGE_NAME, "CphBusinessXML", null, message.getBytes());
                    break;
                case "cphbusiness.bankJSON":
                    sendingChannel.basicPublish(EXCHANGE_NAME, "CphBusinessJSON", null, message.getBytes());
                    break;

                }
            }
        }
    };

    listeningChannel.basicConsume(QUEUE_NAME, true, consumer);
}

From source file:com.nifi.processors.amqp.AbstractAMQPProcessor.java

License:Apache License

/**
 * Creates {@link Connection} to AMQP system.
 *//*from   w  w  w. j a  va2  s .  c o  m*/
private Connection createConnection(ProcessContext context) {
    ConnectionFactory cf = new ConnectionFactory();
    cf.setHost(context.getProperty(HOST).getValue());
    cf.setPort(Integer.parseInt(context.getProperty(PORT).getValue()));
    cf.setUsername(context.getProperty(USER).getValue());
    cf.setPassword(context.getProperty(PASSWORD).getValue());
    String vHost = context.getProperty(V_HOST).getValue();
    if (vHost != null) {
        cf.setVirtualHost(vHost);
    }

    // handles TLS/SSL aspects
    final SSLContextService sslService = context.getProperty(SSL_CONTEXT_SERVICE)
            .asControllerService(SSLContextService.class);
    final String rawClientAuth = context.getProperty(CLIENT_AUTH).getValue();
    final SSLContext sslContext;

    if (sslService != null) {
        final SSLContextService.ClientAuth clientAuth;
        if (StringUtils.isBlank(rawClientAuth)) {
            clientAuth = SSLContextService.ClientAuth.REQUIRED;
        } else {
            //                try {
            clientAuth = SSLContextService.ClientAuth.valueOf(rawClientAuth);
            //                } catch (final IllegalArgumentException iae) {
            //                    throw new ProviderCreationException(String.format("Unrecognized client auth '%s'. Possible values are [%s]",
            //                            rawClientAuth, StringUtils.join(SslContextFactory.ClientAuth.values(), ", ")));
            //                }
        }
        sslContext = sslService.createSSLContext(clientAuth);
    } else {
        sslContext = null;
    }

    // check if the ssl context is set and add it to the factory if so
    if (sslContext != null) {
        cf.useSslProtocol(sslContext);
    }

    try {
        Connection connection = cf.newConnection();
        return connection;
    } catch (Exception e) {
        throw new IllegalStateException("Failed to establish connection with AMQP Broker: " + cf.toString(), e);
    }
}

From source file:com.nxttxn.vramel.components.rabbitMQ.RabbitMQEndpoint.java

License:Apache License

private ConnectionFactory getOrCreateConnectionFactory() {
    if (connectionFactory == null) {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setUsername(getUsername());
        factory.setPassword(getPassword());
        factory.setVirtualHost(getVhost());
        factory.setHost(getHostname());/*from w w  w . j  ava2 s  .  c o  m*/
        factory.setPort(getPortNumber());
        if (getClientProperties() != null) {
            factory.setClientProperties(getClientProperties());
        }
        factory.setConnectionTimeout(getConnectionTimeout());
        factory.setRequestedChannelMax(getRequestedChannelMax());
        factory.setRequestedFrameMax(getRequestedFrameMax());
        factory.setRequestedHeartbeat(getRequestedHeartbeat());
        if (getSslProtocol() != null) {
            try {
                if (getSslProtocol().equals("true")) {
                    factory.useSslProtocol();
                } else if (getTrustManager() == null) {
                    factory.useSslProtocol(getSslProtocol());
                } else {
                    factory.useSslProtocol(getSslProtocol(), getTrustManager());
                }
            } catch (NoSuchAlgorithmException | KeyManagementException e) {
                throw new IllegalArgumentException("Invalid sslProtocol " + sslProtocol, e);
            }
        }
        if (getAutomaticRecoveryEnabled() != null) {
            factory.setAutomaticRecoveryEnabled(getAutomaticRecoveryEnabled());
        }
        if (getNetworkRecoveryInterval() != null) {
            factory.setNetworkRecoveryInterval(getNetworkRecoveryInterval());
        }
        if (getTopologyRecoveryEnabled() != null) {
            factory.setTopologyRecoveryEnabled(getTopologyRecoveryEnabled());
        }
        connectionFactory = factory;
    }
    return connectionFactory;
}

From source file:com.qt.core.util.MqConnectionUtil.java

License:Open Source License

private Connection createPooledConnection(MqConn conn) throws IOException {
    ConnectionFactory connectionFactory = new ConnectionFactory(); // 
    connectionFactory.setHost(conn.getHost());
    connectionFactory.setPort(conn.getPort());
    connectionFactory.setUsername(conn.getAccount());
    connectionFactory.setPassword(conn.getPassword());
    Connection connection = connectionFactory.newConnection();
    return connection;
}

From source file:com.saasovation.common.port.adapter.messaging.rabbitmq.BrokerChannel.java

License:Apache License

/**
 * Answers a new ConnectionFactory configured with aConnectionSettings.
 * @param aConnectionSettings the ConnectionFactory
 * @return ConnectionFactory/*from  w w w. j av a2s .c o m*/
 */
protected ConnectionFactory configureConnectionFactoryUsing(ConnectionSettings aConnectionSettings) {

    ConnectionFactory factory = new ConnectionFactory();

    factory.setHost(aConnectionSettings.hostName());

    if (aConnectionSettings.hasPort()) {
        factory.setPort(aConnectionSettings.port());
    }

    factory.setVirtualHost(aConnectionSettings.virtualHost());

    if (aConnectionSettings.hasUserCredentials()) {
        factory.setUsername(aConnectionSettings.username());
        factory.setPassword(aConnectionSettings.password());
    }

    return factory;
}

From source file:com.simple.sftpfetch.publish.RabbitClient.java

License:Apache License

/**
 * Initialize the RabbitClient, establish a connection and declare the exchange
 *
 * @param factory the RabbitMQ ConnectionFactory
 * @param connectionInfo a bean containing the necessary connection information
 *
 * @throws NoSuchAlgorithmException/*from  ww w  . j a  va 2  s.  com*/
 * @throws KeyManagementException
 * @throws URISyntaxException
 * @throws IOException
 */
public RabbitClient(ConnectionFactory factory, RabbitConnectionInfo connectionInfo)
        throws NoSuchAlgorithmException, KeyManagementException, URISyntaxException, IOException {
    factory.setHost(connectionInfo.getHostname());
    factory.setPort(connectionInfo.getPort());
    factory.setUsername(connectionInfo.getUsername());
    factory.setPassword(connectionInfo.getPassword());
    factory.setVirtualHost(connectionInfo.getVhost());
    factory.setConnectionTimeout(connectionInfo.getTimeout());
    Connection conn = factory.newConnection();
    exchange = connectionInfo.getExchange();
    channel = conn.createChannel();
    channel.exchangeDeclare(exchange, EXCHANGE_TYPE, true);
    this.amqpProperties = new AMQP.BasicProperties.Builder().contentType(CONTENT_TYPE).deliveryMode(2).build();
}

From source file:com.siva.rabbitmq.AmqpMsgPublisher.java

public static void main(String[] argv) throws Exception {

    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost");
    factory.setUsername("admin");
    factory.setPassword("welcome01");
    factory.setPort(5672);/*from w ww  .  ja  v  a2s  .c  om*/
    factory.setVirtualHost("/admin_vhost");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.exchangeDeclare(EXCHANGE_NAME, "topic", true);

    String routingKey = "mqtt_topic.iot.admin_vhost";
    String message = "Test Message from IoT";

    channel.basicPublish(EXCHANGE_NAME, routingKey, null, message.getBytes());
    System.out.println(" [x] Sent '" + routingKey + "':'" + message + "'");

    connection.close();
}

From source file:com.sonymobile.jenkins.plugins.mq.mqnotifier.MQNotifierConfig.java

License:Open Source License

/**
 * Tests connection to the server URI.//from www  .jav  a2  s .  co  m
 *
 * @param uri the URI.
 * @param name the user name.
 * @param pw the user password.
 * @return FormValidation object that indicates ok or error.
 * @throws javax.servlet.ServletException Exception for servlet.
 */
public FormValidation doTestConnection(@QueryParameter(SERVER_URI) final String uri,
        @QueryParameter(USERNAME) final String name, @QueryParameter(PASSWORD) final Secret pw)
        throws ServletException {
    UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.ALLOW_LOCAL_URLS);
    FormValidation result = FormValidation.ok();
    if (urlValidator.isValid(uri)) {
        try {
            ConnectionFactory conn = new ConnectionFactory();
            conn.setUri(uri);
            if (StringUtils.isNotEmpty(name)) {
                conn.setUsername(name);
                if (StringUtils.isNotEmpty(Secret.toString(pw))) {
                    conn.setPassword(Secret.toString(pw));
                }
            }
            conn.newConnection();
        } catch (URISyntaxException e) {
            result = FormValidation.error("Invalid Uri");
        } catch (PossibleAuthenticationFailureException e) {
            result = FormValidation.error("Authentication Failure");
        } catch (Exception e) {
            result = FormValidation.error(e.getMessage());
        }
    } else {
        result = FormValidation.error("Invalid Uri");

    }
    return result;
}