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


Java RabbitTemplate.setReplyTimeout方法代碼示例

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


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

示例1: call

import org.springframework.amqp.rabbit.core.RabbitTemplate; //導入方法依賴的package包/類
/**
 * @Title: call
 * @Description: call類型,點對點發送接收消息
 * @param topicRoutingKey
 * @param serverName
 * @param bodyMsg
 * @param outTimeMillis
 * @throws Exception 設定文件
 * @return Map<String,Object>    返回類型
 */
public Map<String,Object> call(String topicRoutingKey,String serverName,Map<String,Object> bodyMsg,int outTimeMillis) throws Exception{
    Map<String,Object> sendMsg = new HashMap<String,Object>();
    sendMsg.put("mqkey",topicRoutingKey+"."+serverName);
    sendMsg.put("mqtype","call");
    sendMsg.put("mqbody",bodyMsg==null?new HashMap<String,Object>():bodyMsg);

    String topicMessage = JSON.toJSONString(sendMsg, JsonFilter.filter);
    Message message=new Message(topicMessage.getBytes("UTF-8"),new MessageProperties());

    RabbitTemplate directTemplate =new RabbitTemplate();
    directTemplate.setConnectionFactory(connectionFactory);
    directTemplate.setExchange(PropertyLoader.MQ_EXCHANGE);
    directTemplate.setReplyTimeout(outTimeMillis);

    Message reply=directTemplate.sendAndReceive(topicRoutingKey,message);
    if(reply==null){
        throw new Exception("waitting rabbitmq response timeout");
    }
    String body=new String(reply.getBody(),"UTF-8");
    Map<String,Object> reqMsgMap =JSON.parseObject(body,new TypeReference<Map<String, Object>>(){});
    LOG.info("back :"+reqMsgMap);
    reqMsgMap =JSON.parseObject(reqMsgMap.get("mqbody").toString(),new TypeReference<Map<String, Object>>(){});
    return reqMsgMap;
}
 
開發者ID:elves-project,項目名稱:openapi,代碼行數:35,代碼來源:MessageProducer.java

示例2: createDmfClient

import org.springframework.amqp.rabbit.core.RabbitTemplate; //導入方法依賴的package包/類
private RabbitTemplate createDmfClient() {
    final RabbitTemplate template = new RabbitTemplate(connectionFactory);
    template.setMessageConverter(new Jackson2JsonMessageConverter());
    template.setReceiveTimeout(TimeUnit.SECONDS.toMillis(3));
    template.setReplyTimeout(TimeUnit.SECONDS.toMillis(3));
    template.setExchange(getExchange());
    return template;
}
 
開發者ID:eclipse,項目名稱:hawkbit,代碼行數:9,代碼來源:AbstractAmqpIntegrationTest.java

示例3: rabbitTemplateForTest

import org.springframework.amqp.rabbit.core.RabbitTemplate; //導入方法依賴的package包/類
@Bean
@Primary
public RabbitTemplate rabbitTemplateForTest(ConnectionFactory connectionFactory) {
    final RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
    rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
    rabbitTemplate.setReplyTimeout(TimeUnit.SECONDS.toMillis(3));
    rabbitTemplate.setReceiveTimeout(TimeUnit.SECONDS.toMillis(3));
    return rabbitTemplate;
}
 
開發者ID:eclipse,項目名稱:hawkbit,代碼行數:10,代碼來源:AmqpTestConfiguration.java

示例4: internalExecute

import org.springframework.amqp.rabbit.core.RabbitTemplate; //導入方法依賴的package包/類
private void internalExecute(InsuranceTask task) throws JsonProcessingException {
	Assert.notNull(task.getData(), "Missing task data");
	String routingKey = task.getDestinationQueue();
	Object data = task.getData();
	String message = mapper.writeValueAsString(data);
	try {

		log.info("Sending message to {}", routingKey);
		RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
		rabbitTemplate.setReplyTimeout(5000);
		rabbitTemplate.setReceiveTimeout(5000);
		rabbitTemplate.setQueue(routingKey);

		// TODO
		boolean sync = false;

		if (sync) {
			Object response = rabbitTemplate.convertSendAndReceive(routingKey, message);
			log.info("Received message from {}: {}", routingKey, response);
		}
		else {
			rabbitTemplate.convertAndSend(routingKey, message);
			try {
				Thread.sleep(5000);
			}
			catch (InterruptedException e) {
			}
		}
	}
	catch (RuntimeException ex) {
		log.error("Task execution error using routingKey {}", routingKey);
		throw new InsuranceException("Task execution error", ex);
	}
}
 
開發者ID:labcabrera,項目名稱:lab-insurance,代碼行數:35,代碼來源:InsuranceTaskExecutor.java

示例5: fixedReplyQRabbitTemplate

import org.springframework.amqp.rabbit.core.RabbitTemplate; //導入方法依賴的package包/類
@Bean
RabbitTemplate fixedReplyQRabbitTemplate(Exchange exchange, @Qualifier(REPLY_Q) Queue replyQueue, ConnectionFactory connectionFactory) {
    RabbitTemplate template = new RabbitTemplate(connectionFactory);
    template.setExchange(exchange.getName());
    template.setRoutingKey(this.routingKey);
    template.setReplyTimeout(-1); // this means that it should wait forever for a reply. TODO is this too dangerous ?
    template.setReplyQueue(replyQueue);
    return template;
}
 
開發者ID:joshlong,項目名稱:sfdc-cloudfoundry,代碼行數:10,代碼來源:RabbitConfiguration.java

示例6: init

import org.springframework.amqp.rabbit.core.RabbitTemplate; //導入方法依賴的package包/類
/**
 * 
 */
private static void init() {
	connectionFactory = newConnectionFactory();
	rabbitTemplate = new RabbitTemplate(connectionFactory);
	rabbitTemplate.setMessageConverter(new ElfMessageConverter());
	rabbitTemplate.setRoutingKey(CLIENT_SYNC_RCP_Q);
	rabbitTemplate.setReplyTimeout(-1);
	rabbitAdmin = new RabbitAdmin(connectionFactory);

}
 
開發者ID:jiangchanghui,項目名稱:JavaFxClient,代碼行數:13,代碼來源:RabbitConfiguration.java


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