Java Code Examples for com.rabbitmq.client.Channel#basicGet()

The following examples show how to use com.rabbitmq.client.Channel#basicGet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ESBJAVA4569RabbiMQSSLStoreWithoutClientCertValidationTest.java    From product-ei with Apache License 2.0 9 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: RabbitMQTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
private Boolean messageReceived(Channel channel, String queueName) {
    try {
        return channel.basicGet(queueName, !AUTO_ACK) != null;
    } catch (Exception e) {
        return false;
    }
}
 
Example 3
Source File: PublishAMQPTest.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void validateSuccessfullPublishAndTransferToSuccess() throws Exception {
    PublishAMQP pubProc = new LocalPublishAMQP(false);
    TestRunner runner = TestRunners.newTestRunner(pubProc);
    runner.setProperty(PublishAMQP.HOST, "injvm");
    runner.setProperty(PublishAMQP.EXCHANGE, "myExchange");
    runner.setProperty(PublishAMQP.ROUTING_KEY, "key1");

    Map<String, String> attributes = new HashMap<>();
    attributes.put("foo", "bar");
    attributes.put("amqp$contentType", "foo/bar");
    attributes.put("amqp$contentEncoding", "foobar123");
    attributes.put("amqp$headers", "foo=bar,foo2=bar2,foo3");
    attributes.put("amqp$deliveryMode", "1");
    attributes.put("amqp$priority", "2");
    attributes.put("amqp$correlationId", "correlationId123");
    attributes.put("amqp$replyTo", "replyTo123");
    attributes.put("amqp$expiration", "expiration123");
    attributes.put("amqp$messageId", "messageId123");
    attributes.put("amqp$timestamp", "123456789");
    attributes.put("amqp$type", "type123");
    attributes.put("amqp$userId", "userId123");
    attributes.put("amqp$appId", "appId123");
    attributes.put("amqp$clusterId", "clusterId123");

    runner.enqueue("Hello Joe".getBytes(), attributes);

    runner.run();
    final MockFlowFile successFF = runner.getFlowFilesForRelationship(PublishAMQP.REL_SUCCESS).get(0);
    assertNotNull(successFF);
    Channel channel = ((LocalPublishAMQP) pubProc).getConnection().createChannel();
    GetResponse msg1 = channel.basicGet("queue1", true);
    assertNotNull(msg1);
    assertEquals("foo/bar", msg1.getProps().getContentType());

    assertEquals("foobar123", msg1.getProps().getContentEncoding());

    Map<String, Object> headerMap = msg1.getProps().getHeaders();

    Object foo = headerMap.get("foo");
    Object foo2 = headerMap.get("foo2");
    Object foo3 = headerMap.get("foo3");

    assertEquals("bar", foo.toString());
    assertEquals("bar2", foo2.toString());
    assertNull(foo3);

    assertEquals((Integer) 1, msg1.getProps().getDeliveryMode());
    assertEquals((Integer) 2, msg1.getProps().getPriority());
    assertEquals("correlationId123", msg1.getProps().getCorrelationId());
    assertEquals("replyTo123", msg1.getProps().getReplyTo());
    assertEquals("expiration123", msg1.getProps().getExpiration());
    assertEquals("messageId123", msg1.getProps().getMessageId());
    assertEquals(new Date(123456789L), msg1.getProps().getTimestamp());
    assertEquals("type123", msg1.getProps().getType());
    assertEquals("userId123", msg1.getProps().getUserId());
    assertEquals("appId123", msg1.getProps().getAppId());
    assertEquals("clusterId123", msg1.getProps().getClusterId());

    assertNotNull(channel.basicGet("queue2", true));
}
 
Example 4
Source File: ESBJAVA4569RabbiMQSSLStoreWithClientCertValidationTest.java    From product-ei with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source File: PublishAMQPTest.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void validateSuccessfullPublishAndTransferToSuccess() throws Exception {
    final PublishAMQP pubProc = new LocalPublishAMQP();
    final TestRunner runner = TestRunners.newTestRunner(pubProc);
    runner.setProperty(PublishAMQP.HOST, "injvm");
    runner.setProperty(PublishAMQP.EXCHANGE, "myExchange");
    runner.setProperty(PublishAMQP.ROUTING_KEY, "key1");

    final Map<String, String> attributes = new HashMap<>();
    attributes.put("foo", "bar");
    attributes.put("amqp$contentType", "foo/bar");
    attributes.put("amqp$contentEncoding", "foobar123");
    attributes.put("amqp$headers", "foo=bar,foo2=bar2,foo3");
    attributes.put("amqp$deliveryMode", "1");
    attributes.put("amqp$priority", "2");
    attributes.put("amqp$correlationId", "correlationId123");
    attributes.put("amqp$replyTo", "replyTo123");
    attributes.put("amqp$expiration", "expiration123");
    attributes.put("amqp$messageId", "messageId123");
    attributes.put("amqp$timestamp", "123456789");
    attributes.put("amqp$type", "type123");
    attributes.put("amqp$userId", "userId123");
    attributes.put("amqp$appId", "appId123");
    attributes.put("amqp$clusterId", "clusterId123");

    runner.enqueue("Hello Joe".getBytes(), attributes);

    runner.run();

    final MockFlowFile successFF = runner.getFlowFilesForRelationship(PublishAMQP.REL_SUCCESS).get(0);
    assertNotNull(successFF);

    final Channel channel = ((LocalPublishAMQP) pubProc).getConnection().createChannel();
    final GetResponse msg1 = channel.basicGet("queue1", true);
    assertNotNull(msg1);
    assertEquals("foo/bar", msg1.getProps().getContentType());
    assertEquals("foobar123", msg1.getProps().getContentEncoding());

    final Map<String, Object> headerMap = msg1.getProps().getHeaders();

    final Object foo = headerMap.get("foo");
    final Object foo2 = headerMap.get("foo2");
    final Object foo3 = headerMap.get("foo3");

    assertEquals("bar", foo.toString());
    assertEquals("bar2", foo2.toString());
    assertNull(foo3);

    assertEquals((Integer) 1, msg1.getProps().getDeliveryMode());
    assertEquals((Integer) 2, msg1.getProps().getPriority());
    assertEquals("correlationId123", msg1.getProps().getCorrelationId());
    assertEquals("replyTo123", msg1.getProps().getReplyTo());
    assertEquals("expiration123", msg1.getProps().getExpiration());
    assertEquals("messageId123", msg1.getProps().getMessageId());
    assertEquals(new Date(123456789L), msg1.getProps().getTimestamp());
    assertEquals("type123", msg1.getProps().getType());
    assertEquals("userId123", msg1.getProps().getUserId());
    assertEquals("appId123", msg1.getProps().getAppId());
    assertEquals("clusterId123", msg1.getProps().getClusterId());

    assertNotNull(channel.basicGet("queue2", true));
}