Example usage for com.rabbitmq.client GetResponse getProps

List of usage examples for com.rabbitmq.client GetResponse getProps

Introduction

In this page you can find the example usage for com.rabbitmq.client GetResponse getProps.

Prototype

public BasicProperties getProps() 

Source Link

Document

Get the BasicProperties included in this response

Usage

From source file:com.kurento.kmf.rabbitmq.RabbitTemplate.java

License:Apache License

private Message buildMessageFromResponse(GetResponse response) {
    MessageProperties messageProps = this.messagePropertiesConverter.toMessageProperties(response.getProps(),
            response.getEnvelope(), this.encoding);
    messageProps.setMessageCount(response.getMessageCount());
    return new Message(response.getBody(), messageProps);
}

From source file:com.nifi.processors.amqp.ConsumeAMQP.java

License:Apache License

/**
 * Will construct a {@link FlowFile} containing the body of the consumed
 * AMQP message (if {@link GetResponse} returned by {@link AMQPConsumer} is
 * not null) and AMQP properties that came with message which are added to a
 * {@link FlowFile} as attributes, transferring {@link FlowFile} to
 * 'success' {@link Relationship}./*from  w w  w  .  j a v a  2  s  .c o  m*/
 */
@Override
protected void rendezvousWithAmqp(ProcessContext context, ProcessSession processSession)
        throws ProcessException {
    final GetResponse response = this.targetResource.consume();
    if (response != null) {
        FlowFile flowFile = processSession.create();
        flowFile = processSession.write(flowFile, new OutputStreamCallback() {
            @Override
            public void process(final OutputStream out) throws IOException {
                out.write(response.getBody());
            }
        });
        BasicProperties amqpProperties = response.getProps();
        flowFile = AMQPUtils.updateFlowFileAttributesWithAmqpProperties(amqpProperties, flowFile,
                processSession);
        processSession.getProvenanceReporter().receive(flowFile,
                this.amqpConnection.toString() + "/" + context.getProperty(QUEUE).getValue());
        processSession.transfer(flowFile, REL_SUCCESS);
    } else {
        context.yield();
    }
}

From source file:io.opentracing.contrib.rabbitmq.TracingChannel.java

License:Apache License

@Override
public GetResponse basicGet(String queue, boolean autoAck) throws IOException {
    GetResponse response = channel.basicGet(queue, autoAck);
    TracingUtils.buildAndFinishChildSpan(response.getProps(), tracer);
    return response;
}

From source file:lfp.rabbitmq.presence.tests.PresenceTests.java

License:Mozilla Public License

public Map<String, Object> getPresenceHeaders(String qname) throws IOException {
    GetResponse r = basicGet(qname);
    assertNotNull("Expected a presence message", r);

    byte[] body = r.getBody();
    if (body != null && body.length > 0) {
        fail("Expected null or empty body in presence message");
    }/*w  w  w.  ja va  2  s  .  c  o m*/

    Map<String, Object> h = r.getProps().getHeaders();
    assertNotNull("Expected headers in presence message", h);
    return h;
}

From source file:lfp.rabbitmq.udpexchange.tests.UdpExchangeTests.java

License:Mozilla Public License

public void checkReceivedStompDelivery(String expectedRKSuffix) throws IOException {
    GetResponse r = basicGet(q1);
    assertNotNull(r);//from  w w  w . j  a va2 s  . com
    assertTrue("Delivery has correct routing key", r.getEnvelope().getRoutingKey().endsWith(expectedRKSuffix));
    assertEquals("rk1", r.getProps().getHeaders().get("destination").toString());
    assertEquals("rk2", r.getProps().getHeaders().get("rk").toString());
    assertEquals("value1", r.getProps().getHeaders().get("header1").toString());
    assertEquals("value2", r.getProps().getHeaders().get("header2").toString());
    assertEquals("Hello STOMP", new String(r.getBody(), "utf-8"));
}

From source file:net.nzcorp.hbase.tableevent_signaler.TableEventSignalerTest.java

License:Apache License

@Test
public void prePutHappyCase() throws Exception {

    Map<String, String> kvs = configureHBase(primaryTableNameString, secondaryIdxTableNameString, "e", "eg",
            "a", amq_default_address, primaryTableNameString, "true", "");
    setupHBase(kvs);/*from   www. j  a v a2s .c o  m*/

    //simulate population of secondary index as a result of the above
    Put idxPut = new Put("EFG1".getBytes());
    idxPut.addColumn("a".getBytes(), "EFB1".getBytes(), "".getBytes());
    secondaryIdxTable.put(idxPut);

    // Add a column to the primary table, which should trigger a data ripple to the downstream table
    Put tablePut = new Put("EFG1".getBytes());
    tablePut.addColumn("e".getBytes(), "some_key".getBytes(), "some_value".getBytes());
    primaryTable.put(tablePut);

    //check that values made it to the queue
    com.rabbitmq.client.ConnectionFactory factory = new com.rabbitmq.client.ConnectionFactory();
    factory.setUri(amq_default_address);
    com.rabbitmq.client.Connection conn = factory.newConnection();
    com.rabbitmq.client.Channel channel = conn.createChannel();
    System.out.println(String.format("Test: connecting to %s", primaryTableNameString));

    while (true) {
        GetResponse response = channel.basicGet(primaryTableNameString, false);
        if (response == null)//busy-wait until the message has made it through the MQ
        {
            continue;
        }
        String routingKey = response.getEnvelope().getRoutingKey();
        Assert.assertEquals("Routing key should be rowkey", "genome", routingKey);

        String contentType = response.getProps().getContentType();
        Assert.assertEquals("Content type should be preserved", "application/json", contentType);

        Map<String, Object> headers = response.getProps().getHeaders();
        Assert.assertEquals("An action should be set on the message", "put", headers.get("action").toString());

        byte[] body = response.getBody();

        JSONObject jo = new JSONObject(new String(body));
        String column_family = (String) jo.get("column_family");
        Assert.assertEquals("Column family should be preserved in the message body", "eg", column_family);

        String column_value = (String) jo.get("column_value");
        Assert.assertEquals("Column value should be preserved in the message body", "some_value", column_value);

        long deliveryTag = response.getEnvelope().getDeliveryTag();
        channel.basicAck(deliveryTag, false);
        break;
    }
}

From source file:net.nzcorp.hbase.tableevent_signaler.TableEventSignalerTest.java

License:Apache License

@Test
public void verifyValueNotSentByDefault() throws Exception {

    Map<String, String> kvs = configureHBase(primaryTableNameString, secondaryIdxTableNameString, "e", "eg",
            "a", amq_default_address, primaryTableNameString, "false", "");
    setupHBase(kvs);/*from w  ww  .  j av  a2s .  c o m*/

    //simulate population of secondary index as a result of the above
    Put idxPut = new Put("EFG1".getBytes());
    idxPut.addColumn("a".getBytes(), "EFB1".getBytes(), "".getBytes());
    secondaryIdxTable.put(idxPut);

    // Add a column to the primary table, which should trigger a data ripple to the downstream table
    Put tablePut = new Put("EFG1".getBytes());
    tablePut.addColumn("e".getBytes(), "some_key".getBytes(), "some_value".getBytes());
    primaryTable.put(tablePut);

    //check that values made it to the queue
    com.rabbitmq.client.ConnectionFactory factory = new com.rabbitmq.client.ConnectionFactory();
    factory.setUri(amq_default_address);
    com.rabbitmq.client.Connection conn = factory.newConnection();
    com.rabbitmq.client.Channel channel = conn.createChannel();
    System.out.println(String.format("Test: connecting to %s", primaryTableNameString));

    while (true) {
        GetResponse response = channel.basicGet(primaryTableNameString, false);
        if (response == null)//busy-wait until the message has made it through the MQ
        {
            continue;
        }
        String routingKey = response.getEnvelope().getRoutingKey();
        Assert.assertEquals("Routing key should be rowkey", "genome", routingKey);

        String contentType = response.getProps().getContentType();
        Assert.assertEquals("Content type should be preserved", "application/json", contentType);

        Map<String, Object> headers = response.getProps().getHeaders();
        Assert.assertEquals("An action should be set on the message", "put", headers.get("action").toString());

        byte[] body = response.getBody();

        JSONObject jo = new JSONObject(new String(body));
        String column_family = (String) jo.get("column_family");
        Assert.assertEquals("Column family should be preserved in the message body", "eg", column_family);

        String column_value = (String) jo.get("column_value");
        Assert.assertEquals("Column value is not sent by default", "", column_value);

        long deliveryTag = response.getEnvelope().getDeliveryTag();
        channel.basicAck(deliveryTag, false);
        break;
    }
}

From source file:net.nzcorp.hbase.tableevent_signaler.TableEventSignalerTest.java

License:Apache License

@Test
public void filterOnQualifiers() throws Exception {

    Map<String, String> kvs = configureHBase(primaryTableNameString, secondaryIdxTableNameString, "e", "eg",
            "a", amq_default_address, primaryTableNameString, "false", "one_key|some_key");
    setupHBase(kvs);/*from   www  . j av a2 s .  co  m*/

    //simulate population of secondary index as a result of the above
    Put idxPut = new Put("EFG1".getBytes());
    idxPut.addColumn("a".getBytes(), "EFB1".getBytes(), "".getBytes());
    secondaryIdxTable.put(idxPut);

    // Add a column to the primary table, which should trigger a data ripple to the downstream table
    Put tablePut = new Put("EFG1".getBytes());
    tablePut.addColumn("e".getBytes(), "some_key".getBytes(), "some_value".getBytes());
    primaryTable.put(tablePut);

    //check that values made it to the queue
    com.rabbitmq.client.ConnectionFactory factory = new com.rabbitmq.client.ConnectionFactory();
    factory.setUri(amq_default_address);
    com.rabbitmq.client.Connection conn = factory.newConnection();
    com.rabbitmq.client.Channel channel = conn.createChannel();
    System.out.println(String.format("Test: connecting to %s", primaryTableNameString));

    while (true) {
        GetResponse response = channel.basicGet(primaryTableNameString, false);
        if (response == null)//busy-wait until the message has made it through the MQ
        {
            continue;
        }
        String routingKey = response.getEnvelope().getRoutingKey();
        Assert.assertEquals("Routing key should be rowkey", "genome", routingKey);

        String contentType = response.getProps().getContentType();
        Assert.assertEquals("Content type should be preserved", "application/json", contentType);

        Map<String, Object> headers = response.getProps().getHeaders();
        Assert.assertEquals("An action should be set on the message", "put", headers.get("action").toString());

        byte[] body = response.getBody();

        JSONObject jo = new JSONObject(new String(body));
        String column_family = (String) jo.get("column_family");
        Assert.assertEquals("Column family should be preserved in the message body", "eg", column_family);

        String column_value = (String) jo.get("column_value");
        Assert.assertEquals("Column value is not sent by default", "", column_value);

        long deliveryTag = response.getEnvelope().getDeliveryTag();
        channel.basicAck(deliveryTag, false);
        break;
    }
}

From source file:net.nzcorp.hbase.tableevent_signaler.TableEventSignalerTest.java

License:Apache License

@Test
public void onlyPutWhenInQualifierFilter() throws Exception {

    Map<String, String> kvs = configureHBase(primaryTableNameString, secondaryIdxTableNameString, "e", "eg",
            "a", amq_default_address, primaryTableNameString, "false", "some_key");
    setupHBase(kvs);/*from w w w . j a  v a 2 s .  co m*/

    //simulate population of secondary index as a result of the above
    Put idxPut = new Put("EFG1".getBytes());
    idxPut.addColumn("a".getBytes(), "EFB1".getBytes(), "".getBytes());
    secondaryIdxTable.put(idxPut);

    // Add a column to the primary table, which should trigger a data ripple to the downstream table
    Put tablePut = new Put("EFG1".getBytes());
    tablePut.addColumn("e".getBytes(), "some_key".getBytes(), "some_value".getBytes());
    tablePut.addColumn("e".getBytes(), "other_key".getBytes(), "some_value".getBytes());
    tablePut.addColumn("e".getBytes(), "third_key".getBytes(), "some_value".getBytes());
    primaryTable.put(tablePut);

    //check that values made it to the queue
    com.rabbitmq.client.ConnectionFactory factory = new com.rabbitmq.client.ConnectionFactory();
    factory.setUri(amq_default_address);
    com.rabbitmq.client.Connection conn = factory.newConnection();
    com.rabbitmq.client.Channel channel = conn.createChannel();
    System.out.println(String.format("Test: connecting to %s", primaryTableNameString));

    while (true) {
        int numMessages = channel.queueDeclarePassive(primaryTableNameString).getMessageCount();
        GetResponse response = channel.basicGet(primaryTableNameString, false);
        if (response == null || numMessages == 0)//busy-wait until the message has made it through the MQ
        {
            continue;
        }
        Assert.assertEquals("There should be only a single key in the queue", 1, numMessages);
        String routingKey = response.getEnvelope().getRoutingKey();
        Assert.assertEquals("Routing key should be rowkey", "genome", routingKey);

        String contentType = response.getProps().getContentType();
        Assert.assertEquals("Content type should be preserved", "application/json", contentType);

        Map<String, Object> headers = response.getProps().getHeaders();
        Assert.assertEquals("An action should be set on the message", "put", headers.get("action").toString());

        byte[] body = response.getBody();

        JSONObject jo = new JSONObject(new String(body));
        String column_family = (String) jo.get("column_family");
        Assert.assertEquals("Column family should be preserved in the message body", "eg", column_family);

        String column_value = (String) jo.get("column_value");
        Assert.assertEquals("Column value is not sent by default", "", column_value);

        long deliveryTag = response.getEnvelope().getDeliveryTag();
        channel.basicAck(deliveryTag, false);
        break;
    }
}

From source file:net.nzcorp.hbase.tableevent_signaler.TableEventSignalerTest.java

License:Apache License

@Test
public void preDeleteHappyCase() throws Exception {

    Map<String, String> kvs = configureHBase(primaryTableNameString, secondaryIdxTableNameString, "e", "eg",
            "a", amq_default_address, primaryTableNameString, "true", "");
    setupHBase(kvs);/*from ww w  .j a v  a  2 s  .  c  o  m*/
    com.rabbitmq.client.ConnectionFactory factory = new com.rabbitmq.client.ConnectionFactory();
    factory.setUri(amq_default_address);
    com.rabbitmq.client.Connection conn = factory.newConnection();
    com.rabbitmq.client.Channel channel = conn.createChannel();

    //simulate population of secondary index for a put on the downstreamTable
    Put idxPut = new Put("EFG1".getBytes());
    idxPut.addColumn("a".getBytes(), "EFB1".getBytes(), "".getBytes());
    secondaryIdxTable.put(idxPut);

    //simulate a data rippling performed by the data_rippler service consuming off of the rabbitmq queue
    Put tablePut = new Put("EFB1".getBytes());
    tablePut.addColumn("eg".getBytes(), "some_key".getBytes(), "some_value".getBytes());
    downstreamTable.put(tablePut);

    // since we made no active put to the queue from the prePut, we need to declare it explicitly here
    channel.queueDeclare(primaryTableNameString, true, false, false, null);

    // finished with the setup, we now issue a delete which should be caught by the rabbitmq
    Delete d = new Delete("EFG1".getBytes());
    primaryTable.delete(d);

    //check that values made it to the queue
    while (true) {
        GetResponse response = channel.basicGet(primaryTableNameString, false);
        if (response == null)//busy-wait until the message has made it through the MQ
        {
            continue;
        }
        String routingKey = response.getEnvelope().getRoutingKey();
        Assert.assertEquals("Routing key should be rowkey", "genome", routingKey);

        String contentType = response.getProps().getContentType();
        Assert.assertEquals("Content type should be preserved", "application/json", contentType);

        Map<String, Object> headers = response.getProps().getHeaders();
        Assert.assertEquals("An action should be set on the message", "delete",
                headers.get("action").toString());

        byte[] body = response.getBody();
        JSONObject jo = new JSONObject(new String(body));

        String column_qualifier = (String) jo.get("column_qualifier");
        Assert.assertEquals("Column qualifier should be empty, signalling a row delete", "", column_qualifier);

        long deliveryTag = response.getEnvelope().getDeliveryTag();
        channel.basicAck(deliveryTag, false);
        break;
    }
}