当前位置: 首页>>代码示例>>Java>>正文


Java GetResponse.getBody方法代码示例

本文整理汇总了Java中com.rabbitmq.client.GetResponse.getBody方法的典型用法代码示例。如果您正苦于以下问题:Java GetResponse.getBody方法的具体用法?Java GetResponse.getBody怎么用?Java GetResponse.getBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.rabbitmq.client.GetResponse的用法示例。


在下文中一共展示了GetResponse.getBody方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: consumeWithoutCertificate

import com.rabbitmq.client.GetResponse; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:wso2,项目名称:product-ei,代码行数:26,代码来源:ESBJAVA4569RabbiMQSSLStoreWithoutClientCertValidationTest.java

示例2: recover

import com.rabbitmq.client.GetResponse; //导入方法依赖的package包/类
@Override
public void recover() {
	try {
		componentManager.getHeartbeatMQAccessService().start();
		stateManager = componentManager.getStateManager();
		
		LOG.info("Start to read messages from MQ ...");
		final Channel channel = componentManager.getHeartbeatMQAccessService().getChannel();
		final String q = componentManager.getHeartbeatMQAccessService().getQueueName();
		
		while(true) {
			GetResponse response = channel.basicGet(q, false);
			if(response != null) {
				long deliveryTag = response.getEnvelope().getDeliveryTag();
				String message = new String(response.getBody(), "UTF-8");
				LOG.info("Received msg: deliveryTag=" + deliveryTag + ", message=" + message);
				
				JSONObject result = JSONObject.parseObject(message);
				if(result.containsKey(JSONKeys.TYPE)) {
					String type = result.getString(JSONKeys.TYPE);
					switch(type) {
						case ScheduledConstants.HEARTBEAT_TYPE_TASK_PROGRESS:
							
							// {"type":"taskProgress","platform_id":"7fe13e9879314da38bb7abc8b61657bb","tasks":[{"result":{"traceId":"1480402382967","callId":"1","resultCount":"1423","message":"SUCCESS","status":5},"jobId":1,"taskType":1,"taskId":1,"seqNo":1,"status":"SUCCEEDED"}]}
							// add flag 'needRecovering' to a tasks response
							result.put(ScheduledConstants.NEED_RECOVERING, ScheduledConstants.YES);
							needRecoveredTaskQueue.add(result);
							channel.basicAck(deliveryTag, false);
							break;
					}
				} else {
					channel.basicAck(deliveryTag, false);
				}
			} else {
				break;
			}
		}
		LOG.info("Complete to read MQ messages: q=" + q);
		
		// update Redis statuses
		recoverRedisStates();
		
		// recover job/task statuses
		processPendingTaskResponses();
	} catch (Exception e) {
		LOG.error("Recovery failure:", e);
		Throwables.propagate(e);
	} finally {
		componentManager.getHeartbeatMQAccessService().stop();
	}
}
 
开发者ID:shirdrn,项目名称:scheduled,代码行数:52,代码来源:RecoveryManagerImpl.java

示例3: consumeWithoutCertificate

import com.rabbitmq.client.GetResponse; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:wso2,项目名称:product-ei,代码行数:49,代码来源:ESBJAVA4569RabbiMQSSLStoreWithClientCertValidationTest.java

示例4: prePutHappyCase

import com.rabbitmq.client.GetResponse; //导入方法依赖的package包/类
@Test
public void prePutHappyCase() throws Exception {

    Map<String, String> kvs = configureHBase(primaryTableNameString, secondaryIdxTableNameString, "e", "eg", "a", amq_default_address, primaryTableNameString, "true", "");
    setupHBase(kvs);

    //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;
    }
}
 
开发者ID:manniche,项目名称:hbase-table-event-signaler,代码行数:53,代码来源:TableEventSignalerTest.java

示例5: verifyValueNotSentByDefault

import com.rabbitmq.client.GetResponse; //导入方法依赖的package包/类
@Test
public void verifyValueNotSentByDefault() throws Exception {

    Map<String, String> kvs = configureHBase(primaryTableNameString, secondaryIdxTableNameString, "e", "eg", "a", amq_default_address, primaryTableNameString, "false", "");
    setupHBase(kvs);

    //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;
    }
}
 
开发者ID:manniche,项目名称:hbase-table-event-signaler,代码行数:53,代码来源:TableEventSignalerTest.java

示例6: filterOnQualifiers

import com.rabbitmq.client.GetResponse; //导入方法依赖的package包/类
@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);

    //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;
    }
}
 
开发者ID:manniche,项目名称:hbase-table-event-signaler,代码行数:53,代码来源:TableEventSignalerTest.java

示例7: onlyPutWhenInQualifierFilter

import com.rabbitmq.client.GetResponse; //导入方法依赖的package包/类
@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);

    //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;
    }
}
 
开发者ID:manniche,项目名称:hbase-table-event-signaler,代码行数:57,代码来源:TableEventSignalerTest.java

示例8: preDeleteHappyCase

import com.rabbitmq.client.GetResponse; //导入方法依赖的package包/类
@Test
public void preDeleteHappyCase() throws Exception {

    Map<String, String> kvs = configureHBase(primaryTableNameString, secondaryIdxTableNameString, "e", "eg", "a", amq_default_address, primaryTableNameString, "true", "");
    setupHBase(kvs);
    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;
    }
}
 
开发者ID:manniche,项目名称:hbase-table-event-signaler,代码行数:56,代码来源:TableEventSignalerTest.java

示例9: discernNewPutFromUpdate

import com.rabbitmq.client.GetResponse; //导入方法依赖的package包/类
@Test
public void discernNewPutFromUpdate() throws Exception {
    Map<String, String> kvs = configureHBase(primaryTableNameString, secondaryIdxTableNameString, "e", "eg", "a", amq_default_address, primaryTableNameString, "true", "");
    setupHBase(kvs);

    //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);

    /*
        The first put should be registered as a "put" action, while the second should be registered as an "update"
        action, thereby signalling different action to be taken by the consumers
     */

    Put tablePut = new Put("EFG1".getBytes());
    tablePut.addColumn("e".getBytes(), "some_key".getBytes(), "some_value".getBytes());
    primaryTable.put(tablePut);

    tablePut = new Put("EFG1".getBytes());
    tablePut.addColumn("e".getBytes(), "some_other_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();
    int msgs_to_consume = 2;
    while (msgs_to_consume > 0) {
        System.out.println(String.format("Messages to get: %s", msgs_to_consume));
        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();
        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_qualifier");

        if(headers.get("action").toString().equals("update")){
            Assert.assertEquals("Column value should be preserved in the message body", "some_other_key", column_value);
        }
        else {
            Assert.assertEquals("Column value should be preserved in the message body", "some_key", column_value);
        }

        long deliveryTag = response.getEnvelope().getDeliveryTag();
        channel.basicAck(deliveryTag, false);
        msgs_to_consume--;
    }
}
 
开发者ID:manniche,项目名称:hbase-table-event-signaler,代码行数:64,代码来源:TableEventSignalerTest.java


注:本文中的com.rabbitmq.client.GetResponse.getBody方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。