當前位置: 首頁>>代碼示例>>Java>>正文


Java Channel.basicGet方法代碼示例

本文整理匯總了Java中com.rabbitmq.client.Channel.basicGet方法的典型用法代碼示例。如果您正苦於以下問題:Java Channel.basicGet方法的具體用法?Java Channel.basicGet怎麽用?Java Channel.basicGet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.rabbitmq.client.Channel的用法示例。


在下文中一共展示了Channel.basicGet方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: consumeWithoutCertificate

import com.rabbitmq.client.Channel; //導入方法依賴的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.Channel; //導入方法依賴的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.Channel; //導入方法依賴的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


注:本文中的com.rabbitmq.client.Channel.basicGet方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。