Search in sources :

Example 1 with ConnectionFactory

use of io.nats.client.ConnectionFactory in project camel by apache.

the class NatsProducer method getConnection.

private Connection getConnection() throws TimeoutException, IOException, GeneralSecurityException {
    Properties prop = getEndpoint().getNatsConfiguration().createProperties();
    ConnectionFactory factory = new ConnectionFactory(prop);
    if (getEndpoint().getNatsConfiguration().getSslContextParameters() != null && getEndpoint().getNatsConfiguration().isSecure()) {
        SSLContext sslCtx = getEndpoint().getNatsConfiguration().getSslContextParameters().createSSLContext(getEndpoint().getCamelContext());
        factory.setSSLContext(sslCtx);
        if (getEndpoint().getNatsConfiguration().isTlsDebug()) {
            factory.setTlsDebug(getEndpoint().getNatsConfiguration().isTlsDebug());
        }
    }
    connection = factory.createConnection();
    return connection;
}
Also used : ConnectionFactory(io.nats.client.ConnectionFactory) SSLContext(javax.net.ssl.SSLContext) Properties(java.util.Properties)

Example 2 with ConnectionFactory

use of io.nats.client.ConnectionFactory in project camel by apache.

the class NatsConsumerLoadTest method testLoadConsumer.

@Test
public void testLoadConsumer() throws InterruptedException, IOException, TimeoutException {
    mockResultEndpoint.setExpectedMessageCount(10000);
    ConnectionFactory cf = new ConnectionFactory("nats://localhost:4222");
    Connection connection = cf.createConnection();
    for (int i = 0; i < 10000; i++) {
        connection.publish("test", ("test" + i).getBytes());
    }
    mockResultEndpoint.assertIsSatisfied();
}
Also used : ConnectionFactory(io.nats.client.ConnectionFactory) Connection(io.nats.client.Connection) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 3 with ConnectionFactory

use of io.nats.client.ConnectionFactory in project camel by apache.

the class NatsConsumer method getConnection.

private Connection getConnection() throws IOException, InterruptedException, TimeoutException, GeneralSecurityException {
    Properties prop = getEndpoint().getNatsConfiguration().createProperties();
    ConnectionFactory factory = new ConnectionFactory(prop);
    if (getEndpoint().getNatsConfiguration().getSslContextParameters() != null && getEndpoint().getNatsConfiguration().isSecure()) {
        SSLContext sslCtx = getEndpoint().getNatsConfiguration().getSslContextParameters().createSSLContext(getEndpoint().getCamelContext());
        factory.setSSLContext(sslCtx);
        if (getEndpoint().getNatsConfiguration().isTlsDebug()) {
            factory.setTlsDebug(getEndpoint().getNatsConfiguration().isTlsDebug());
        }
    }
    connection = factory.createConnection();
    return connection;
}
Also used : ConnectionFactory(io.nats.client.ConnectionFactory) SSLContext(javax.net.ssl.SSLContext) Properties(java.util.Properties)

Aggregations

ConnectionFactory (io.nats.client.ConnectionFactory)3 Properties (java.util.Properties)2 SSLContext (javax.net.ssl.SSLContext)2 Connection (io.nats.client.Connection)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1 Test (org.junit.Test)1