当前位置: 首页>>代码示例>>Java>>正文


Java ConnectionFactory.useSslProtocol方法代码示例

本文整理汇总了Java中com.rabbitmq.client.ConnectionFactory.useSslProtocol方法的典型用法代码示例。如果您正苦于以下问题:Java ConnectionFactory.useSslProtocol方法的具体用法?Java ConnectionFactory.useSslProtocol怎么用?Java ConnectionFactory.useSslProtocol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.rabbitmq.client.ConnectionFactory的用法示例。


在下文中一共展示了ConnectionFactory.useSslProtocol方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: consumeWithoutCertificate

import com.rabbitmq.client.ConnectionFactory; //导入方法依赖的package包/类
/**
 * Helper method to retrieve queue message from rabbitMQ
 *
 * @return result
 * @throws Exception
 */
private static String consumeWithoutCertificate() throws Exception {
    String result = "";
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost");
    factory.setPort(5671);
    factory.useSslProtocol();

    Connection conn = factory.newConnection();
    Channel channel = conn.createChannel();

    GetResponse chResponse = channel.basicGet("WithoutClientCertQueue", true);
    if(chResponse != null) {
        byte[] body = chResponse.getBody();
        result = new String(body);
    }
    channel.close();
    conn.close();
    return result;
}
 
开发者ID:wso2,项目名称:product-ei,代码行数:26,代码来源:ESBJAVA4569RabbiMQSSLStoreWithoutClientCertValidationTest.java

示例2: createConnection

import com.rabbitmq.client.ConnectionFactory; //导入方法依赖的package包/类
private synchronized Connection createConnection() throws KeyManagementException, NoSuchAlgorithmException, IOException, TimeoutException {
    final ConnectionFactory factory = new ConnectionFactory();
    factory.setUsername(username);
    factory.setPassword(password);
    factory.setHost(amqpHost);
    factory.setPort(port);

    if (virtualHost != null && !virtualHost.isEmpty()) {
        factory.setVirtualHost(virtualHost);
    } else {
        factory.setVirtualHost("/");
    }

    if (useSsl != null && !useSsl.isEmpty() && useSsl.equalsIgnoreCase("true")) {
        factory.useSslProtocol(secureProtocol);
    }
    final Connection connection = factory.newConnection();
    connection.addShutdownListener(disconnectHandler);
    connection.addBlockedListener(blockedConnectionHandler);
    s_connection = connection;
    return s_connection;
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:23,代码来源:RabbitMQEventBus.java

示例3: consumeWithoutCertificate

import com.rabbitmq.client.ConnectionFactory; //导入方法依赖的package包/类
/**
 * Helper method to retrieve queue message from rabbitMQ
 *
 * @return result
 * @throws Exception
 */
private static String consumeWithoutCertificate() throws Exception {
    String result = "";

    String basePath = TestConfigurationProvider.getResourceLocation() + "/artifacts/ESB/messageStore/rabbitMQ/SSL/";

    String truststoreLocation = basePath + "rabbitMQ/certs/client/rabbitstore";
    String keystoreLocation = basePath + "rabbitMQ/certs/client/keycert.p12";

    char[] keyPassphrase = "MySecretPassword".toCharArray();
    KeyStore ks = KeyStore.getInstance("PKCS12");
    ks.load(new FileInputStream(keystoreLocation), keyPassphrase);

    KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    kmf.init(ks, keyPassphrase);

    char[] trustPassphrase = "rabbitstore".toCharArray();
    KeyStore tks = KeyStore.getInstance("JKS");
    tks.load(new FileInputStream(truststoreLocation), trustPassphrase);

    TrustManagerFactory tmf = TrustManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    tmf.init(tks);

    SSLContext c = SSLContext.getInstance("SSL");
    c.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);

    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost");
    factory.setPort(5671);
    factory.useSslProtocol(c);

    Connection conn = factory.newConnection();
    Channel channel = conn.createChannel();

    GetResponse chResponse = channel.basicGet("WithClientCertQueue", true);
    if(chResponse != null) {
        byte[] body = chResponse.getBody();
        result = new String(body);
    }
    channel.close();
    conn.close();
    return result;
}
 
开发者ID:wso2,项目名称:product-ei,代码行数:49,代码来源:ESBJAVA4569RabbiMQSSLStoreWithClientCertValidationTest.java

示例4: apply

import com.rabbitmq.client.ConnectionFactory; //导入方法依赖的package包/类
private void apply(final ConnectionFactory connectionFactory, final RabbitMqConfig config)
        throws NoSuchAlgorithmException, KeyManagementException {
    if (context != null) {
        connectionFactory.useSslProtocol(context);
    } else if (trustManager != null) {
        final String protocol = !isNullOrEmpty(config.sslProtocol()) ?
                config.sslProtocol() : SslProtocol.TLSv1_2.protocolName();
                connectionFactory.useSslProtocol(protocol, trustManager);
    } else if (!isNullOrEmpty(config.sslProtocol())) {
        connectionFactory.useSslProtocol(config.sslProtocol());
    } else {
        connectionFactory.useSslProtocol();
    }
}
 
开发者ID:FinderSystems,项目名称:Elmer,代码行数:15,代码来源:RabbitConnectionProvider.java

示例5: createFactoryFor

import com.rabbitmq.client.ConnectionFactory; //导入方法依赖的package包/类
public ConnectionFactory createFactoryFor(final RabbitMQEndpoint endpoint) {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setUsername(endpoint.getUsername());
    factory.setPassword(endpoint.getPassword());
    factory.setVirtualHost(endpoint.getVhost());
    factory.setHost(endpoint.getHostname());
    factory.setPort(endpoint.getPortNumber());
    if (endpoint.getClientProperties() != null) {
        factory.setClientProperties(endpoint.getClientProperties());
    }
    factory.setConnectionTimeout(endpoint.getConnectionTimeout());
    factory.setRequestedChannelMax(endpoint.getRequestedChannelMax());
    factory.setRequestedFrameMax(endpoint.getRequestedFrameMax());
    factory.setRequestedHeartbeat(endpoint.getRequestedHeartbeat());
    if (endpoint.getSslProtocol() != null) {
        try {
            if (endpoint.getSslProtocol().equals("true")) {
                factory.useSslProtocol();
            } else if (endpoint.getTrustManager() == null) {
                factory.useSslProtocol(endpoint.getSslProtocol());
            } else {
                factory.useSslProtocol(endpoint.getSslProtocol(), endpoint.getTrustManager());
            }
        } catch (NoSuchAlgorithmException | KeyManagementException e) {
            throw new IllegalArgumentException("Invalid sslProtocol " + endpoint.getSslProtocol(), e);
        }
    }
    if (endpoint.getAutomaticRecoveryEnabled() != null) {
        factory.setAutomaticRecoveryEnabled(endpoint.getAutomaticRecoveryEnabled());
    }
    if (endpoint.getNetworkRecoveryInterval() != null) {
        factory.setNetworkRecoveryInterval(endpoint.getNetworkRecoveryInterval());
    }
    if (endpoint.getTopologyRecoveryEnabled() != null) {
        factory.setTopologyRecoveryEnabled(endpoint.getTopologyRecoveryEnabled());
    }
    return factory;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:39,代码来源:RabbitMQConnectionFactorySupport.java

示例6: createConnection

import com.rabbitmq.client.ConnectionFactory; //导入方法依赖的package包/类
private synchronized Connection createConnection(ChannelType connectionType) throws ConnectionFailureException {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date startTime = new Date();
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    settings.getClient_properties().put("connection_type", connectionType.toString());
    settings.getClient_properties().put("connect_time", sdf.format(startTime)+"Z");

    ConnectionFactory cf = new ConnectionFactory();
    cf.setRequestedHeartbeat(settings.getHeartbeat());
    cf.setConnectionTimeout(settings.getConnection_timeout_millis());
    cf.setShutdownTimeout(settings.getShutdown_timeout_millis());
    cf.setRequestedFrameMax(settings.getFrame_max());
    cf.setHandshakeTimeout(settings.getHandshake_timeout_millis());
    cf.setClientProperties((Map)settings.getClient_properties());
    //cf.setSocketConfigurator(); NOTE is this worth investigating??
    cf.setRequestedChannelMax(0);//Hard coded ..
    cf.setAutomaticRecoveryEnabled(false);//Hard coded ..
    cf.setTopologyRecoveryEnabled(false);//Hard coded ..

    Exception lastException = null;
    Connection connection = null;
    for (BrokerAddresses.BrokerAddress address : addresses) {
        cf.setPassword(address.password);
        cf.setUsername(address.username);
        cf.setPort(address.port);
        cf.setHost(address.host);
        cf.setVirtualHost(address.virtualHost);
        try {
            if(address.scheme.toLowerCase().equals("amqps")){
                cf.useSslProtocol();
                cf.setSocketFactory(SSLSocketFactory.getDefault()); //Because rabbit uses NoopTrustStore by default...
            }
            log.infoWithParams("Creating "+connectionType+" connection to broker ...",
                    "address", address.toString(),
                    "settings", settings.toString());
            connection = cf.newConnection();
            boolean isOpen = connection.isOpen();
            if(!isOpen){
                continue;
            }
            break;
        } catch (Exception e) {
            log.debugWithParams("Failed to createConnection to broker",
                    "address", address.toString());
            lastException = e;
        }
    }

    if(connection == null){
        throw new ConnectionFailureException(cf, lastException);
    }

    conToChannel.put(connectionType,
            new ConnectionInfo(
                    connection,
                    new ArrayList<ChannelImpl>(),
                    settings.getClient_properties(),
                    connectionType)
    );
    log.infoWithParams("Successfully created "+connectionType+" connection to broker.",
            "address", addresses.get(0).toString(),
            "localPort", ((AMQConnection) connection).getLocalPort(),
            "settings", settings.toString());

    return connection;

}
 
开发者ID:meltwater,项目名称:rxrabbit,代码行数:68,代码来源:DefaultChannelFactory.java


注:本文中的com.rabbitmq.client.ConnectionFactory.useSslProtocol方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。