Search in sources :

Example 6 with RMQConnectionFactory

use of com.rabbitmq.jms.admin.RMQConnectionFactory in project rabbitmq-jms-client by rabbitmq.

the class RabbitAPIConnectionFactory method getConnectionFactory.

@Override
public ConnectionFactory getConnectionFactory() {
    RMQConnectionFactory rmqCF = new RMQConnectionFactory() {

        private static final long serialVersionUID = 1L;

        @Override
        public Connection createConnection(String userName, String password) throws JMSException {
            if (!testssl) {
                this.setPort(RABBIT_PORT);
            } else {
                this.setPort(RABBIT_TLS_PORT);
            }
            return super.createConnection(userName, password);
        }
    };
    if (testssl) {
        try {
            rmqCF.useSslProtocol();
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }
    rmqCF.setQueueBrowserReadMax(qbrMax);
    return rmqCF;
}
Also used : RMQConnectionFactory(com.rabbitmq.jms.admin.RMQConnectionFactory) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 7 with RMQConnectionFactory

use of com.rabbitmq.jms.admin.RMQConnectionFactory in project rabbitmq-jms-client by rabbitmq.

the class RabbitMqBasicQosIT method connection.

private QueueConnection connection(int qos) throws Exception {
    RMQConnectionFactory connectionFactory = (RMQConnectionFactory) AbstractTestConnectionFactory.getTestConnectionFactory().getConnectionFactory();
    connectionFactory.setChannelsQos(qos);
    QueueConnection queueConnection = connectionFactory.createQueueConnection();
    queueConnection.start();
    return queueConnection;
}
Also used : RMQConnectionFactory(com.rabbitmq.jms.admin.RMQConnectionFactory)

Example 8 with RMQConnectionFactory

use of com.rabbitmq.jms.admin.RMQConnectionFactory in project rabbitmq-jms-client by rabbitmq.

the class RpcIT method setupRpcServer.

void setupRpcServer() throws Exception {
    RMQConnectionFactory connectionFactory = (RMQConnectionFactory) AbstractTestConnectionFactory.getTestConnectionFactory().getConnectionFactory();
    connectionFactory.setDeclareReplyToDestination(false);
    serverConnection = connectionFactory.createConnection();
    serverConnection.start();
    Session session = serverConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue(QUEUE_NAME);
    drainQueue(session, queue);
    session.close();
    rpcServer = new RpcServer(serverConnection);
}
Also used : RMQConnectionFactory(com.rabbitmq.jms.admin.RMQConnectionFactory) BlockingQueue(java.util.concurrent.BlockingQueue) Queue(javax.jms.Queue) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Session(javax.jms.Session)

Example 9 with RMQConnectionFactory

use of com.rabbitmq.jms.admin.RMQConnectionFactory in project rabbitmq-jms-client by rabbitmq.

the class SslContextIT method defaultSslContextOverridesSetSslContext.

@Test
public void defaultSslContextOverridesSetSslContext() throws Exception {
    RMQConnectionFactory connectionFactory = (RMQConnectionFactory) AbstractTestConnectionFactory.getTestConnectionFactory(true, 0).getConnectionFactory();
    SSLContext defaultSslContext = createSslContext();
    AlwaysTrustTrustManager defaultTrustManager = new AlwaysTrustTrustManager();
    defaultSslContext.init(null, new TrustManager[] { defaultTrustManager }, null);
    SSLContext.setDefault(defaultSslContext);
    connectionFactory.useDefaultSslContext(true);
    SSLContext sslContext = createSslContext();
    AlwaysTrustTrustManager trustManager = new AlwaysTrustTrustManager();
    sslContext.init(null, new TrustManager[] { trustManager }, null);
    connectionFactory.useSslProtocol(sslContext);
    connection = connectionFactory.createConnection();
    assertTrue(defaultTrustManager.checkServerTrustedCallCount.get() >= 1, "TrustManager#checkServerTrusted must be called");
    assertEquals(0, trustManager.checkServerTrustedCallCount.get());
}
Also used : RMQConnectionFactory(com.rabbitmq.jms.admin.RMQConnectionFactory) SSLContext(javax.net.ssl.SSLContext) Test(org.junit.jupiter.api.Test)

Example 10 with RMQConnectionFactory

use of com.rabbitmq.jms.admin.RMQConnectionFactory in project rabbitmq-jms-client by rabbitmq.

the class SslContextIT method sslContextShouldBeUsedWhenExplicitlySet.

// https://github.com/rabbitmq/rabbitmq-jms-client/issues/12
// the set SSLContext isn't overridden
@Test
public void sslContextShouldBeUsedWhenExplicitlySet() throws Exception {
    RMQConnectionFactory connectionFactory = (RMQConnectionFactory) AbstractTestConnectionFactory.getTestConnectionFactory(true, 0).getConnectionFactory();
    connectionFactory.setUri("amqps://guest:guest@localhost:5671/%2f");
    SSLContext sslContext = createSslContext();
    AlwaysTrustTrustManager trustManager = new AlwaysTrustTrustManager();
    sslContext.init(null, new TrustManager[] { trustManager }, null);
    connectionFactory.useSslProtocol(sslContext);
    connection = connectionFactory.createConnection();
    assertTrue(trustManager.checkServerTrustedCallCount.get() >= 1, "TrustManager#checkServerTrusted must be called");
}
Also used : RMQConnectionFactory(com.rabbitmq.jms.admin.RMQConnectionFactory) SSLContext(javax.net.ssl.SSLContext) Test(org.junit.jupiter.api.Test)

Aggregations

RMQConnectionFactory (com.rabbitmq.jms.admin.RMQConnectionFactory)16 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Session (javax.jms.Session)3 SSLContext (javax.net.ssl.SSLContext)3 Test (org.junit.jupiter.api.Test)3 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)2 BlockingQueue (java.util.concurrent.BlockingQueue)2 Queue (javax.jms.Queue)2 RMQTextMessage (com.rabbitmq.jms.client.message.RMQTextMessage)1 DataConnectException (io.openmessaging.connector.api.exception.DataConnectException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)1 Connection (javax.jms.Connection)1 Destination (javax.jms.Destination)1 JMSException (javax.jms.JMSException)1 MessageProducer (javax.jms.MessageProducer)1 QueueConnection (javax.jms.QueueConnection)1 TextMessage (javax.jms.TextMessage)1