Search in sources :

Example 61 with ConnectionFactory

use of com.rabbitmq.client.ConnectionFactory in project tech by ffyyhh995511.

the class NewTask method main.

public static void main(String[] argv) throws Exception {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();
    channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);
    String message = getMessage(argv);
    channel.basicPublish("", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes("UTF-8"));
    System.out.println(" [x] Sent '" + message + "'");
    channel.close();
    connection.close();
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) Channel(com.rabbitmq.client.Channel) Connection(com.rabbitmq.client.Connection)

Example 62 with ConnectionFactory

use of com.rabbitmq.client.ConnectionFactory in project tech by ffyyhh995511.

the class Send1 method main.

public static void main(String[] argv) throws Exception {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();
    channel.queueDeclare(QUEUE_NAME, false, false, false, null);
    String message = "Hello World!";
    channel.basicPublish("", QUEUE_NAME, null, message.getBytes("UTF-8"));
    System.out.println(" [x] Sent '" + message + "'");
    channel.close();
    connection.close();
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) Channel(com.rabbitmq.client.Channel) Connection(com.rabbitmq.client.Connection)

Example 63 with ConnectionFactory

use of com.rabbitmq.client.ConnectionFactory in project metrics by dropwizard.

the class GraphiteRabbitMQTest method shouldFailWhenGraphiteHostUnavailable.

@Test
public void shouldFailWhenGraphiteHostUnavailable() {
    ConnectionFactory connectionFactory = new ConnectionFactory();
    connectionFactory.setHost("some-unknown-host");
    try (GraphiteRabbitMQ unavailableGraphite = new GraphiteRabbitMQ(connectionFactory, "graphite")) {
        unavailableGraphite.connect();
        failBecauseExceptionWasNotThrown(UnknownHostException.class);
    } catch (Exception e) {
        assertThat(e.getMessage()).contains("some-unknown-host");
    }
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) Test(org.junit.Test)

Example 64 with ConnectionFactory

use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.

the class HostnameVerification method hostnameVerificationSucceeds.

@Test
public void hostnameVerificationSucceeds() throws Exception {
    ConnectionFactory connectionFactory = TestUtils.connectionFactory();
    connectionFactory.useSslProtocol(sslContext);
    customizer.accept(connectionFactory);
    try (Connection conn = connectionFactory.newConnection(() -> singletonList(new Address("localhost", ConnectionFactory.DEFAULT_AMQP_OVER_SSL_PORT)))) {
        assertTrue(conn.isOpen());
    }
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) Address(com.rabbitmq.client.Address) Connection(com.rabbitmq.client.Connection) Test(org.junit.Test)

Example 65 with ConnectionFactory

use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.

the class HostnameVerification method hostnameVerificationFailsBecauseCertificateNotIssuedForLoopbackInterface.

@Test(expected = SSLHandshakeException.class)
public void hostnameVerificationFailsBecauseCertificateNotIssuedForLoopbackInterface() throws Exception {
    ConnectionFactory connectionFactory = TestUtils.connectionFactory();
    connectionFactory.useSslProtocol(sslContext);
    customizer.accept(connectionFactory);
    connectionFactory.newConnection(() -> singletonList(new Address("127.0.0.1", ConnectionFactory.DEFAULT_AMQP_OVER_SSL_PORT)));
    fail("The server certificate isn't issued for 127.0.0.1, the TLS handshake should have failed");
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) Address(com.rabbitmq.client.Address) Test(org.junit.Test)

Aggregations

ConnectionFactory (com.rabbitmq.client.ConnectionFactory)188 Connection (com.rabbitmq.client.Connection)87 Test (org.junit.Test)73 Channel (com.rabbitmq.client.Channel)63 IOException (java.io.IOException)53 TimeoutException (java.util.concurrent.TimeoutException)23 DefaultConsumer (com.rabbitmq.client.DefaultConsumer)11 Envelope (com.rabbitmq.client.Envelope)11 SSLContext (javax.net.ssl.SSLContext)11 QueueingConsumer (com.rabbitmq.client.QueueingConsumer)9 HashMap (java.util.HashMap)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 AMQP (com.rabbitmq.client.AMQP)6 Consumer (com.rabbitmq.client.Consumer)6 ShutdownSignalException (com.rabbitmq.client.ShutdownSignalException)6 AMQConnection (com.rabbitmq.client.impl.AMQConnection)6 Address (com.rabbitmq.client.Address)5 NioParams (com.rabbitmq.client.impl.nio.NioParams)4 AutorecoveringConnection (com.rabbitmq.client.impl.recovery.AutorecoveringConnection)4 Path (javax.ws.rs.Path)3