当前位置: 首页>>代码示例>>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;未经允许,请勿转载。